Jarves\Tools::getArrayTrace PHP Метод

getArrayTrace() публичный статический Метод

public static getArrayTrace ( $exception )
    public static function getArrayTrace($exception)
    {
        $trace = [];
        foreach ($exception->getTrace() as $t) {
            $args = [];
            foreach ((array) @$t['args'] as $arg) {
                $args[] = gettype($arg);
            }
            $trace[] = ['function' => @$t['function'], 'class' => @$t['class'], 'file' => @$t['file'], 'line' => @$t['line'], 'type' => @$t['type'], 'args' => $args];
        }
        return $trace;
    }

Usage Example

Пример #1
0
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if ($this->container->get('jarves.page_stack')->isAdmin()) {
         $exception = $event->getException();
         $statusCode = $exception instanceof HttpExceptionInterface ? $exception->getStatusCode() : 500;
         $view = ['status' => $statusCode, 'error' => get_class($event->getException()), 'message' => $event->getException()->getMessage()];
         if ($exception instanceof RestException) {
             $view['data'] = $exception->getData();
         }
         $previous = $exception;
         while ($previous = $previous->getPrevious()) {
             $prev = array('error' => get_class($previous), 'message' => $previous->getMessage());
             if ($this->container->get('kernel')->isDebug()) {
                 $trace = Tools::getArrayTrace($previous);
                 $prev['file'] = $previous->getFile();
                 $prev['line'] = $previous->getLine();
                 $prev['trace'] = $trace;
             }
             $view['previous'][] = $prev;
         }
         if ($this->container->get('kernel')->isDebug()) {
             $trace = Tools::getArrayTrace($event->getException());
             $view['file'] = $event->getException()->getFile();
             $view['line'] = $event->getException()->getLine();
             $view['trace'] = $trace;
         }
         $response = new Response(json_encode($view, JSON_PRETTY_PRINT));
         $response->headers->set('Content-Type', 'application/json');
         $event->setResponse($response);
         //why does the kernel send a 500 statusCode ?
     }
 }