コード例 #1
0
 public function setUp()
 {
     $this->varnishOptions = new VarnishOptions();
     $this->varnishOptions->setCacheEnabled(true);
     $this->listener = new InjectCacheHeaderListener($this->varnishOptions);
     $this->listener->setLayoutUpdater(new LayoutUpdater());
     $this->eventManager = new EventManager(new SharedEventManager());
     $this->eventManager->getSharedManager()->clearListeners(InjectCacheHeaderListener::class);
     $this->attachStrategy(DefaultStrategy::class, 100);
     $this->listener->setEventManager($this->eventManager);
     $this->createMvcEvent();
 }
コード例 #2
0
 /**
  * 1. Registers Sentry as exception handler
  * 2. Replaces the default ExceptionStrategy so Exception that are caught by Zend Framework can still be logged
  *
  * @param MvcEvent $event
  */
 protected function setupExceptionLogging(MvcEvent $event)
 {
     // Register Sentry as exception handler for exception that bubble up to the top
     $this->zendSentry->registerExceptionHandler($this->config['zend-sentry']['call-existing-exception-handler']);
     // Replace the default ExceptionStrategy with ZendSentry's strategy
     if ($event->getApplication()->getServiceManager()->has('HttpExceptionStrategy')) {
         /** @var $exceptionStrategy ExceptionStrategy */
         $exceptionStrategy = $event->getApplication()->getServiceManager()->get('HttpExceptionStrategy');
         $exceptionStrategy->detach($this->eventManager);
     }
     // Check if script is running in console
     $exceptionStrategy = PHP_SAPI == 'cli' ? new SentryConsoleStrategy() : new SentryHttpStrategy();
     $exceptionStrategy->attach($this->eventManager);
     $exceptionStrategy->setDisplayExceptions($this->config['zend-sentry']['display-exceptions']);
     $exceptionStrategy->setDefaultExceptionMessage($this->config['zend-sentry'][PHP_SAPI == 'cli' ? 'default-exception-console-message' : 'default-exception-message']);
     $ravenClient = $this->ravenClient;
     // Attach an exception listener for the ZendSentry exception strategy, can be triggered from anywhere else too
     $this->eventManager->getSharedManager()->attach('*', 'logException', function ($event) use($ravenClient) {
         /** @var $event MvcEvent */
         $exception = $event->getParam('exception');
         $tags = $event->getParam('tags', array());
         $eventID = $ravenClient->captureException($exception, array('tags' => $tags));
         return $eventID;
     });
 }
コード例 #3
0
 public function testAttach()
 {
     $eventManager = new EventManager();
     $eventManager->getSharedManager()->clearListeners('ConLayout\\Updater\\LayoutUpdater');
     $this->listener->attach($eventManager);
     $listeners = $eventManager->getSharedManager()->getListeners('ConLayout\\Updater\\LayoutUpdater', 'getLayoutStructure.pre');
     $this->assertCount(1, $listeners);
 }
コード例 #4
0
ファイル: EventController.php プロジェクト: trongle/zend-2
 public function index12Action()
 {
     $eventHost = new EventManager();
     $shareEventManager = $eventHost->getSharedManager();
     $shareEventManager->attach("emOne", "eventOne", function ($e) {
         echo "<h3 style='color:red;font-weight:bold'>eventManagerOne - eventOne - Do 1</h3>";
     });
     $shareEventManager->attach(array("emTwo", "emThree"), "eventNew", function ($e) {
         echo "<h3 style='color:red;font-weight:bold'>eventManagerOne - eventNew - Do 1</h3>";
     });
     $eventManager = new EventManager(array("emOne", "emThree"));
     //$eventManager->setSharedManager($shareEventManager);<---không cần thiết xem lại action 10
     $eventManager->trigger("eventOne");
     $eventManager->trigger("eventNew");
     $eventManager = new EventManager("emTwo");
     //$eventManager->setSharedManager($shareEventManager);<---không cần thiết xem lại action 10
     $eventManager->trigger("eventNew");
     return false;
 }