1
0
Fork 0

Pass the current dev mode to the event dispatcher, which in turn passes it to the events fired. This can be fetched in scripts to check which mode we are currently in

pull/1331/head
Christer Edvartsen 2012-11-15 15:29:25 +01:00
parent 172414a1f0
commit 4b8813269c
5 changed files with 35 additions and 15 deletions

View File

@ -179,7 +179,7 @@ class Installer
if ($this->runScripts) { if ($this->runScripts) {
// dispatch pre event // dispatch pre event
$eventName = $this->update ? ScriptEvents::PRE_UPDATE_CMD : ScriptEvents::PRE_INSTALL_CMD; $eventName = $this->update ? ScriptEvents::PRE_UPDATE_CMD : ScriptEvents::PRE_INSTALL_CMD;
$this->eventDispatcher->dispatchCommandEvent($eventName); $this->eventDispatcher->dispatchCommandEvent($eventName, $this->devMode);
} }
$this->suggestedPackages = array(); $this->suggestedPackages = array();
@ -227,7 +227,7 @@ class Installer
if ($this->runScripts) { if ($this->runScripts) {
// dispatch post event // dispatch post event
$eventName = $this->update ? ScriptEvents::POST_UPDATE_CMD : ScriptEvents::POST_INSTALL_CMD; $eventName = $this->update ? ScriptEvents::POST_UPDATE_CMD : ScriptEvents::POST_INSTALL_CMD;
$this->eventDispatcher->dispatchCommandEvent($eventName); $this->eventDispatcher->dispatchCommandEvent($eventName, $this->devMode);
} }
} }
@ -487,7 +487,7 @@ class Installer
$event = 'Composer\Script\ScriptEvents::PRE_PACKAGE_'.strtoupper($operation->getJobType()); $event = 'Composer\Script\ScriptEvents::PRE_PACKAGE_'.strtoupper($operation->getJobType());
if (defined($event) && $this->runScripts) { if (defined($event) && $this->runScripts) {
$this->eventDispatcher->dispatchPackageEvent(constant($event), $operation); $this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $operation);
} }
// not installing from lock, force dev packages' references if they're in root package refs // not installing from lock, force dev packages' references if they're in root package refs
@ -516,7 +516,7 @@ class Installer
$event = 'Composer\Script\ScriptEvents::POST_PACKAGE_'.strtoupper($operation->getJobType()); $event = 'Composer\Script\ScriptEvents::POST_PACKAGE_'.strtoupper($operation->getJobType());
if (defined($event) && $this->runScripts) { if (defined($event) && $this->runScripts) {
$this->eventDispatcher->dispatchPackageEvent(constant($event), $operation); $this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $operation);
} }
if (!$this->dryRun) { if (!$this->dryRun) {

View File

@ -37,18 +37,25 @@ class Event
*/ */
private $io; private $io;
/**
* @var boolean Dev mode flag
*/
private $devMode;
/** /**
* Constructor. * Constructor.
* *
* @param string $name The event name * @param string $name The event name
* @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
*/ */
public function __construct($name, Composer $composer, IOInterface $io) public function __construct($name, Composer $composer, IOInterface $io, $devMode)
{ {
$this->name = $name; $this->name = $name;
$this->composer = $composer; $this->composer = $composer;
$this->io = $io; $this->io = $io;
$this->devMode = $devMode;
} }
/** /**
@ -80,4 +87,14 @@ class Event
{ {
return $this->io; return $this->io;
} }
/**
* Return the dev mode flag
*
* @return boolean
*/
public function isDevMode()
{
return $this->devMode;
}
} }

View File

@ -55,21 +55,23 @@ class EventDispatcher
* Dispatch a package event. * Dispatch a package event.
* *
* @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 OperationInterface $operation The package being installed/updated/removed * @param OperationInterface $operation The package being installed/updated/removed
*/ */
public function dispatchPackageEvent($eventName, OperationInterface $operation) public function dispatchPackageEvent($eventName, $devMode, OperationInterface $operation)
{ {
$this->doDispatch(new PackageEvent($eventName, $this->composer, $this->io, $operation)); $this->doDispatch(new PackageEvent($eventName, $this->composer, $this->io, $devMode, $operation));
} }
/** /**
* Dispatch a command event. * Dispatch a command event.
* *
* @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
*/ */
public function dispatchCommandEvent($eventName) public function dispatchCommandEvent($eventName, $devMode)
{ {
$this->doDispatch(new CommandEvent($eventName, $this->composer, $this->io)); $this->doDispatch(new CommandEvent($eventName, $this->composer, $this->io, $devMode));
} }
/** /**

View File

@ -34,11 +34,12 @@ class PackageEvent extends Event
* @param string $name The event name * @param string $name The event name
* @param Composer $composer The composer objet * @param Composer $composer The composer objet
* @param IOInterface $io The IOInterface object * @param IOInterface $io The IOInterface object
* @param boolean $devMode Whether or not we are in dev mode
* @param OperationInterface $operation The operation object * @param OperationInterface $operation The operation object
*/ */
public function __construct($name, Composer $composer, IOInterface $io, OperationInterface $operation) public function __construct($name, Composer $composer, IOInterface $io, $devMode, OperationInterface $operation)
{ {
parent::__construct($name, $composer, $io); parent::__construct($name, $composer, $io, $devMode);
$this->operation = $operation; $this->operation = $operation;
} }

View File

@ -32,7 +32,7 @@ class EventDispatcherTest extends TestCase
->method('write') ->method('write')
->with('<error>Script Composer\Test\Script\EventDispatcherTest::call handling the post-install-cmd event terminated with an exception</error>'); ->with('<error>Script Composer\Test\Script\EventDispatcherTest::call handling the post-install-cmd event terminated with an exception</error>');
$dispatcher->dispatchCommandEvent("post-install-cmd"); $dispatcher->dispatchCommandEvent("post-install-cmd", false);
} }
/** /**
@ -60,7 +60,7 @@ class EventDispatcherTest extends TestCase
->method('execute') ->method('execute')
->with($command); ->with($command);
$dispatcher->dispatchCommandEvent("post-install-cmd"); $dispatcher->dispatchCommandEvent("post-install-cmd", false);
} }
public function testDispatcherCanExecuteCliAndPhpInSameEventScriptStack() public function testDispatcherCanExecuteCliAndPhpInSameEventScriptStack()
@ -95,7 +95,7 @@ class EventDispatcherTest extends TestCase
->with('Composer\Test\Script\EventDispatcherTest', 'someMethod') ->with('Composer\Test\Script\EventDispatcherTest', 'someMethod')
->will($this->returnValue(true)); ->will($this->returnValue(true));
$dispatcher->dispatchCommandEvent("post-install-cmd"); $dispatcher->dispatchCommandEvent("post-install-cmd", false);
} }
private function getDispatcherStubForListenersTest($listeners, $io) private function getDispatcherStubForListenersTest($listeners, $io)