Пример #1
0
 public function testConstructor()
 {
     $name = 'Foo';
     $exception = new Exception('Bar');
     $system = $this->getMockBuilder(System::CLASS)->disableOriginalConstructor()->getMock();
     $event = new ErrorEvent($name, $exception, $system);
     $this->assertSame($name, $event->getName());
     $this->assertSame($exception, $event->getException());
     $this->assertSame($system, $event->getContext());
 }
Пример #2
0
 /**
  * Handles a fatal system errors.
  *
  * @param \Es\System\ErrorEvent $event The error event
  */
 public function __invoke(ErrorEvent $event)
 {
     $server = $this->getServer();
     $request = $server->getRequest();
     $strategy = null;
     foreach ($this->strategies as $item) {
         if ($item->isAcceptable($request)) {
             $strategy = $item;
             break;
         }
     }
     if (null === $strategy) {
         $strategy = $this->getDefaultErrorStrategy();
     }
     $system = $event->getContext();
     $systemEvent = $system->getEvent();
     $exception = $event->getException();
     if ($system->isDevMode()) {
         $strategy->handleDevelopmentError($systemEvent, $exception);
     } elseif ($exception instanceof NotFoundExceptionInterface) {
         $strategy->handleNotFoundError($systemEvent);
     } else {
         $strategy->handleProductionError($systemEvent, $exception);
     }
 }