1
0
Fork 0

Avoid passing args to CLI handlers when none are needed, fixes #3332

pull/3320/head
Jordi Boggiano 2014-10-07 11:05:05 +01:00
parent 382b6c64d5
commit 4ce9252255
5 changed files with 38 additions and 17 deletions

View File

@ -53,7 +53,7 @@ class AutoloadGenerator
public function dump(Config $config, InstalledRepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir, $scanPsr0Packages = false, $suffix = '')
{
$this->eventDispatcher->dispatchScript(ScriptEvents::PRE_AUTOLOAD_DUMP, $this->devMode, array(
$this->eventDispatcher->dispatchScript(ScriptEvents::PRE_AUTOLOAD_DUMP, $this->devMode, array(), array(
'optimize' => (bool) $scanPsr0Packages
));
@ -237,7 +237,7 @@ EOF;
fclose($targetLoader);
unset($sourceLoader, $targetLoader);
$this->eventDispatcher->dispatchScript(ScriptEvents::POST_AUTOLOAD_DUMP, $this->devMode, array(
$this->eventDispatcher->dispatchScript(ScriptEvents::POST_AUTOLOAD_DUMP, $this->devMode, array(), array(
'optimize' => (bool) $scanPsr0Packages,
));
}

View File

@ -25,10 +25,15 @@ class Event
protected $name;
/**
* @var array Arguments passed by the user
* @var array Arguments passed by the user, these will be forwarded to CLI script handlers
*/
protected $args;
/**
* @var array Flags usable in PHP script handlers
*/
protected $flags;
/**
* @var boolean Whether the event should not be passed to more listeners
*/
@ -38,12 +43,14 @@ class Event
* Constructor.
*
* @param string $name The event name
* @param array $events Arguments passed by the user
* @param array $args Arguments passed by the user
* @param array $flags Optional flags to pass data not as argument
*/
public function __construct($name, array $args = array())
public function __construct($name, array $args = array(), array $flags = array())
{
$this->name = $name;
$this->args = $args;
$this->flags = $flags;
}
/**
@ -66,6 +73,16 @@ class Event
return $this->args;
}
/**
* Returns the event's flags.
*
* @return array The event flags
*/
public function getFlags()
{
return $this->flags;
}
/**
* Checks if stopPropagation has been called
*

View File

@ -81,13 +81,14 @@ class EventDispatcher
*
* @param string $eventName The constant in ScriptEvents
* @param bool $devMode
* @param array $additionalArgs
* @param array $additionalArgs Arguments passed by the user
* @param array $flags Optional flags to pass data not as argument
* @return int return code of the executed script if any, for php scripts a false return
* value is changed to 1, anything else to 0
*/
public function dispatchScript($eventName, $devMode = false, $additionalArgs = array())
public function dispatchScript($eventName, $devMode = false, $additionalArgs = array(), $flags = array())
{
return $this->doDispatch(new Script\Event($eventName, $this->composer, $this->io, $devMode, $additionalArgs));
return $this->doDispatch(new Script\Event($eventName, $this->composer, $this->io, $devMode, $additionalArgs, $flags));
}
/**
@ -109,13 +110,14 @@ class EventDispatcher
*
* @param string $eventName The constant in ScriptEvents
* @param boolean $devMode Whether or not we are in dev mode
* @param array $additionalArgs
* @param array $additionalArgs Arguments passed by the user
* @param array $flags Optional flags to pass data not as argument
* @return int return code of the executed script if any, for php scripts a false return
* value is changed to 1, anything else to 0
*/
public function dispatchCommandEvent($eventName, $devMode, $additionalArgs = array())
public function dispatchCommandEvent($eventName, $devMode, $additionalArgs = array(), $flags = array())
{
return $this->doDispatch(new CommandEvent($eventName, $this->composer, $this->io, $devMode, $additionalArgs));
return $this->doDispatch(new CommandEvent($eventName, $this->composer, $this->io, $devMode, $additionalArgs, $flags));
}

View File

@ -45,11 +45,12 @@ class CommandEvent extends Event
* @param string $commandName The command name
* @param InputInterface $input
* @param OutputInterface $output
* @param array $events Arguments passed by the user
* @param array $args Arguments passed by the user
* @param array $flags Optional flags to pass data not as argument
*/
public function __construct($name, $commandName, $input, $output, array $args = array())
public function __construct($name, $commandName, $input, $output, array $args = array(), array $flags = array())
{
parent::__construct($name, $args);
parent::__construct($name, $args, $flags);
$this->commandName = $commandName;
$this->input = $input;
$this->output = $output;

View File

@ -46,11 +46,12 @@ class Event extends BaseEvent
* @param Composer $composer The composer object
* @param IOInterface $io The IOInterface object
* @param boolean $devMode Whether or not we are in dev mode
* @param array $events Arguments passed by the user
* @param array $args Arguments passed by the user
* @param array $flags Optional flags to pass data not as argument
*/
public function __construct($name, Composer $composer, IOInterface $io, $devMode = false, array $args = array())
public function __construct($name, Composer $composer, IOInterface $io, $devMode = false, array $args = array(), array $flags = array())
{
parent::__construct($name, $args);
parent::__construct($name, $args, $flags);
$this->composer = $composer;
$this->io = $io;
$this->devMode = $devMode;