-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathShutdownActiveModulesDataProviderBridge.php
More file actions
125 lines (108 loc) · 3.83 KB
/
Copy pathShutdownActiveModulesDataProviderBridge.php
File metadata and controls
125 lines (108 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\OxLogIQ;
use DateTimeImmutable;
use Exception;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ActiveModulesDataProviderBridge;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ActiveModulesDataProviderBridgeInterface;
use Psr\Log\LoggerInterface;
class ShutdownActiveModulesDataProviderBridge implements ActiveModulesDataProviderBridgeInterface
{
/**
* @param ActiveModulesDataProviderBridge $innerConfig
* @codeCoverageIgnore
*/
public function __construct(
protected ActiveModulesDataProviderBridgeInterface $innerConfig
) {
register_shutdown_function([$this, 'handleShutdown']);
}
public function handleShutdown(): void
{
$handledErrorTypes = $this->getHandledErrors();
$error = error_get_last();
if ($error !== null && in_array($error['type'], $handledErrorTypes)) {
$errorType = array_flip(
array_slice(
get_defined_constants(true)['Core'],
0,
16,
true
)
)[$error['type']];
$errorMessage = $error['message'];
$unifiedNamespaceClassNotFound = preg_match(
'/^Class \'OxidEsales\\\\Eshop\\\\.*\' not found/',
$errorMessage
);
// @codeCoverageIgnoreStart
if (1 === $unifiedNamespaceClassNotFound) {
$errorMessage .= '. Is an autogenerated class file missing? ' .
'Please run "composer oe:unified-namespace:generate" and double-check for errors. ' .
'Also double-check, if the class file for this very class was created.';
}
// @codeCoverageIgnoreEnd
/** report the error */
$logMessage = sprintf(
'[uncaught error] [type %1$s] [file %2$s] [line %3$s] [code ] [message %4$s]',
$errorType,
$error['file'],
$error['line'],
$errorMessage
);
/** write to log */
$time = microtime(true);
$micro = sprintf("%06d", ($time - floor($time)) * 1000000);
// @codeCoverageIgnoreStart
try {
$date = new DateTimeImmutable(date('Y-m-d H:i:s.' . $micro, (int) $time));
} catch (Exception) {
$date = new DateTimeImmutable();
}
// @codeCoverageIgnoreEnd
$timestamp = $date->format('d M H:i:s.u Y');
$message = "[$timestamp] " . $logMessage . PHP_EOL;
$this->getLogger()->critical($message);
}
}
/**
* @codeCoverageIgnore
*/
public function getLogger(): LoggerInterface
{
return Registry::getLogger();
}
public function getHandledErrors(): array
{
return [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_RECOVERABLE_ERROR, E_USER_ERROR];
}
public function getModuleIds(): array
{
return $this->innerConfig->getModuleIds();
}
public function getModulePaths(): array
{
return $this->innerConfig->getModulePaths();
}
public function getControllers(): array
{
return $this->innerConfig->getControllers();
}
public function getClassExtensions(): array
{
return $this->innerConfig->getClassExtensions();
}
}