1 | <?php |
||
28 | class ExceptionStrategy implements ListenerAggregateInterface |
||
29 | { |
||
30 | /** |
||
31 | * Display exceptions? |
||
32 | * @var bool |
||
33 | */ |
||
34 | protected $displayExceptions = false; |
||
35 | |||
36 | /** |
||
37 | * Default Exception Message |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $defaultExceptionMessage = "Oh no. Something went wrong, but we have been notified.\n"; |
||
41 | |||
42 | /** |
||
43 | * A template for message to show in console when an exception has occurred. |
||
44 | * @var string|callable |
||
45 | */ |
||
46 | protected $message = <<<EOT |
||
47 | ====================================================================== |
||
48 | The application has thrown an exception! |
||
49 | ====================================================================== |
||
50 | :className |
||
51 | :message |
||
52 | ---------------------------------------------------------------------- |
||
53 | :file::line |
||
54 | :stack |
||
55 | ====================================================================== |
||
56 | Previous Exception(s): |
||
57 | ====================================================================== |
||
58 | :previous |
||
59 | |||
60 | EOT; |
||
61 | |||
62 | /** |
||
63 | * @var \Zend\Stdlib\CallbackHandler[] |
||
64 | */ |
||
65 | protected $listeners = array(); |
||
66 | |||
67 | /** |
||
68 | * Attach the aggregate to the specified event manager |
||
69 | * |
||
70 | * @param EventManagerInterface $events |
||
71 | * @return void |
||
72 | */ |
||
73 | public function attach(EventManagerInterface $events) |
||
78 | |||
79 | /** |
||
80 | * Detach aggregate listeners from the specified event manager |
||
81 | * |
||
82 | * @param EventManagerInterface $events |
||
83 | * @return void |
||
84 | */ |
||
85 | public function detach(EventManagerInterface $events) |
||
93 | |||
94 | /** |
||
95 | * Flag: display exceptions in error pages? |
||
96 | * |
||
97 | * @param bool $displayExceptions |
||
98 | * @return ExceptionStrategy |
||
99 | */ |
||
100 | public function setDisplayExceptions($displayExceptions) |
||
105 | |||
106 | /** |
||
107 | * Should we display exceptions in error pages? |
||
108 | * |
||
109 | * @return bool |
||
110 | */ |
||
111 | public function displayExceptions() |
||
115 | |||
116 | /** |
||
117 | * Get current template for message that will be shown in Console. |
||
118 | * |
||
119 | * @return string |
||
1 ignored issue
–
show
|
|||
120 | */ |
||
121 | public function getMessage() |
||
125 | |||
126 | /** |
||
127 | * Set the default exception message |
||
128 | * @param string $defaultExceptionMessage |
||
129 | */ |
||
130 | public function setDefaultExceptionMessage($defaultExceptionMessage) |
||
135 | |||
136 | /** |
||
137 | * Set template for message that will be shown in Console. |
||
138 | * The message can be a string (template) or a callable (i.e. a closure). |
||
139 | * |
||
140 | * The closure is expected to return a string and will be called with 2 parameters: |
||
141 | * Exception $exception - the exception being thrown |
||
142 | * boolean $displayExceptions - whether to display exceptions or not |
||
143 | * |
||
144 | * If the message is a string, one can use the following template params: |
||
145 | * |
||
146 | * :className - full class name of exception instance |
||
147 | * :message - exception message |
||
148 | * :code - exception code |
||
149 | * :file - the file where the exception has been thrown |
||
150 | * :line - the line where the exception has been thrown |
||
151 | * :stack - full exception stack |
||
152 | * |
||
153 | * @param string|callable $message |
||
154 | * @return ExceptionStrategy |
||
155 | */ |
||
156 | public function setMessage($message) |
||
161 | |||
162 | /** |
||
163 | * Create an exception view model, and set the console status code |
||
164 | * |
||
165 | * @param MvcEvent $e |
||
166 | * @return void |
||
167 | */ |
||
168 | public function prepareExceptionViewModel(MvcEvent $e) |
||
238 | } |
||
1 ignored issue
–
show
|
|||
239 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.