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
|
20 |
|
public function register(BaseApp $app) |
22
|
|
|
{ |
23
|
|
|
$app->set('errorLogger', function (BaseApp $app) { |
24
|
20 |
|
$logger = new \Monolog\Logger('errorLogger'); |
25
|
|
|
|
26
|
20 |
|
$handler = new \Monolog\Handler\ErrorLogHandler(); |
27
|
20 |
|
if (!$app->isCli()) { |
28
|
|
|
$handler->pushProcessor(new \Monolog\Processor\WebProcessor()); |
29
|
|
|
$format = '%level_name%: %message% %extra.server%%extra.url%'; |
30
|
|
|
} else { |
31
|
20 |
|
$format = '%level_name%: %message%'; |
32
|
|
|
} |
33
|
20 |
|
$handler->setFormatter(new \Monolog\Formatter\LineFormatter($format, null, true)); |
34
|
20 |
|
$logger->pushHandler($handler); |
35
|
|
|
|
36
|
20 |
|
return $logger; |
37
|
20 |
|
}); |
38
|
|
|
|
39
|
|
|
$app->set('whoopsDebugErrorPageHandler', function (BaseApp $app) { |
40
|
20 |
|
$prettyPageHandler = new \Whoops\Handler\PrettyPageHandler(); |
41
|
20 |
|
if ($app->getConfig()->has('editor')) { |
42
|
|
|
$prettyPageHandler->setEditor($app->getConfig()->get('editor')); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
20 |
|
return $prettyPageHandler; |
46
|
20 |
|
}); |
47
|
|
|
|
48
|
|
|
$app->set('whoopsErrorHandler', function (BaseApp $app) { |
49
|
20 |
|
$plainTextHandler = new \Whoops\Handler\PlainTextHandler(); |
50
|
20 |
|
$plainTextHandler->setLogger($app->get('errorLogger')); |
51
|
20 |
|
if (!$app->isCli()) { |
52
|
|
|
$plainTextHandler->loggerOnly(true); |
53
|
|
|
} |
54
|
|
|
|
55
|
20 |
|
return $plainTextHandler; |
56
|
20 |
|
}); |
57
|
|
|
|
58
|
20 |
|
$app->set('whoops', function (BaseApp $app) { |
59
|
20 |
|
$whoops = new \Whoops\Run(); |
60
|
|
|
|
61
|
20 |
|
if (ini_get('display_errors')) { |
62
|
20 |
|
$whoops->pushHandler($app->get('whoopsDebugErrorPageHandler')); |
|
|
|
|
63
|
20 |
|
} |
64
|
|
|
|
65
|
|
|
// Handles cli output and logging |
66
|
20 |
|
$whoops->pushHandler($app->get('whoopsErrorHandler')); |
|
|
|
|
67
|
|
|
|
68
|
20 |
|
return $whoops; |
69
|
20 |
|
}); |
70
|
20 |
|
$app->get('whoops')->register(); |
71
|
20 |
|
} |
72
|
|
|
} |
73
|
|
|
|
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: