Allow to specify an array of event subscribers

This commit is contained in:
Yanick Witschi 2018-04-06 11:08:04 +02:00
parent e30de6b719
commit e531fa585a
2 changed files with 32 additions and 0 deletions

View file

@ -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;

View file

@ -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
*