Giter Site home page Giter Site logo

Comments (4)

igorw avatar igorw commented on May 2, 2024

Actually, since PSR-0 is backward-compatible with PEAR, it is supported. You just need to do prefix matching:

$loader = new ClassLoader();
$loader->add('Twig_', __DIR__.'/vendor/twig/lib');
$loader->add('Symfony\\', __DIR__.'/vendor/symfony/src');
$loader->register();

The current loader does support multiple directories per namespace, you just need to set them in the initial add() call. Being able to add others later is a detail, and could easily be added.

from composer.

stof avatar stof commented on May 2, 2024

Another argument to generate a map instead of the autoloader: PHP 5.4 is likely to have an SplClassLoader which will probably be more efficient than PHP implementations so it should be possible to use it.

from composer.

naderman avatar naderman commented on May 2, 2024

As per Igor, the class loader in composer is just as powerful as the Symfony2 one, it's just a lot simpler. However I agree that generating just the map in case someone wants to use their own autoloader, but the default mappings, makes sense. So I would simply generate both. One file with the mappings, one file with a default autoloader and one file which adds the map entries to the default auto loader. A project can then decide on its own which file(s) to include.

from composer.

Seldaek avatar Seldaek commented on May 2, 2024

@fabpot: As @igorw said, it is compatible with PEAR. The implementation is more than sufficient imo. The fallbacks and such can easily be done in a second autoloader if that is required, but IMO it'd be just as easy to allow users to configure their namespaces in their composer.json file too. Usually you have only one namespace in the src/ dir anyway.

@stof: You may have noticed that I used add() and register() which AFAIK are the proposed method names for the SplClassLoader (the new version, not the one in the RFC). The point being that we could just use the php one if it's available, once it's merged. Whatever happens with that I'll definitely keep our autoloader in sync. I want it to be a fallback implementation and that's it. Unless the one in core is really not made flexible enough, in which case we can still extend from it or wrap it to speed things up a bit.

Another thing regarding generating a map, I don't really like this too much because I don't think every single project should have an autoloader. It's just commodity stuff that should be given for free. What I would like to do though is have a command that will generate a hardcoded MapClassLoader-like thing on demand. For production this would be nice.

from composer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.