Add .composer/autoload.php in namespace loader
parent
f017074655
commit
0bcf3c26d9
|
@ -103,11 +103,12 @@ 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();
|
||||||
|
|
||||||
// get classes
|
// 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'])) {
|
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, '/'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->loader->register();
|
||||||
|
$namespaces = $this->loader->getPrefixes();
|
||||||
}
|
}
|
||||||
|
|
||||||
// filter class::method have not a namespace registered
|
// filter class::method have not a namespace registered
|
||||||
foreach ($searchNamespaces as $ns => $path) {
|
foreach ($namespaces as $ns => $path) {
|
||||||
foreach ($searchListeners as $method) {
|
foreach ($searchListeners as $method) {
|
||||||
if (0 === strpos($method, $ns)) {
|
if (0 === strpos($method, $ns)) {
|
||||||
$listeners[] = $method;
|
$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;
|
return $listeners;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue