Exemplo n.º 1
0
 public function onBootstrap(MvcEvent $e)
 {
     $serviceManager = $e->getApplication()->getServiceManager();
     $application = $e->getApplication();
     $eventManager = $application->getEventManager();
     $eventManager->attach(MvcEvent::EVENT_DISPATCH, function ($event) use($serviceManager) {
         $serviceManager = ServiceLocatorFactory::getInstance()->getServiceLocator();
         $action = $event->getRouteMatch()->getParam('action');
         $action = $action . "Action";
         if (!method_exists($event->getTarget(), $action)) {
             $url = $event->getRequest()->getUri()->getPath();
             $errorInfo = new EventLogger($serviceManager);
             $errorInfo->set_event_type(EventType::ROUTER_NOT_MATCH);
             $trace = debug_backtrace();
             array_shift($trace);
             $errorMessage = 'The requested controller ' . $event->getRouteMatch()->getParam('controller') . ' was unable to dispatch the request';
             $errorInfo->handle(Application::ERROR_CONTROLLER_CANNOT_DISPATCH, $errorMessage, null, null, $trace, null, $url);
         }
     });
     $eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($event) use($serviceManager) {
         $exception = $event->getResult()->exception;
         if ($exception instanceof \Exception) {
             $errorInfo = new EventLogger($serviceManager);
             $errorInfo->set_event_type(EventType::EXCEPTION_DISPATCH);
             $errorInfo->handle($exception);
             die;
         }
         $error = $event->getError();
         $url = $event->getRequest()->getUri()->getPath();
         $errorMessage = "";
         if ($error == Application::ERROR_CONTROLLER_NOT_FOUND) {
             $errorMessage = 'The requested controller ' . $event->getRouteMatch()->getParam('controller') . ' could not be mapped to an existing controller class';
         }
         if ($error == Application::ERROR_CONTROLLER_INVALID) {
             $errorMessage = 'The requested controller ' . $event->getRouteMatch()->getParam('controller') . ' is not dispatchable';
         }
         if ($error == Application::ERROR_ROUTER_NO_MATCH) {
             $errorMessage = 'The requested URL could not be matched by routing';
         }
         if ($error == Application::ERROR_CONTROLLER_NOT_FOUND || $error == Application::ERROR_CONTROLLER_INVALID || $error == Application::ERROR_ROUTER_NO_MATCH) {
             $trace = debug_backtrace();
             array_shift($trace);
             $errorInfo = new EventLogger($serviceManager);
             $errorInfo->set_event_type(EventType::ROUTER_NOT_MATCH);
             $errorInfo->handle($error, $errorMessage, null, null, $trace, null, $url);
         }
     });
     $eventManager->attach(MvcEvent::EVENT_RENDER_ERROR, function ($event) use($serviceManager) {
         $exception = $event->getResult()->exception;
         if ($exception instanceof \Exception) {
             $errorInfo = new EventLogger($serviceManager);
             $errorInfo->set_event_type(EventType::EXCEPTION_RENDER);
             $errorInfo->handle($exception);
             die;
         }
     });
     $factory = ServiceLocatorFactory::getInstance();
     $factory->setServiceLocator($serviceManager);
 }
 public function save(EventLogger $eventLogger)
 {
     try {
         $this->result("Can't save event into the database");
         $data = $eventLogger->getArrayCopy();
         unset($data["event_logger_id"]);
         $event_logger_id = $eventLogger->get_event_logger_id();
         if ($event_logger_id == null || $event_logger_id < 0) {
             $affected = $this->insert($data);
             if ($affected > 0) {
                 $eventLogger->set_event_logger_id($this->getLastInsertValue());
                 $this->result("Event was created successfully.", false);
             }
         } else {
             $affected = $this->update($data, array('event_logger_id' => $event_logger_id));
             $this->result("Event was updated successfully.", false);
         }
     } catch (\Exception $e) {
         throw new H\ResultException($e);
     }
 }
Exemplo n.º 3
0
function process_error_backtrace($errno, $errstr, $errfile, $errline, $errcontext)
{
    $sm = ServiceLocatorFactory::getInstance()->getServiceLocator();
    $customEvent = new EventLogger($sm);
    switch ($errno) {
        case E_ERROR:
            $errorDangerLevel = EventType::ERROR_PHP;
            break;
        case E_WARNING:
            $errorDangerLevel = EventType::WARNING_PHP;
            break;
        case E_PARSE:
            $errorDangerLevel = EventType::ERROR_PHP;
            break;
        case E_NOTICE:
            $errorDangerLevel = EventType::NOTICE_PHP;
            break;
        case E_CORE_ERROR:
            $errorDangerLevel = EventType::ERROR_PHP;
            break;
        case E_CORE_WARNING:
            $errorDangerLevel = EventType::WARNING_PHP;
            break;
        case E_COMPILE_ERROR:
            $errorDangerLevel = EventType::ERROR_PHP;
            break;
        case E_COMPILE_WARNING:
            $errorDangerLevel = EventType::WARNING_PHP;
            break;
        case E_USER_ERROR:
            $errorDangerLevel = EventType::ERROR_PHP;
            break;
        case E_USER_WARNING:
            $errorDangerLevel = EventType::WARNING_PHP;
            break;
        case E_USER_NOTICE:
            $errorDangerLevel = EventType::NOTICE_PHP;
            break;
        case E_STRICT:
            $errorDangerLevel = EventType::WARNING_PHP;
            break;
        case E_RECOVERABLE_ERROR:
            $errorDangerLevel = EventType::ERROR_PHP;
            break;
        case E_DEPRECATED:
            $errorDangerLevel = EventType::NOTICE_PHP;
            break;
        case E_USER_DEPRECATED:
            $errorDangerLevel = EventType::NOTICE_PHP;
            break;
        default:
            $errorDangerLevel = EventType::ERROR_PHP;
            break;
    }
    $customEvent->set_event_type($errorDangerLevel);
    $trace = debug_backtrace();
    array_shift($trace);
    $customEvent->handle($errno, $errstr, $errfile, $errline, $trace, $errcontext);
    if ($errorDangerLevel == EventType::ERROR_PHP) {
        die;
    }
}