Ejemplo n.º 1
0
 protected function compile($args)
 {
     $cmd = call_user_func_array('sprintf', $args);
     if ($this->debugger->enabled()) {
         $this->loggerEx->debug($cmd);
     }
     return $cmd;
 }
Ejemplo n.º 2
0
 public function run()
 {
     try {
         $this->boot();
         $event = new RequestEvent($this->request);
         $this->dispatcher->fire(RequestEvent::REQUEST_HANDLE, $event);
         $this->response = $event->getResponse();
     } catch (AuthError $e) {
         $this->response->setStatusCode(401);
     } catch (ResourceNotFoundException $e) {
         $this->response->setStatusCode(404);
     } catch (\Throwable $e) {
         http_response_code(500);
         $this->response->setStatusCode(500);
         if ($e instanceof PrintableError) {
             $this->response->setContent($e->getMessage());
         } else {
             if (preg_match("/Duplicate entry '(.*?)' for key '(.*?)'/", $e->getMessage(), $matches)) {
                 $errorStr = sprintf("DUPLICATE: %s ('%s' is already in use).", ucfirst($matches[2]), $matches[1]);
             } else {
                 if ($this->debug->enabled()) {
                     throw $e;
                 } else {
                     $event = new ExceptionEvent($e);
                     $this->dispatcher->fire(ExceptionEvent::EXCEPTION_UNHANDLED, $event);
                 }
                 if (preg_match("/Unknown column 'user_id'.*from (.*?) /", $e->getMessage(), $matches)) {
                     $errorStr = sprintf("Permission::SAME_USER requires a `user_id` column (which is missing in table {$matches['1']})");
                 } else {
                     $errorStr = 'Internal server error';
                 }
             }
             $this->response->setContent($errorStr);
         }
     }
     if ($this->response->getStatusCode() === 200) {
         $this->dispatcher->fire(ResponseEvent::RESPONSE_RENDER, new ResponseEvent($this->response));
     } else {
         $this->dispatcher->fire(ResponseEvent::RESPONSE_ERROR, new ResponseEvent($this->response));
     }
 }