13
PHP 5.3 and the Symfony2 UniversalClassLoader – Where to load?
5 Comments · Posted by Christian in The right tool
While working on my rewrite of the ImageTransform library I decided to follow the PHP Standards Working Group proposal for naming schemes as well as using the new Symfony2 UniversalClassLoader.
But I’m not yet sure what is the best approach to use this loader.
When I started looking for examples I sent a small tweet which was replied to by Stefan Koopmanschap as he used this class loader in one of his own libraries.
What he did is to include the class/namespace registering code in one of the central classes of his library. If you take a look at my code you will see the same approach.
However this will not deliver instant plug’n'play imho as you still have to require this one class file to trigger the registration.
The more I think about the more I come to the conclusion that it is not advisable to include automatic class loading in library code as the user of your library still has to do it on his own even if you do some of it for him. This also puts the decision what kind of loading mechanism to use back in his hands.
The library code should assume that there is a loading mechanism in place thus not implementing any of its own nor hard wiring with require().
I actuaally realized that when I wrote the bootstrap file for my PHPUnit tests. Unit tests are client code that use parts of the library they test. If they would have to include this central class only to have all other classes of the library available then this would be a case of coupling that I wanted to get rid of in the first place.
So instead of including calls to UniversialClassLoader I will eventually only mention it in the docs I think.
phpUnit · Separation of Concerns · Symfony2
<< [Question] Inject or map or annotate – how to manage dependencies for PHP library code?


Pingback: Tweets that mention • PHP 5.3 and the Symfony2 UniversalClassLoader – Where to load? | test.ical.ly -- Topsy.com
Pingback: Test.ical.ly Blog: PHP 5.3 and the Symfony2 UniversalClassLoader - Where to load? | Development Blog With Code Updates : Developercast.com