1
0
Fork 0

Add .composer/autoload.php in namespace loader

pull/257/head
François Pluchino 2012-01-25 17:08:06 +01:00
parent f017074655
commit 0bcf3c26d9
1 changed files with 18 additions and 17 deletions

View File

@ -103,11 +103,12 @@ class TriggerDispatcher
protected function getListeners(TriggerEvent $event)
{
$package = $this->composer->getPackage();
$vendorDir = $this->composer->getInstallationManager()->getVendorPath(true);
$autoloadFile = $vendorDir . '/.composer/autoload.php';
$ex = $package->getExtra();
$al = $package->getAutoload();
$searchListeners = array();
$searchNamespaces = array();
$listeners = array();
$listeners = array();
$namespaces = array();
// get classes
@ -117,34 +118,34 @@ class TriggerDispatcher
}
}
// get namespaces
// get autoload namespaces
if (file_exists($autoloadFile)) {
$this->loader = require $autoloadFile;
}
$namespaces = $this->loader->getPrefixes();
// get namespaces in composer.json project
if (isset($al['psr-0'])) {
foreach ($al['psr-0'] as $ns => $path) {
$path = trim(realpath('.') . '/' . $path, '/');
$searchNamespaces[$ns] = $path;
if (!isset($namespaces[str_replace('\\', '\\\\', $ns)])) {
$this->loader->add($ns, trim(realpath('.').'/'.$path, '/'));
}
}
$this->loader->register();
$namespaces = $this->loader->getPrefixes();
}
// filter class::method have not a namespace registered
foreach ($searchNamespaces as $ns => $path) {
foreach ($namespaces as $ns => $path) {
foreach ($searchListeners as $method) {
if (0 === strpos($method, $ns)) {
$listeners[] = $method;
if (!in_array($ns, array_keys($namespaces))) {
$namespaces[$ns] = $path;
}
}
}
}
// register namespaces in class loader
foreach ($namespaces as $ns => $path) {
$this->loader->add($ns, $path);
}
$this->loader->register();
return $listeners;
}
}