I’m slowly working on a script to add some measureability to our code base and I wanted to use the composer autoloader. I wanted to document how it was I did this for the next time I need it.
To start you need to add the autoload key to your composer.json file. The top level namspace needs to replace Managertools in this example:
Then you need to run composer to setup up it’s autoloader to use your namespace:
Finally, you’ll need to add the composer autoload.php file to your script. It should look something like this:
If you’re using PHPUnit for testing (and I highly recommend you do) you’ll need to add a Bootstrap file to your config:
With the following contents:
Like this post? Don't forget to follow us on Twitter and Facebook for updates.