1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Starlit App. |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2016 Starweb AB |
6
|
|
|
* @license BSD 3-Clause |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Starlit\App\Provider; |
10
|
|
|
|
11
|
|
|
use Starlit\App\BaseApp; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @author Andreas Nilsson <http://github.com/jandreasn> |
15
|
|
|
*/ |
16
|
|
|
class ErrorServiceProvider implements ServiceProviderInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @param BaseApp $app |
20
|
|
|
*/ |
21
|
22 |
|
public function register(BaseApp $app) |
22
|
|
|
{ |
23
|
22 |
|
$app->alias('errorLogger', \Monolog\Logger::class); |
24
|
22 |
|
$app->set(\Monolog\Logger::class, function (BaseApp $app) { |
25
|
22 |
|
$logger = new \Monolog\Logger('errorLogger'); |
26
|
|
|
|
27
|
22 |
|
$handler = new \Monolog\Handler\ErrorLogHandler(); |
28
|
22 |
|
if (!$app->isCli()) { |
29
|
|
|
$handler->pushProcessor(new \Monolog\Processor\WebProcessor()); |
30
|
|
|
$format = '%level_name%: %message% %extra.server%%extra.url%'; |
31
|
|
|
} else { |
32
|
22 |
|
$format = '%level_name%: %message%'; |
33
|
|
|
} |
34
|
22 |
|
$handler->setFormatter(new \Monolog\Formatter\LineFormatter($format, null, true)); |
35
|
22 |
|
$logger->pushHandler($handler); |
36
|
|
|
|
37
|
22 |
|
return $logger; |
38
|
22 |
|
}); |
39
|
|
|
|
40
|
22 |
|
$app->set('whoopsDebugErrorPageHandler', function (BaseApp $app) { |
41
|
22 |
|
$prettyPageHandler = new \Whoops\Handler\PrettyPageHandler(); |
42
|
22 |
|
if ($app->getConfig()->has('editor')) { |
43
|
|
|
$prettyPageHandler->setEditor($app->getConfig()->get('editor')); |
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
22 |
|
return $prettyPageHandler; |
47
|
22 |
|
}); |
48
|
|
|
|
49
|
22 |
|
$app->alias('whoopsUserErrorPageHandler', \Starlit\App\ErrorHandling\UserErrorPageHandler::class); |
50
|
22 |
|
$app->set(\Starlit\App\ErrorHandling\UserErrorPageHandler::class, function (BaseApp $app) { |
51
|
|
|
return new \Starlit\App\ErrorHandling\UserErrorPageHandler( |
52
|
|
|
$app->getConfig()->getRequired('errorPagePath') |
53
|
|
|
); |
54
|
22 |
|
}); |
55
|
|
|
|
56
|
22 |
|
$app->set('whoopsErrorHandler', function (BaseApp $app) { |
57
|
22 |
|
$plainTextHandler = new \Whoops\Handler\PlainTextHandler(); |
58
|
22 |
|
$plainTextHandler->setLogger($app->get(\Monolog\Logger::class)); |
59
|
22 |
|
if (!$app->isCli()) { |
60
|
|
|
$plainTextHandler->loggerOnly(true); |
61
|
|
|
} |
62
|
|
|
|
63
|
22 |
|
return $plainTextHandler; |
64
|
22 |
|
}); |
65
|
|
|
|
66
|
22 |
|
$app->set('whoops', function (BaseApp $app) { |
67
|
22 |
|
$whoops = new \Whoops\Run(); |
68
|
|
|
|
69
|
22 |
|
if (ini_get('display_errors')) { |
70
|
22 |
|
$whoops->pushHandler($app->get('whoopsDebugErrorPageHandler')); |
|
|
|
|
71
|
|
|
} elseif ($app->getConfig()->has('errorPagePath')) { |
72
|
|
|
$whoops->pushHandler($app->get('whoopsUserErrorPageHandler')); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
// Handles cli output and logging |
76
|
22 |
|
$whoops->pushHandler($app->get('whoopsErrorHandler')); |
|
|
|
|
77
|
|
|
|
78
|
22 |
|
return $whoops; |
79
|
22 |
|
}); |
80
|
|
|
$app->get('whoops')->register(); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: