From e531fa585a2293939b206f72ef049a53bc551525 Mon Sep 17 00:00:00 2001 From: Yanick Witschi Date: Fri, 6 Apr 2018 11:08:04 +0200 Subject: [PATCH] Allow to specify an array of event subscribers --- src/MageApplication.php | 11 +++++++++++ src/Runtime/Runtime.php | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/MageApplication.php b/src/MageApplication.php index b7b1408..d0116ce 100644 --- a/src/MageApplication.php +++ b/src/MageApplication.php @@ -12,6 +12,7 @@ namespace Mage; use Mage\Command\AbstractCommand; use Mage\Runtime\Runtime; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\SplFileInfo; use Monolog\Logger; @@ -55,6 +56,7 @@ class MageApplication extends Application }); $this->runtime = $this->instantiateRuntime(); + $this->runtime->setEventDispatcher($dispatcher); $this->loadBuiltInCommands(); } @@ -89,6 +91,15 @@ class MageApplication extends Application throw new RuntimeException(sprintf('The configured log_dir "%s" does not exists or is not a directory.', $config['magephp']['log_dir'])); } + // Subscribers + if (array_key_exists('subscribers', $config['magephp'])) { + foreach ((array) $config['magephp']['subscribers'] as $subscriber) { + if ($subscriber instanceof EventSubscriberInterface) { + $this->runtime->getEventDispatcher()->addSubscriber($subscriber); + } + } + } + $this->runtime->setConfiguration($config['magephp']); $this->runtime->setLogger($logger); return; diff --git a/src/Runtime/Runtime.php b/src/Runtime/Runtime.php index 5b7368d..63c03f6 100644 --- a/src/Runtime/Runtime.php +++ b/src/Runtime/Runtime.php @@ -15,6 +15,7 @@ use Mage\Deploy\Strategy\RsyncStrategy; use Mage\Deploy\Strategy\StrategyInterface; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Process\Process; use Mage\Runtime\Exception\RuntimeException; @@ -46,6 +47,11 @@ class Runtime */ protected $stage; + /** + * @var EventDispatcherInterface + */ + protected $eventDispatcher; + /** * @var string|null The host being deployed to */ @@ -316,6 +322,21 @@ class Runtime return $this->stage; } + /** + * @return EventDispatcherInterface + */ + public function getEventDispatcher() + { + return $this->eventDispatcher; + } + + /** + * @param EventDispatcherInterface $eventDispatcher + */ + public function setEventDispatcher(EventDispatcherInterface $eventDispatcher) + { + $this->eventDispatcher = $eventDispatcher; + } /** * Retrieve the defined Tasks for the current Environment and Stage *