Exemplo n.º 1
0
 public function runAllCommand(GenericEvent $event)
 {
     /* @var \PhpGuard\Application\Plugin\PluginInterface $plugin */
     $this->container->setParameter('application.exit_code', 0);
     if (is_null($plugin = $event->getArgument('plugin'))) {
         $plugins = $this->container->getByPrefix('plugins');
     } else {
         $name = 'plugins.' . $plugin;
         if ($this->container->has($name)) {
             $plugin = $this->container->get('plugins.' . $plugin);
             $plugins = array($plugin);
         } else {
             throw new \RuntimeException(sprintf('Plugin "%s" is not registered', $plugin));
         }
     }
     foreach ($plugins as $plugin) {
         if (!$plugin->isActive()) {
             $this->getLogger()->addDebug(sprintf('Plugin "%s" is not active', $plugin->getTitle()));
             continue;
         } else {
             $this->getLogger()->addDebug('Start running all for plugin ' . $plugin->getTitle());
             $event->addProcessEvent($plugin->runAll());
             $this->getLogger()->addDebug('End running all for plugin ' . $plugin->getTitle());
         }
     }
 }
Exemplo n.º 2
0
 function it_plugin_should_not_runAll_if_not_active(ContainerInterface $container, PluginInterface $active, PluginInterface $inactive, GenericEvent $event)
 {
     $event->getSubject()->willReturn($container);
     $event->getArgument('plugin')->willReturn(null);
     $event->addProcessEvent(Argument::any())->shouldBeCalled();
     $container->getByPrefix('plugins')->willReturn(array($active, $inactive));
     $container->has('active')->willReturn(true);
     $active->isActive()->shouldBeCalled()->willReturn(true);
     $active->runAll()->willReturn(new ProcessEvent($active->getWrappedObject(), array()));
     $active->getTitle()->willReturn('active');
     $container->has('inactive')->willReturn(true);
     $inactive->getName()->willReturn('inactive');
     $inactive->getTitle()->willReturn('Inactive');
     $inactive->isActive()->shouldBeCalled()->willReturn(false);
     $inactive->runAll(Argument::any())->shouldNotBeCalled();
     $this->runAllCommand($event);
 }