Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoload files - load vendors first #956

Closed
Vrtak-CZ opened this issue Jul 30, 2012 · 11 comments · Fixed by #1051 or #1223
Closed

Autoload files - load vendors first #956

Vrtak-CZ opened this issue Jul 30, 2012 · 11 comments · Fixed by #1051 or #1223
Labels
Milestone

Comments

@Vrtak-CZ
Copy link

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.

@stof
Copy link
Contributor

stof commented Jul 30, 2012

@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.

@Seldaek
Copy link
Member

Seldaek commented Aug 10, 2012

Yup that makes sense, not sure how easy it is to achieve though after the first run I think it's quite random.

@naderman
Copy link
Member

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 :)

@naderman
Copy link
Member

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.

@Vrtak-CZ
Copy link
Author

@fprochazka
Copy link
Contributor

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.

@Seldaek
Copy link
Member

Seldaek commented Sep 7, 2012

Merged @hosiplan's fix.

@chez14
Copy link

chez14 commented Oct 14, 2016

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.

@Wirone
Copy link
Contributor

Wirone commented Nov 25, 2016

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.

@paslandau
Copy link

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

@chez14
Copy link

chez14 commented Jan 26, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
8 participants