You are here

function Main::registerModule in X Autoload 7.4

Same name and namespace in other branches
  1. 7.5 src/Main.php \Drupal\xautoload\Main::registerModule()

Register a module in early bootstrap, or from modulename.install.

This is only needed for modules that need autoloading very early in the request, or e.g. during uninstall, or any situation that xautoload cannot catch up with.

The method will register all autoloading schemes for this module that are supported by default:

  • PSR-0: "Drupal\\$module\\Foo" => "$module_dir/lib/Drupal/$module/Foo.php"
  • PEAR-FLAT: $module . "_Foo_Bar" => "$module_dir/lib/Foo/Bar.php"

It will not register anything for PSR-4, since it is not clear whether this will be in "/lib/" or "/src/" or elsewhere.

Suggested usage: (in your $modulename.module, or $modulename.install):

xautoload()->registerModule(__FILE__);

Parameters

string $__FILE__: File path to a *.module or *.install file. The basename of the file MUST be the module name. It is recommended to call this from the respective file itself, using the __FILE__ constant for this argument.

File

lib/Main.php, line 62

Class

Main

Namespace

Drupal\xautoload

Code

function registerModule($__FILE__) {
  $info = pathinfo($__FILE__);
  $name = $info['filename'];
  $dir = $info['dirname'];
  $this->extensionRegistrationService
    ->registerExtension($name, 'module', $dir);
}