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

main
Jordi Boggiano 10 years ago
parent 382b6c64d5
commit 4ce9252255

@ -53,7 +53,7 @@ class AutoloadGenerator
public function dump(Config $config, InstalledRepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir, $scanPsr0Packages = false, $suffix = '') 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 'optimize' => (bool) $scanPsr0Packages
)); ));
@ -237,7 +237,7 @@ EOF;
fclose($targetLoader); fclose($targetLoader);
unset($sourceLoader, $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, 'optimize' => (bool) $scanPsr0Packages,
)); ));
} }

@ -25,10 +25,15 @@ class Event
protected $name; 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; protected $args;
/**
* @var array Flags usable in PHP script handlers
*/
protected $flags;
/** /**
* @var boolean Whether the event should not be passed to more listeners * @var boolean Whether the event should not be passed to more listeners
*/ */
@ -38,12 +43,14 @@ class Event
* Constructor. * Constructor.
* *
* @param string $name The event name * @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->name = $name;
$this->args = $args; $this->args = $args;
$this->flags = $flags;
} }
/** /**
@ -66,6 +73,16 @@ class Event
return $this->args; 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 * Checks if stopPropagation has been called
* *

@ -81,13 +81,14 @@ class EventDispatcher
* *
* @param string $eventName The constant in ScriptEvents * @param string $eventName The constant in ScriptEvents
* @param bool $devMode * @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 * @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 * 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 string $eventName The constant in ScriptEvents
* @param boolean $devMode Whether or not we are in dev mode * @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 * @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 * 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));
} }

@ -45,11 +45,12 @@ class CommandEvent extends Event
* @param string $commandName The command name * @param string $commandName The command name
* @param InputInterface $input * @param InputInterface $input
* @param OutputInterface $output * @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->commandName = $commandName;
$this->input = $input; $this->input = $input;
$this->output = $output; $this->output = $output;

@ -46,11 +46,12 @@ class Event extends BaseEvent
* @param Composer $composer The composer object * @param Composer $composer The composer object
* @param IOInterface $io The IOInterface object * @param IOInterface $io The IOInterface object
* @param boolean $devMode Whether or not we are in dev mode * @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->composer = $composer;
$this->io = $io; $this->io = $io;
$this->devMode = $devMode; $this->devMode = $devMode;

Loading…
Cancel
Save