Skip to content

Commit 72d2152

Browse files
committed
Updated to version 1.1.3
1 parent 1c16fb5 commit 72d2152

File tree

4 files changed

+77
-14
lines changed

4 files changed

+77
-14
lines changed

README-ES.md

+3
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ use Josantonius\ErrorHandler\Tests\ErrorHandlerTest;
114114
Métodos de prueba disponibles en esta librería:
115115

116116
```php
117+
ErrorHandlerTest->testSetCustomMethod1();
118+
ErrorHandlerTest->testSetCustomMethod2();
119+
ErrorHandlerTest->testSetCustomMethod3();
117120
ErrorHandlerTest->testSProvokeException();
118121
ErrorHandlerTest->testSProvokeWarning();
119122
ErrorHandlerTest->testSProvokeNotice();

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ use Josantonius\ErrorHandler\Tests\ErrorHandlerTest;
116116
Available test methods in this library:
117117

118118
```php
119-
ErrorHandlerTest->testSetCustomMethod();
119+
ErrorHandlerTest->testSetCustomMethod1();
120+
ErrorHandlerTest->testSetCustomMethod2();
121+
ErrorHandlerTest->testSetCustomMethod3();
120122
ErrorHandlerTest->testSProvokeException();
121123
ErrorHandlerTest->testSProvokeWarning();
122124
ErrorHandlerTest->testSProvokeNotice();

src/ErrorHandler.php

+24-11
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function exception($e) {
181181
* @param string $trace → exception/error trace
182182
* @param string $http → HTTP response status code
183183
*/
184-
protected function setParams($type,$code,$msg,$file,$line,$trace,$http) {
184+
protected function setParams($type, $code, $msg, $file, $line, $trace, $http) {
185185

186186
self::$stack = [
187187
'type' => $type,
@@ -238,17 +238,14 @@ protected function getPreviewCode() {
238238
*
239239
* @since 1.1.3
240240
*
241-
* @param string|object $class
242-
* @param string $method
243-
* @param int $repeat
244-
*
245-
* @return true
241+
* @param string|object $class → class name or class object
242+
* @param string $method → method name
243+
* @param int $repeat → number of times to repeat method
244+
* @param boolean $default → show default view
246245
*/
247-
public static function setCustomMethod($class, $method, $repeat = 0) {
246+
public static function setCustomMethod($class, $method, $repeat = 0, $default = false) {
248247

249248
self::$customMethods[] = [$class, $method, $repeat];
250-
251-
return true;
252249
}
253250

254251
/**
@@ -258,6 +255,8 @@ public static function setCustomMethod($class, $method, $repeat = 0) {
258255
*/
259256
protected function getCustomMethods() {
260257

258+
$showDefaultView = true;
259+
261260
$params = [self::$stack];
262261

263262
unset($params[0]['trace'], $params[0]['preview']);
@@ -274,7 +273,14 @@ protected function getCustomMethods() {
274273

275274
$method = isset($custom[1]) ? $custom[1] : false;
276275

277-
$repeat = isset($custom[2]) ? $custom[2] : 0;
276+
$repeat = $custom[2];
277+
278+
$showDefault = $custom[3];
279+
280+
if ($showDefault === false) {
281+
282+
$showDefaultView = false;
283+
}
278284

279285
if ($repeat === 0) {
280286

@@ -287,20 +293,27 @@ protected function getCustomMethods() {
287293

288294
call_user_func_array([$class, $method], $params);
289295
}
296+
297+
return $showDefaultView;
290298
}
291299

292300
/**
293301
* Renderization.
294302
*
295303
* @since 1.0.0
304+
*
305+
* @return
296306
*/
297307
protected function render() {
298308

299309
self::$stack['mode'] = defined('HHVM_VERSION') ? 'HHVM' : 'PHP';
300310

301311
if (self::$customMethods) {
302312

303-
return $this->getCustomMethods();
313+
if ($this->getCustomMethods() === false) {
314+
315+
return;
316+
}
304317
}
305318

306319
$this->getPreviewCode();

tests/ErrorHandlerTest.php

+47-2
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,63 @@ class ErrorHandlerTest {
2626
*
2727
* @since 1.1.3
2828
*/
29-
public function testSetCustomMethod() {
29+
public function testSetCustomMethod1() {
30+
31+
$class = $this;
32+
33+
$method = '_customMethodResponse';
34+
35+
ErrorHandler::SetCustomMethod($class, $method);
36+
37+
throw new \Exception("View from custom method");
38+
}
39+
40+
/**
41+
* Set custom method.
42+
*
43+
* @since 1.1.3
44+
*/
45+
public function testSetCustomMethod2() {
3046

3147
$class = $this;
3248

3349
$method = '_customMethodResponse';
3450

3551
/**
52+
* Optional. 0 by default.
53+
*
3654
* Number of times to repeat this method in case of multiple errors.
3755
*/
3856
$times = 0;
3957

40-
ErrorHandler::SetCustomMethod($class, $method, $times);
58+
/**
59+
* Optional. false by default.
60+
*
61+
* Display also the default view.
62+
*/
63+
$default = false;
64+
65+
ErrorHandler::SetCustomMethod($class, $method, $times, $default);
66+
67+
throw new \Exception("View from custom method");
68+
}
69+
70+
/**
71+
* Set custom method and display also the default view.
72+
*
73+
* @since 1.1.3
74+
*/
75+
public function testSetCustomMethod3() {
76+
77+
$class = $this;
78+
79+
$method = '_customMethodResponse';
80+
81+
$times = 3;
82+
83+
$default = true;
84+
85+
ErrorHandler::SetCustomMethod($class, $method, $times, $default);
4186

4287
throw new \Exception("View from custom method");
4388
}

0 commit comments

Comments
 (0)