You are here

function Main::registerModulePsr4 in X Autoload 7.5

Same name and namespace in other branches
  1. 7.4 lib/Main.php \Drupal\xautoload\Main::registerModulePsr4()

Register a module as PSR-4, in early bootstrap or from modulename.install

This can be used while Drupal 8 is still undecided whether PSR-4 class files should live in "lib" or in "src" by default.

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

// E.g. "Drupal\\$module\\Foo" => "$module_dir/lib/Foo.php" xautoload()->registerModulePsr4(__FILE__, 'lib');

or

// E.g. "Drupal\\$module\\Foo" => "$module_dir/src/Foo.php" xautoload()->registerModulePsr4(__FILE__, 'src');

or

// E.g. "Drupal\\$module\\Foo" => "$module_dir/psr4/Foo.php" xautoload()->registerModulePsr4(__FILE__, 'psr4');

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.

string $subdir: The PSR-4 base directory for the module namespace, relative to the module directory. E.g. "src" or "lib".

File

src/Main.php, line 96

Class

Main

Namespace

Drupal\xautoload

Code

function registerModulePsr4($__FILE__, $subdir) {
  $this->services->extensionNamespaces
    ->registerExtensionPsr4($__FILE__, $subdir);
}