I'm using autoloading with custom files loader. And I have a problem because my loader depends some classes from vendors. But composer require my loader before vendor loader.
Here is generated autoloader.php
:
<?php
// autoload.php generated by Composer
if (!class_exists('Composer\\Autoload\\ClassLoader', false)) {
require __DIR__ . '/composer' . '/ClassLoader.php';
}
return call_user_func(function() {
$loader = new \Composer\Autoload\ClassLoader();
$composerDir = __DIR__ . '/composer';
$map = require $composerDir . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
$loader->add($namespace, $path);
}
$classMap = require $composerDir . '/autoload_classmap.php';
if ($classMap) {
$loader->addClassMap($classMap);
}
$loader->register();
require $baseDir . '/Nella/loader.php'; // <-- my libs
require $vendorDir . '/nette/nette/Nette/loader.php'; // <-- vendor libs
return $loader;
});
I need load _Nette_ before my libs (_Nella_) because my (_Nella_) loader require some classes from _Nette_.
@Seldaek I guess the order here should respect the order found when resolving the dependencies, so that the autoloading file of a dependency is loaded before the file of a package depending on it.
Yup that makes sense, not sure how easy it is to achieve though after the first run I think it's quite random.
I'm not entirely sure I get this? All autoloaders will be required, and then the order should not matter?
Edit: nevermind I get it :)
The solver should already be returning these in the correct order in the transaction, including the case when packages are already installed, so not sure why the order would be incorrect.
Here is my _composer.json_ https://github.com/nella/framework/blob/composer/composer.json
I've just experienced the same issue with kdyby/forms-replicator
{
"name":"kdyby/forms-replicator",
"require":{
"php":">=5.3.2",
"nette/nette":"*"
},
"autoload":{
"files":["Replicator.php"]
}
}
The order of require
in autoload_real.php
should correspond to how the packages require each other.
Merged @HosipLan's fix.
How to mark that our lib should be loaded first?
I mean, it didn't depends on other, but its should be loaded first before anything else load.
I have the same question as @onlyongunz - I have globally installed apigen/apigen
and symfony/var-dumper
, but when I use dump()
version from tracy/tracy
(required by ApiGen) is called. I want to use VarDumper's version.
Would be nice to be able to define the order. Or even better: have an extra option to define files that need to be loaded first.
Use case: Trying to override the helper functions of laravel as they are specifically defined with that in mind, but there is no way to tell composer that my definition has to come before laravel's native one.
Workaround: https://github.com/funkjedi/composer-include-files
Well i think i'll sugest load_first
to prioritize the package on load when it didn't depend on other liblary (unless it's php or something else), and add --ignore-order
to ignore the load_first
.
Most helpful comment
Would be nice to be able to define the order. Or even better: have an extra option to define files that need to be loaded first.
Use case: Trying to override the helper functions of laravel as they are specifically defined with that in mind, but there is no way to tell composer that my definition has to come before laravel's native one.
Context: https://laracasts.com/index.php/discuss/channels/general-discussion/override-functions-in-supporthelpersphp
Workaround: https://github.com/funkjedi/composer-include-files