Browse Source

Issue 5769 dev mode varaible

Andrew Taylor 8 năm trước cách đây
mục cha
commit
ce6a3c0dd7
2 tập tin đã thay đổi với 5 bổ sung0 xóa
  1. 2 0
      doc/articles/scripts.md
  2. 3 0
      src/Composer/Installer.php

+ 2 - 0
doc/articles/scripts.md

@@ -150,6 +150,8 @@ class MyClass
 }
 ```
 
+**Note:** During composer install / update, a `COMPOSER_DEV_MODE` php environment variable is set. If composer install / update was run with the `--no-dev option`, this variable will be set to 0, otherwise it will be set to 1. This exposes the mode in which the install / update was run, to any post-install / update commands.
+
 ## Event classes
 
 When an event is fired, your PHP callback receives as first argument a

+ 3 - 0
src/Composer/Installer.php

@@ -292,6 +292,9 @@ class Installer
             }
 
             if ($this->runScripts) {
+                $devMode = (int) $this->devMode;
+                putenv("COMPOSER_DEV_MODE=$devMode");
+
                 // dispatch post event
                 $eventName = $this->update ? ScriptEvents::POST_UPDATE_CMD : ScriptEvents::POST_INSTALL_CMD;
                 $this->eventDispatcher->dispatchScript($eventName, $this->devMode);