Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

FlattenException.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 7.64 KiB


001  <?php
002   
003  /*
004   * This file is part of the Symfony package.
005   *
006   * (c) Fabien Potencier <fabien@symfony.com>
007   *
008   * For the full copyright and license information, please view the LICENSE
009   * file that was distributed with this source code.
010   */
011   
012  namespace Symfony\Component\Debug\Exception;
013   
014  use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
015   
016  /**
017   * FlattenException wraps a PHP Exception to be able to serialize it.
018   *
019   * Basically, this class removes all objects from the trace.
020   *
021   * @author Fabien Potencier <fabien@symfony.com>
022   */
023  class FlattenException
024  {
025      private $message;
026      private $code;
027      private $previous;
028      private $trace;
029      private $class;
030      private $statusCode;
031      private $headers;
032      private $file;
033      private $line;
034   
035      public static function create(\Exception $exception, $statusCode = null, array $headers = array())
036      {
037          $e = new static();
038          $e->setMessage($exception->getMessage());
039          $e->setCode($exception->getCode());
040   
041          if ($exception instanceof HttpExceptionInterface) {
042              $statusCode = $exception->getStatusCode();
043              $headers = array_merge($headers, $exception->getHeaders());
044          }
045   
046          if (null === $statusCode) {
047              $statusCode = 500;
048          }
049   
050          $e->setStatusCode($statusCode);
051          $e->setHeaders($headers);
052          $e->setTraceFromException($exception);
053          $e->setClass(get_class($exception));
054          $e->setFile($exception->getFile());
055          $e->setLine($exception->getLine());
056          if ($exception->getPrevious()) {
057              $e->setPrevious(static::create($exception->getPrevious()));
058          }
059   
060          return $e;
061      }
062   
063      public function toArray()
064      {
065          $exceptions = array();
066          foreach (array_merge(array($this), $this->getAllPrevious()) as $exception) {
067              $exceptions[] = array(
068                  'message' => $exception->getMessage(),
069                  'class'   => $exception->getClass(),
070                  'trace'   => $exception->getTrace(),
071              );
072          }
073   
074          return $exceptions;
075      }
076   
077      public function getStatusCode()
078      {
079          return $this->statusCode;
080      }
081   
082      public function setStatusCode($code)
083      {
084          $this->statusCode = $code;
085      }
086   
087      public function getHeaders()
088      {
089          return $this->headers;
090      }
091   
092      public function setHeaders(array $headers)
093      {
094          $this->headers = $headers;
095      }
096   
097      public function getClass()
098      {
099          return $this->class;
100      }
101   
102      public function setClass($class)
103      {
104          $this->class = $class;
105      }
106   
107      public function getFile()
108      {
109          return $this->file;
110      }
111   
112      public function setFile($file)
113      {
114          $this->file = $file;
115      }
116   
117      public function getLine()
118      {
119          return $this->line;
120      }
121   
122      public function setLine($line)
123      {
124          $this->line = $line;
125      }
126   
127      public function getMessage()
128      {
129          return $this->message;
130      }
131   
132      public function setMessage($message)
133      {
134          $this->message = $message;
135      }
136   
137      public function getCode()
138      {
139          return $this->code;
140      }
141   
142      public function setCode($code)
143      {
144          $this->code = $code;
145      }
146   
147      public function getPrevious()
148      {
149          return $this->previous;
150      }
151   
152      public function setPrevious(FlattenException $previous)
153      {
154          $this->previous = $previous;
155      }
156   
157      public function getAllPrevious()
158      {
159          $exceptions = array();
160          $e = $this;
161          while ($e = $e->getPrevious()) {
162              $exceptions[] = $e;
163          }
164   
165          return $exceptions;
166      }
167   
168      public function getTrace()
169      {
170          return $this->trace;
171      }
172   
173      public function setTraceFromException(\Exception $exception)
174      {
175          $trace = $exception->getTrace();
176   
177          if ($exception instanceof FatalErrorException) {
178              if (function_exists('xdebug_get_function_stack')) {
179                  $trace = array_slice(array_reverse(xdebug_get_function_stack()), 4);
180   
181                  foreach ($trace as $i => $frame) {
182                      //  XDebug pre 2.1.1 doesn't currently set the call type key http://bugs.xdebug.org/view.php?id=695
183                      if (!isset($frame['type'])) {
184                          $trace[$i]['type'] = '??';
185                      }
186   
187                      if ('dynamic' === $trace[$i]['type']) {
188                          $trace[$i]['type'] = '->';
189                      } elseif ('static' === $trace[$i]['type']) {
190                          $trace[$i]['type'] = '::';
191                      }
192   
193                      // XDebug also has a different name for the parameters array
194                      if (isset($frame['params']) && !isset($frame['args'])) {
195                          $trace[$i]['args'] = $frame['params'];
196                          unset($trace[$i]['params']);
197                      }
198                  }
199              } else {
200                  $trace = array_slice(array_reverse($trace), 1);
201              }
202          }
203   
204          $this->setTrace($trace, $exception->getFile(), $exception->getLine());
205      }
206   
207      public function setTrace($trace, $file, $line)
208      {
209          $this->trace = array();
210          $this->trace[] = array(
211              'namespace'   => '',
212              'short_class' => '',
213              'class'       => '',
214              'type'        => '',
215              'function'    => '',
216              'file'        => $file,
217              'line'        => $line,
218              'args'        => array(),
219          );
220          foreach ($trace as $entry) {
221              $class = '';
222              $namespace = '';
223              if (isset($entry['class'])) {
224                  $parts = explode('\\', $entry['class']);
225                  $class = array_pop($parts);
226                  $namespace = implode('\\', $parts);
227              }
228   
229              $this->trace[] = array(
230                  'namespace'   => $namespace,
231                  'short_class' => $class,
232                  'class'       => isset($entry['class']) ? $entry['class'] : '',
233                  'type'        => isset($entry['type']) ? $entry['type'] : '',
234                  'function'    => isset($entry['function']) ? $entry['function'] : null,
235                  'file'        => isset($entry['file']) ? $entry['file'] : null,
236                  'line'        => isset($entry['line']) ? $entry['line'] : null,
237                  'args'        => isset($entry['args']) ? $this->flattenArgs($entry['args']) : array(),
238              );
239          }
240      }
241   
242      private function flattenArgs($args, $level = 0)
243      {
244          $result = array();
245          foreach ($args as $key => $value) {
246              if (is_object($value)) {
247                  $result[$key] = array('object', get_class($value));
248              } elseif (is_array($value)) {
249                  if ($level > 10) {
250                      $result[$key] = array('array', '*DEEP NESTED ARRAY*');
251                  } else {
252                      $result[$key] = array('array', $this->flattenArgs($value, $level + 1));
253                  }
254              } elseif (null === $value) {
255                  $result[$key] = array('null', null);
256              } elseif (is_bool($value)) {
257                  $result[$key] = array('boolean', $value);
258              } elseif (is_resource($value)) {
259                  $result[$key] = array('resource', get_resource_type($value));
260              } elseif ($value instanceof \__PHP_Incomplete_Class) {
261                  // Special case of object, is_object will return false
262                  $result[$key] = array('incomplete-object', $this->getClassNameFromIncomplete($value));
263              } else {
264                  $result[$key] = array('string', (string) $value);
265              }
266          }
267   
268          return $result;
269      }
270   
271      private function getClassNameFromIncomplete(\__PHP_Incomplete_Class $value)
272      {
273          $array = new \ArrayObject($value);
274   
275          return $array['__PHP_Incomplete_Class_Name'];
276      }
277  }
278