Since we like Phalcon and composer, we're using both of them.
What I don't like is to have two different autoloaders so I wrote this part of code (which i'm not very proud of), to be able to use Phalcon autoloader instead of composer one :
$loader = new \Phalcon\Loader();
$namespaces = [
// internal namespaces which could also be done proper using composer.json
];
// get namespaces from Composer
$map = require $config->application->vendorDir . 'composer/autoload_namespaces.php';
foreach ($map as $k => $values) {
$k = trim($k, '\\');
if (!isset($namespaces[$k])) {
$dir = '/' . str_replace('\\', '/', $k) . '/';
$namespaces[$k] = implode($dir . ';', $values) . $dir;
}
}
$loader->registerNamespaces($namespaces);
$classMap = require $config->application->vendorDir . 'composer/autoload_classmap.php';
$loader->registerClasses($classMap);
$loader->register();
this code doesn't take care of PSR4 composer parts, but at this time it does the job.
What do you think of it ?
I've got one problem with it, Phalcon loader seems to lack the ability to have multiple dir for the same namespace which exists in composer. At this time i've got incubator & dev-tools in my projet, so one of the two projects is not treated in this autoloader. Is it me or does phalcon lacks this functionality ?
Duplicate from an issue posted on github (https://github.com/phalcon/incubator/issues/164), but I really don't know where it should be posted...