Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291123

DX: Allow programmer to specify a different namespace (a.k.a classes under lib/ folder) in .info files.

$
0
0

Problems/Motivations

The lib/Drupal// convention is not suitable for everything, so the programmer has the option to change himself the namespace of its registered classes. This is easily done by the following snippet:

<?php
$loader
= drupal_classloader();
$loader->registerNamespace('MyFancyNamespace', DRUPAL_ROOT . '/'. drupal_get_path('module', 'myfancymodule') . '/lib');
?>

This is pure glue code which is not fun to write and maintain, we could make it sexier, by allowing programmer to specify its namespace directly within the .info file.

Moreover, if you change all your modules namespace, it feels we are adding execution time because the original routine for registering namespace depends on module_list(). We can improve it.

Proposed resolution

Writing the namespace as following in the module's .info file:

name = My fancy module
description = My fancy description

namespace[] = MyFancyNamespace
namespace[] = MySecondComponentNamespace
namespace[] = ...

This make sense because we don't have to allocate a hook_init() for defining new classes. We can also re-factor the registering routing so that it register only the namespace needed and not the list of enabled modules, plus the custom namespaces which will overwrite default defined namespaces.


Viewing all articles
Browse latest Browse all 291123

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>