How to Use the Composer Autoloader in Your Project
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:
Scott Keck-Warren
Scott is the Director of Technology at WeCare Connect where he strives to provide solutions for his customers needs. He's the father of two and can be found most weekends working on projects around the house with his loving partner.
Top Posts
- Working With Soft Deletes in Laravel (By Example)
- Fixing CMake was unable to find a build program corresponding to "Unix Makefiles"
- Upgrading to Laravel 8.x
- Get The Count of the Number of Users in an AD Group
- Multiple Vagrant VMs in One Vagrantfile
- Fixing the "this is larger than GitHub's recommended maximum file size of 50.00 MB" error
- Changing the Directory Vagrant Stores the VMs In
- Accepting Android SDK Licenses From The OSX Command Line
- Fixing the 'Target class [config] does not exist' Error
- Using Rectangle to Manage MacOS Windows