Replace or overload the autoloader (or class finder) for some package ?

144 views
Skip to first unread message

Nicolas

unread,
Mar 16, 2013, 5:56:47 AM3/16/13
to compose...@googlegroups.com
Hello,

I'm stuck since a few days, I want to use my autoloader for some package.

Is it possible to retrieve the definition of classpath in composer.json and use my autoloader or a custom class finder function ?

"autoload": { "psr-0": {"Acme": "src/"} }

There may be simpler ... what I want to do exactly :

I have a classpath specific for each vendor and plugin (e.g: plugin/Acme), in my framework it is possible to replace a class by putting a class with the same name in the folder app/custom (e.g: app/custom/Acme/TheClass).

This process is managed by my autoloader but with composer it does not work :(

An idea please ?

Jordi Boggiano

unread,
Mar 16, 2013, 10:38:11 AM3/16/13
to compose...@googlegroups.com
Heya,

> I'm stuck since a few days, I want to use my autoloader for some package.
>
> Is it possible to retrieve the definition of classpath in composer.json
> and use my autoloader or a custom class finder function ?
>
> "autoload": { "psr-0": {"Acme": "src/"} }
>
> There may be simpler ... what I want to do exactly :
>
> I have a classpath specific for each vendor and plugin (e.g:
> plugin/Acme), in my framework it is possible to replace a class by
> putting a class with the same name in the folder app/custom (e.g:
> app/custom/Acme/TheClass).

You can do "psr-0": {"Acme": ["app/custom/", "src/"]} - then it will
always check first in app/custom and fallback to src.

I would recommend using some sort of dependency injection instead of
relying on class name overrides though. It allows you to extend the
original class and overriding only the relevant parts instead of having
to copy paste it entirely. Makes such "hacks" more maintainable.

Cheers

--
Jordi Boggiano
@seldaek - http://nelm.io/jordi

Nicolas

unread,
Mar 16, 2013, 9:40:57 PM3/16/13
to compose...@googlegroups.com
Thanks for your reply Jordi.

I use the dependency injection but not this type case, I will not touch the original package (example composer.json of Monolog). A package 
It allows me also to extend the original class and overriding only the relevant parts instead. Not copy paste entirely the code.

It is true that it reduces maintainability. An external package can use classes of another external package, this is the best way I have to capture it on the fly without touching the original packages whose I am not the author.

Cheers
Nicolas
PS : Sorry for my broken english.
Reply all
Reply to author
Forward
0 new messages