Ejemplo n.º 1
0
 public function testGetters()
 {
     $exception = new CM_Exception('Foo bar', ['foo' => new SplFixedArray(), 'bar' => [1, 2, 3]]);
     $serializableException = new CM_ExceptionHandling_SerializableException($exception);
     $this->assertSame('Foo bar', $serializableException->getMessage());
     $this->assertSame('CM_Exception', $serializableException->getClass());
     $this->assertSame(__FILE__, $serializableException->getFile());
     $this->assertInternalType('int', $serializableException->getLine());
     $this->assertSame(['foo' => 'SplFixedArray', 'bar' => '[]'], $serializableException->getMeta());
 }
Ejemplo n.º 2
0
 /**
  * @param CM_ExceptionHandling_SerializableException $exception
  * @return string
  */
 protected function _renderException(CM_ExceptionHandling_SerializableException $exception)
 {
     $traceData = [];
     $traceCount = 0;
     foreach ($exception->getTrace() as $trace) {
         $traceData[] = sprintf('     %02d. %s %s:%s', $traceCount++, $trace['code'], $trace['file'], $trace['line']);
     }
     $traceText = implode(PHP_EOL, $traceData);
     return PHP_EOL . $this->_formatArrayToLines('   - %s: %s', ['message' => $exception->getMessage(), 'type' => $exception->getClass(), 'stacktrace' => PHP_EOL . $traceText]);
 }
Ejemplo n.º 3
0
 public function formatContext(CM_Log_Context $context)
 {
     $result = [];
     if ($computerInfo = $context->getComputerInfo()) {
         $result['computerInfo'] = ['fqdn' => $computerInfo->getFullyQualifiedDomainName(), 'phpVersion' => $computerInfo->getPhpVersion()];
     }
     $request = $context->getHttpRequest();
     if (null !== $request) {
         $serverArray = $request->getServer();
         $formattedRequest = ['uri' => $request->getUri(), 'method' => $request->getMethodName()];
         $query = $request->findQuery();
         unset($query['viewInfoList']);
         $formattedRequest['query'] = CM_Util::jsonEncode($query, true);
         if (array_key_exists('http_referer', $serverArray)) {
             $formattedRequest['referer'] = (string) $serverArray['http_referer'];
         }
         if (array_key_exists('http_user_agent', $serverArray)) {
             $formattedRequest['useragent'] = (string) $serverArray['http_user_agent'];
         }
         if ($ip = $request->getIp()) {
             $formattedRequest['ip'] = (string) $ip;
         }
         if ($request->hasHeader('host')) {
             $formattedRequest['hostname'] = $request->getHost();
         }
         $result['httpRequest'] = $formattedRequest;
     }
     $result = array_merge($result, $this->formatAppContext($context));
     if ($exception = $context->getException()) {
         $serializableException = new CM_ExceptionHandling_SerializableException($exception);
         $stack = $serializableException->getTrace();
         if (!empty($stack)) {
             $stackAsString = trim(Functional\reduce_left(array_reverse($stack), function ($value, $index, $collection, $reduction) {
                 return $reduction . '#' . $index . ' ' . $value['file'] . '(' . $value['line'] . '): ' . $value['code'] . PHP_EOL;
             }, ''));
         } else {
             $stackAsString = $serializableException->getTraceAsString();
         }
         $result['exception'] = ['type' => $serializableException->getClass(), 'message' => $serializableException->getMessage(), 'stack' => $stackAsString, 'metaInfo' => $serializableException->getMeta()];
     }
     return $result;
 }
Ejemplo n.º 4
0
 /**
  * @param CM_Log_Record $record
  * @return array
  */
 protected function _formatRecord(CM_Log_Record $record)
 {
     $recordContext = $record->getContext();
     $computerInfo = $recordContext->getComputerInfo();
     $user = $recordContext->getUser();
     $extra = $recordContext->getExtra();
     $request = $recordContext->getHttpRequest();
     $createdAt = $record->getCreatedAt();
     $formattedContext = [];
     if (null !== $computerInfo) {
         $formattedContext['computerInfo'] = ['fqdn' => $computerInfo->getFullyQualifiedDomainName(), 'phpVersion' => $computerInfo->getPhpVersion()];
     }
     if (!isset($extra['type'])) {
         $extra['type'] = self::DEFAULT_TYPE;
     }
     $formattedContext['extra'] = $extra;
     if (null !== $user) {
         $formattedContext['user'] = ['id' => $user->getId(), 'name' => $user->getDisplayName()];
     }
     if (null !== $request) {
         $formattedContext['httpRequest'] = ['method' => $request->getMethodName(), 'uri' => $request->getUri(), 'query' => [], 'server' => $request->getServer(), 'headers' => $request->getHeaders()];
         $formattedContext['httpRequest']['query'] = $request->findQuery();
         if ($request instanceof CM_Http_Request_Post) {
             $formattedContext['httpRequest']['body'] = $request->getBody();
         }
         $formattedContext['httpRequest']['clientId'] = $request->getClientId();
     }
     if ($exception = $recordContext->getException()) {
         $serializableException = new CM_ExceptionHandling_SerializableException($exception);
         $formattedContext['exception'] = ['class' => $serializableException->getClass(), 'message' => $serializableException->getMessage(), 'line' => $serializableException->getLine(), 'file' => $serializableException->getFile(), 'trace' => $serializableException->getTrace(), 'traceString' => $serializableException->getTraceAsString(), 'meta' => $serializableException->getMeta()];
     }
     $formattedRecord = ['level' => (int) $record->getLevel(), 'message' => (string) $record->getMessage(), 'createdAt' => $createdAt, 'context' => $formattedContext];
     if (null !== $this->_recordTtl) {
         $expireAt = clone $createdAt;
         $expireAt->add(new DateInterval('PT' . $this->_recordTtl . 'S'));
         $formattedRecord['expireAt'] = $expireAt;
     }
     $formattedRecord = $this->_sanitizeRecord($formattedRecord);
     //TODO remove after investigation
     return $formattedRecord;
 }
Ejemplo n.º 5
0
 public function getHeader(CM_ExceptionHandling_SerializableException $exception)
 {
     return $exception->getClass() . ': ' . $exception->getMessage() . ' in ' . $exception->getFile() . ' on line ' . $exception->getLine() . PHP_EOL;
 }
Ejemplo n.º 6
0
 public function getHeader(CM_ExceptionHandling_SerializableException $exception)
 {
     return '<h1>' . $exception->getClass() . '</h1><h2>' . $exception->getMessage() . '</h2><pre>' . $exception->getFile() . ' on line ' . $exception->getLine() . '</pre>';
 }