|
|
@ -16,6 +16,7 @@ use Composer\Autoload\AutoloadGenerator;
|
|
|
|
use Composer\IO\IOInterface;
|
|
|
|
use Composer\IO\IOInterface;
|
|
|
|
use Composer\Composer;
|
|
|
|
use Composer\Composer;
|
|
|
|
use Composer\DependencyResolver\Operation\OperationInterface;
|
|
|
|
use Composer\DependencyResolver\Operation\OperationInterface;
|
|
|
|
|
|
|
|
use Composer\Util\ProcessExecutor;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* The Event Dispatcher.
|
|
|
|
* The Event Dispatcher.
|
|
|
@ -34,6 +35,7 @@ class EventDispatcher
|
|
|
|
protected $composer;
|
|
|
|
protected $composer;
|
|
|
|
protected $io;
|
|
|
|
protected $io;
|
|
|
|
protected $loader;
|
|
|
|
protected $loader;
|
|
|
|
|
|
|
|
protected $process;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
* Constructor.
|
|
|
@ -41,10 +43,11 @@ class EventDispatcher
|
|
|
|
* @param Composer $composer The composer instance
|
|
|
|
* @param Composer $composer The composer instance
|
|
|
|
* @param IOInterface $io The IOInterface instance
|
|
|
|
* @param IOInterface $io The IOInterface instance
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function __construct(Composer $composer, IOInterface $io)
|
|
|
|
public function __construct(Composer $composer, IOInterface $io, ProcessExecutor $process = null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$this->composer = $composer;
|
|
|
|
$this->composer = $composer;
|
|
|
|
$this->io = $io;
|
|
|
|
$this->io = $io;
|
|
|
|
|
|
|
|
$this->process = $process ?: new ProcessExecutor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -78,6 +81,7 @@ class EventDispatcher
|
|
|
|
$listeners = $this->getListeners($event);
|
|
|
|
$listeners = $this->getListeners($event);
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($listeners as $callable) {
|
|
|
|
foreach ($listeners as $callable) {
|
|
|
|
|
|
|
|
if ($this->isPhpScript($callable)) {
|
|
|
|
$className = substr($callable, 0, strpos($callable, '::'));
|
|
|
|
$className = substr($callable, 0, strpos($callable, '::'));
|
|
|
|
$methodName = substr($callable, strpos($callable, '::') + 2);
|
|
|
|
$methodName = substr($callable, strpos($callable, '::') + 2);
|
|
|
|
|
|
|
|
|
|
|
@ -91,15 +95,37 @@ class EventDispatcher
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
$className::$methodName($event);
|
|
|
|
$this->executeEventPhpScript($className, $methodName, $event);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$message = "Script %s handling the %s event terminated with an exception";
|
|
|
|
$message = "Script %s handling the %s event terminated with an exception";
|
|
|
|
$this->io->write('<error>'.sprintf($message, $callable, $event->getName()).'</error>');
|
|
|
|
$this->io->write('<error>'.sprintf($message, $callable, $event->getName()).'</error>');
|
|
|
|
throw $e;
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$callback = function ($type, $buffer) use ($event, $callable) {
|
|
|
|
|
|
|
|
$io = $event->getIO();
|
|
|
|
|
|
|
|
if ('err' === $type) {
|
|
|
|
|
|
|
|
$message = 'Script %s handling the %s event returned an error: %s';
|
|
|
|
|
|
|
|
$io->write(sprintf('<error>'.$message.'</error>', $callable, $event->getName(), $buffer));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$io->write($buffer, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
$this->process->execute($callable, $callback);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @param string $className
|
|
|
|
|
|
|
|
* @param string $methodName
|
|
|
|
|
|
|
|
* @param Event $event Event invoking the PHP callable
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected function executeEventPhpScript($className, $methodName, Event $event)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$className::$methodName($event);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param Event $event Event object
|
|
|
|
* @param Event $event Event object
|
|
|
|
* @return array Listeners
|
|
|
|
* @return array Listeners
|
|
|
@ -126,4 +152,15 @@ class EventDispatcher
|
|
|
|
|
|
|
|
|
|
|
|
return $scripts[$event->getName()];
|
|
|
|
return $scripts[$event->getName()];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Checks if string given references a class path and method
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param string $callable
|
|
|
|
|
|
|
|
* @return boolean
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected function isPhpScript($callable)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return false === strpos($callable, ' ') && false !== strpos($callable, '::');
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|