I'm building a small project using Composer, but I now have to use some custom code, in the parent folder of vendor folder.
Similar file structure: libraries > companyname > namespace > classfile.php
Is it possible to effectively use the composer autoloader? It seems that it is, but I'm having trouble wrapping my head around it.
Would it be easier to use a second autoloader script?
We're loading in our own code via composer.
Our code is installed in the lib folder under our company name. Our composer file looks like this.
{
"config": {
"vendor-dir": "lib"
},
"require": {
"twig/twig": "v1.15.1",
"symfony/symfony": "2.5.4"
},
"autoload": {
"psr-4": {
"CompanyName\\": "lib/companyName/src"
}
}
}
the autoload psr4 section is the important part. CompanyName
will resolve files located in lib/companyName/src
.
Inside lib/companyName/src, you'd have a file called ThingDoer.php
<?php
namespace CompanyName;
class ThingDoer {
public static function doThings() {}
}
And now from anywhere in your codebase, you can call CompanyName\ThingDoer::doThings();