|
|
@ -45,6 +45,7 @@ class EventDispatcher
|
|
|
|
protected $loader;
|
|
|
|
protected $loader;
|
|
|
|
protected $process;
|
|
|
|
protected $process;
|
|
|
|
protected $listeners;
|
|
|
|
protected $listeners;
|
|
|
|
|
|
|
|
private $eventStack;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
* Constructor.
|
|
|
@ -58,6 +59,7 @@ class EventDispatcher
|
|
|
|
$this->composer = $composer;
|
|
|
|
$this->composer = $composer;
|
|
|
|
$this->io = $io;
|
|
|
|
$this->io = $io;
|
|
|
|
$this->process = $process ?: new ProcessExecutor($io);
|
|
|
|
$this->process = $process ?: new ProcessExecutor($io);
|
|
|
|
|
|
|
|
$this->eventStack = array();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -145,11 +147,21 @@ class EventDispatcher
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$listeners = $this->getListeners($event);
|
|
|
|
$listeners = $this->getListeners($event);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->pushEvent($event);
|
|
|
|
|
|
|
|
|
|
|
|
$return = 0;
|
|
|
|
$return = 0;
|
|
|
|
foreach ($listeners as $callable) {
|
|
|
|
foreach ($listeners as $callable) {
|
|
|
|
if (!is_string($callable) && is_callable($callable)) {
|
|
|
|
if (!is_string($callable) && is_callable($callable)) {
|
|
|
|
$event = $this->checkListenerExpectedEvent($callable, $event);
|
|
|
|
$event = $this->checkListenerExpectedEvent($callable, $event);
|
|
|
|
$return = false === call_user_func($callable, $event) ? 1 : 0;
|
|
|
|
$return = false === call_user_func($callable, $event) ? 1 : 0;
|
|
|
|
|
|
|
|
} elseif ($this->isComposerScript($callable)) {
|
|
|
|
|
|
|
|
if ($this->io->isVerbose()) {
|
|
|
|
|
|
|
|
$this->io->writeError(sprintf('> %s: %s', $event->getName(), $callable));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$this->io->writeError(sprintf('> %s', $callable));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$scriptName = substr($callable, 1);
|
|
|
|
|
|
|
|
$return = $this->dispatch($scriptName, new Script\Event($scriptName, $event->getComposer(), $event->getIO(), $event->isDevMode()));
|
|
|
|
} elseif ($this->isPhpScript($callable)) {
|
|
|
|
} elseif ($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);
|
|
|
@ -190,6 +202,8 @@ class EventDispatcher
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->popEvent();
|
|
|
|
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -362,4 +376,42 @@ class EventDispatcher
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return false === strpos($callable, ' ') && false !== strpos($callable, '::');
|
|
|
|
return false === strpos($callable, ' ') && false !== strpos($callable, '::');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Checks if string given references a composer run-script
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param string $callable
|
|
|
|
|
|
|
|
* @return bool
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected function isComposerScript($callable)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return '@' === substr($callable, 0, 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Push an event to the stack of active event
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param Event $event
|
|
|
|
|
|
|
|
* @throws \RuntimeException
|
|
|
|
|
|
|
|
* @return number
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected function pushEvent(Event $event)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$eventName = $event->getName();
|
|
|
|
|
|
|
|
if (in_array($eventName, $this->eventStack)) {
|
|
|
|
|
|
|
|
throw new \RuntimeException(sprintf("Recursive call to '%s' detected", $eventName));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return array_push($this->eventStack, $eventName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Pops the active event from the stack
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return mixed
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected function popEvent()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return array_pop($this->eventStack);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|