Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Pass the current dev mode to the event dispatcher, which in turn pass…

…es it to the events fired. This can be fetched in scripts to check which mode we are currently in
  • Loading branch information...
commit 4b8813269c3d365285512f2386e25cea528ee2c4 1 parent 172414a
@christeredvartsen christeredvartsen authored
View
8 src/Composer/Installer.php
@@ -179,7 +179,7 @@ public function run()
if ($this->runScripts) {
// dispatch pre event
$eventName = $this->update ? ScriptEvents::PRE_UPDATE_CMD : ScriptEvents::PRE_INSTALL_CMD;
- $this->eventDispatcher->dispatchCommandEvent($eventName);
+ $this->eventDispatcher->dispatchCommandEvent($eventName, $this->devMode);
}
$this->suggestedPackages = array();
@@ -227,7 +227,7 @@ public function run()
if ($this->runScripts) {
// dispatch post event
$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 @@ protected function doInstall($localRepo, $installedRepo, $aliases, $devMode = fa
$event = 'Composer\Script\ScriptEvents::PRE_PACKAGE_'.strtoupper($operation->getJobType());
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
@@ -516,7 +516,7 @@ protected function doInstall($localRepo, $installedRepo, $aliases, $devMode = fa
$event = 'Composer\Script\ScriptEvents::POST_PACKAGE_'.strtoupper($operation->getJobType());
if (defined($event) && $this->runScripts) {
- $this->eventDispatcher->dispatchPackageEvent(constant($event), $operation);
+ $this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $operation);
}
if (!$this->dryRun) {
View
19 src/Composer/Script/Event.php
@@ -38,17 +38,24 @@ class Event
private $io;
/**
+ * @var boolean Dev mode flag
+ */
+ private $devMode;
+
+ /**
* Constructor.
*
* @param string $name The event name
* @param Composer $composer The composer 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->composer = $composer;
$this->io = $io;
+ $this->devMode = $devMode;
}
/**
@@ -80,4 +87,14 @@ public function getIO()
{
return $this->io;
}
+
+ /**
+ * Return the dev mode flag
+ *
+ * @return boolean
+ */
+ public function isDevMode()
+ {
+ return $this->devMode;
+ }
}
View
12 src/Composer/Script/EventDispatcher.php
@@ -55,21 +55,23 @@ public function __construct(Composer $composer, IOInterface $io, ProcessExecutor
* Dispatch a package event.
*
* @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
*/
- 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.
*
- * @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
5 src/Composer/Script/PackageEvent.php
@@ -34,11 +34,12 @@ class PackageEvent extends Event
* @param string $name The event name
* @param Composer $composer The composer objet
* @param IOInterface $io The IOInterface object
+ * @param boolean $devMode Whether or not we are in dev mode
* @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;
}
View
6 tests/Composer/Test/Script/EventDispatcherTest.php
@@ -32,7 +32,7 @@ public function testListenerExceptionsAreCaught()
->method('write')
->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 @@ public function testDispatcherCanExecuteSingleCommandLineScript($command)
->method('execute')
->with($command);
- $dispatcher->dispatchCommandEvent("post-install-cmd");
+ $dispatcher->dispatchCommandEvent("post-install-cmd", false);
}
public function testDispatcherCanExecuteCliAndPhpInSameEventScriptStack()
@@ -95,7 +95,7 @@ public function testDispatcherCanExecuteCliAndPhpInSameEventScriptStack()
->with('Composer\Test\Script\EventDispatcherTest', 'someMethod')
->will($this->returnValue(true));
- $dispatcher->dispatchCommandEvent("post-install-cmd");
+ $dispatcher->dispatchCommandEvent("post-install-cmd", false);
}
private function getDispatcherStubForListenersTest($listeners, $io)
Please sign in to comment.
Something went wrong with that request. Please try again.