Exemple #1
0
 public function listenerCallback(ChangeSetEvent $event)
 {
     if ($this->callbackCount == 2) {
         touch($file = self::$tmpDir . '/foo.txt');
         file_put_contents($file, 'Hello World');
         $event->getListener()->stop();
         return;
     }
     $this->isCallbackCalled = true;
     $this->callbackCount++;
 }
Exemple #2
0
 function it_should_reload_when_configuration_changed(ContainerInterface $container, ChangeSetEvent $event, EventDispatcherInterface $dispatcher, ConsoleHandler $handler, Logger $logger)
 {
     $container->getParameter('config.file', Argument::any())->shouldBeCalled()->willReturn('phpguard.yml.dist');
     $container->get('logger.handler')->willReturn($handler);
     $container->get('logger')->willReturn($logger);
     $event->getFiles()->willReturn(array('phpguard.yml.dist'));
     $dispatcher->dispatch(ConfigEvents::RELOAD, Argument::any())->shouldBeCalled();
     $dispatcher->dispatch(ApplicationEvents::preEvaluate, Argument::any())->shouldBeCalled();
     $dispatcher->dispatch(ApplicationEvents::evaluate, Argument::any())->shouldBeCalled();
     $dispatcher->dispatch(ApplicationEvents::postEvaluate, Argument::any())->shouldBeCalled();
     $this->listen($event);
 }
Exemple #3
0
 /**
  * @return \PhpGuard\Listen\Listener
  */
 public function getListener()
 {
     return $this->changeSet->getListener();
 }
Exemple #4
0
 public function listen(ChangeSetEvent $event)
 {
     $files = $event->getFiles();
     if (empty($files)) {
         return;
     }
     $container = $this->container;
     $dispatcher = $container->get('dispatcher');
     $configFile = $container->getParameter('config.file');
     if (in_array($configFile, $files)) {
         $container->get('logger.handler')->reset();
         $container->get('logger')->addCommon("Reloading Configuration");
         $reloadEvent = new GenericEvent($container);
         $dispatcher->dispatch(ConfigEvents::RELOAD, $reloadEvent);
         $container->get('logger')->addCommon('Configuration Reloaded');
         $container->get('ui.shell')->showPrompt();
     }
     $evaluateEvent = new EvaluateEvent($event);
     $dispatcher->dispatch(ApplicationEvents::preEvaluate, $evaluateEvent);
     $dispatcher->dispatch(ApplicationEvents::evaluate, $evaluateEvent);
     $dispatcher->dispatch(ApplicationEvents::postEvaluate, $evaluateEvent);
 }