Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 92 lines (78 sloc) 2.604 kb
6e803a27 »
2006-08-23 imported pake project
1 <?php
2
3 /*
4 * This file is part of the pake package.
c054048b »
2006-08-23 pake: update email address + added pakeColor class + better handling …
5 * (c) 2004, 2005 Fabien Potencier <fabien.potencier@symfony-project.com>
6e803a27 »
2006-08-23 imported pake project
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 /**
12 * pakeException is the base class for all pake related exceptions and
13 * provides an additional method for printing up a detailed view of an
14 * exception.
15 *
16 * @package pake
c054048b »
2006-08-23 pake: update email address + added pakeColor class + better handling …
17 * @author Fabien Potencier <fabien.potencier@symfony-project.com>
6e803a27 »
2006-08-23 imported pake project
18 * @version SVN: $Id$
19 */
20 class pakeException extends Exception
21 {
adbf8e4f »
2006-11-23 pake: fixed pake exception output is not multibyte compatible (closes…
22 public static function strlen($string)
23 {
24 return function_exists('mb_strlen') ? mb_strlen($string) : strlen($string);
25 }
26
c054048b »
2006-08-23 pake: update email address + added pakeColor class + better handling …
27 function render($e)
6e803a27 »
2006-08-23 imported pake project
28 {
18a5c406 »
2006-08-24 pake: better display of exceptions in pake
29 $title = ' ['.get_class($e).'] ';
adbf8e4f »
2006-11-23 pake: fixed pake exception output is not multibyte compatible (closes…
30 $len = self::strlen($title);
9f9397b3 »
2006-08-30 pake: fixed color problem with exceptions
31 $lines = array();
32 foreach (explode("\n", $e->getMessage()) as $line)
33 {
34 $lines[] = ' '.$line.' ';
adbf8e4f »
2006-11-23 pake: fixed pake exception output is not multibyte compatible (closes…
35 $len = max(self::strlen($line) + 4, $len);
9f9397b3 »
2006-08-30 pake: fixed color problem with exceptions
36 }
18a5c406 »
2006-08-24 pake: better display of exceptions in pake
37 $messages = array(
38 str_repeat(' ', $len),
adbf8e4f »
2006-11-23 pake: fixed pake exception output is not multibyte compatible (closes…
39 $title.str_repeat(' ', $len - self::strlen($title)),
18a5c406 »
2006-08-24 pake: better display of exceptions in pake
40 );
41
9f9397b3 »
2006-08-30 pake: fixed color problem with exceptions
42 foreach ($lines as $line)
43 {
adbf8e4f »
2006-11-23 pake: fixed pake exception output is not multibyte compatible (closes…
44 $messages[] = $line.str_repeat(' ', $len - self::strlen($line));
9f9397b3 »
2006-08-30 pake: fixed color problem with exceptions
45 }
46
47 $messages[] = str_repeat(' ', $len);
48
91476b4d »
2006-10-12 pake: added proper support for STDERR and status code return
49 fwrite(STDERR, "\n");
18a5c406 »
2006-08-24 pake: better display of exceptions in pake
50 foreach ($messages as $message)
51 {
91476b4d »
2006-10-12 pake: added proper support for STDERR and status code return
52 fwrite(STDERR, pakeColor::colorize($message, 'ERROR', STDERR)."\n");
18a5c406 »
2006-08-24 pake: better display of exceptions in pake
53 }
91476b4d »
2006-10-12 pake: added proper support for STDERR and status code return
54 fwrite(STDERR, "\n");
c054048b »
2006-08-23 pake: update email address + added pakeColor class + better handling …
55
56 $pake = pakeApp::get_instance();
57
58 if ($pake->get_trace())
59 {
91476b4d »
2006-10-12 pake: added proper support for STDERR and status code return
60 fwrite(STDERR, "exception trace:\n");
c054048b »
2006-08-23 pake: update email address + added pakeColor class + better handling …
61
62 $trace = $this->trace($e);
63 for ($i = 0, $count = count($trace); $i < $count; $i++)
64 {
65 $class = (isset($trace[$i]['class']) ? $trace[$i]['class'] : '');
66 $type = (isset($trace[$i]['type']) ? $trace[$i]['type'] : '');
67 $function = $trace[$i]['function'];
68 $file = isset($trace[$i]['file']) ? $trace[$i]['file'] : 'n/a';
69 $line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a';
70
91476b4d »
2006-10-12 pake: added proper support for STDERR and status code return
71 fwrite(STDERR, sprintf(" %s%s%s at %s:%s\n", $class, $type, $function, pakeColor::colorize($file, 'INFO', STDERR), pakeColor::colorize($line, 'INFO', STDERR)));
c054048b »
2006-08-23 pake: update email address + added pakeColor class + better handling …
72 }
73 }
74
91476b4d »
2006-10-12 pake: added proper support for STDERR and status code return
75 fwrite(STDERR, "\n");
c054048b »
2006-08-23 pake: update email address + added pakeColor class + better handling …
76 }
77
78 function trace($exception)
79 {
80 // exception related properties
81 $trace = $exception->getTrace();
82 array_unshift($trace, array(
83 'function' => '',
84 'file' => ($exception->getFile() != null) ? $exception->getFile() : 'n/a',
85 'line' => ($exception->getLine() != null) ? $exception->getLine() : 'n/a',
86 'args' => array(),
87 ));
88
89 return $trace;
6e803a27 »
2006-08-23 imported pake project
90 }
91 }
Something went wrong with that request. Please try again.