I have
"autoload": {
"psr-4": {
"ACME": "src/",
},
"classmap": ["src/"],
"files": ["mapper.php"],
"exclude-from-classmap": ["mapper.php"]
},
in mapper.php I'm trying to give different namespaces for some legacy stuff.
<?php
class_alias(Some_Class::class, 'Cool\NameSpaced\Class');
I think this fails to build because mapper.php is using classes in src/ and they have not been loaded by composer yet. Is there a way to do this?
Command that I run is composer install --optimize-autoloader --no-dev
I've tried you example and it works well.
It might be related to composer command you use. Try this one instead:
composer dump-autoload
This will refresh anything from autoload section.
Here is the setup file by file:
composer.json{
"autoload": {
"classmap": ["src/"],
"files": ["mapper.php"]
}
}
mapper.php<?php
class_alias(Some_Class::class, 'Cool\NameSpaced\Class');
index.php<?php
require __DIR__ . '/vendor/autoload.php';
var_dump(class_exists(Some_Class::class));
var_dump(class_exists('Cool\NameSpaced\Class'));
$ composer dump-autoload
$ php index.php
bool(true);
bool(true);
commposer.json{
"autoload": {
"classmap": ["src/"]
}
}
$ composer dump-autoload
$ php index.php
bool(true);
bool(false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With