WP_CLI
Autoloader::add_namespace
Add a specific namespace structure with our custom autoloader.
Method of the class: Autoloader{}
No Hooks.
Returns
self.
Usage
$Autoloader = new Autoloader(); $Autoloader->add_namespace( $root, $base_dir, $prefix, $suffix, $lowercase, $underscores );
- $root(string) (required)
- Root namespace name.
- $base_dir(string) (required)
- Directory containing the class files.
- $prefix(string)
- Prefix to be added before the class.
Default:'' - $suffix(string)
- Suffix to be added after the class.
Default:'.php' - $lowercase(true|false)
- Whether the class should be changed to lowercase.
Default:false - $underscores(true|false)
- Whether the underscores should be changed to hyphens.
Default:false
Autoloader::add_namespace() Autoloader::add namespace code WP-CLI 2.13.0-alpha
public function add_namespace(
$root,
$base_dir,
$prefix = '',
$suffix = '.php',
$lowercase = false,
$underscores = false
) {
$this->namespaces[] = [
'root' => $this->normalize_root( (string) $root ),
'base_dir' => $this->add_trailing_slash( (string) $base_dir ),
'prefix' => (string) $prefix,
'suffix' => (string) $suffix,
'lowercase' => (bool) $lowercase,
'underscores' => (bool) $underscores,
];
return $this;
}