Bläddra i källkod

Merge remote-tracking branch 'MaxGfeller/run-script-enhancement'

Jordi Boggiano 11 år sedan
förälder
incheckning
33cedda708

+ 4 - 0
src/Composer/Command/RunScriptCommand.php

@@ -73,7 +73,11 @@ EOT
             if (defined('Composer\Script\ScriptEvents::'.str_replace('-', '_', strtoupper($script)))) {
                 throw new \InvalidArgumentException(sprintf('Script "%s" cannot be run with this command', $script));
             }
+        }
+
+        $hasListeners = $this->getComposer()->getEventDispatcher()->hasEventListeners(new \Composer\Script\CommandEvent($script, $this->getComposer(), $this->getIO()));
 
+        if(!$hasListeners) {
             throw new \InvalidArgumentException(sprintf('Script "%s" does not exist', $script));
         }
 

+ 13 - 0
src/Composer/EventDispatcher/EventDispatcher.php

@@ -216,6 +216,19 @@ class EventDispatcher
         return call_user_func_array('array_merge', $listeners[$event->getName()]);
     }
 
+    /**
+     * Checks if an event has listeners registered
+     *
+     * @param Event $event
+     * @return boolean
+     */
+    public function hasEventListeners(Event $event)
+    {
+        $listeners = $this->getListeners($event);
+
+        return (sizeof($listeners) > 0);
+    }
+
     /**
      * Finds all listeners defined as scripts in the package
      *