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,10 +103,11 @@ class TriggerDispatcher
protected function getListeners(TriggerEvent $event) protected function getListeners(TriggerEvent $event)
{ {
$package = $this->composer->getPackage(); $package = $this->composer->getPackage();
$vendorDir = $this->composer->getInstallationManager()->getVendorPath(true);
$autoloadFile = $vendorDir . '/.composer/autoload.php';
$ex = $package->getExtra(); $ex = $package->getExtra();
$al = $package->getAutoload(); $al = $package->getAutoload();
$searchListeners = array(); $searchListeners = array();
$searchNamespaces = array();
$listeners = array(); $listeners = array();
$namespaces = array(); $namespaces = array();
@ -117,33 +118,33 @@ 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'])) { if (isset($al['psr-0'])) {
foreach ($al['psr-0'] as $ns => $path) { foreach ($al['psr-0'] as $ns => $path) {
$path = trim(realpath('.') . '/' . $path, '/'); if (!isset($namespaces[str_replace('\\', '\\\\', $ns)])) {
$searchNamespaces[$ns] = $path; $this->loader->add($ns, trim(realpath('.').'/'.$path, '/'));
} }
} }
// filter class::method have not a namespace registered
foreach ($searchNamespaces 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(); $this->loader->register();
$namespaces = $this->loader->getPrefixes();
}
// filter class::method have not a namespace registered
foreach ($namespaces as $ns => $path) {
foreach ($searchListeners as $method) {
if (0 === strpos($method, $ns)) {
$listeners[] = $method;
}
}
}
return $listeners; return $listeners;
} }