Answer the question
In order to leave comments, you need to log in
How to use autoload.php from composer?
The project had a class autoloader
class Loader {
public static function init() {
spl_autoload_register( [new self, 'autoload'] );
}
public function autoload($className)
{
$className = ltrim($className, '\\');
$fileName = '';
$namespace = '';
if ($lastNsPos = strripos($className, '\\')) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
$fileName .= $className . '.php';
if ( is_readable( $fileName) ) {
include $fileName;
}
}
}
Answer the question
In order to leave comments, you need to log in
Taken from Composer Cheat Sheet for developers .
Here's a more extended example:
"autoload": {
"psr-4": {
"Application\\": "module/Application/src/",
"Vendor\\Namespace\\": ""
},
"psr-0": {
"Monolog": "src/",
"Vendor\\Namespace": ["src/", "lib/"],
"Pear_Style": "src/",
"": "src/"
},
"classmap": ["src/", "lib/", "Something.php"],
"files": ["src/MyLibrary/functions.php"]
},
"config": {
"optimize-autoloader": true
},
$ php composer.phar dump-autoload --optimize
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question