Skip to content

Commit 41b585f

Browse files
authored
Add support for Symfony 7 (#50)
This bumps the min PHP version to 7.2 because Symfony 7 requires adding a return type and this requires support for variance rules to stay compatible with older Symfony versions, which are available only in PHP 7.2+.
1 parent 74ce456 commit 41b585f

File tree

3 files changed

+34
-45
lines changed

3 files changed

+34
-45
lines changed

Diff for: DependencyInjection/Configuration.php

+2-10
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,11 @@
1414
*/
1515
class Configuration implements ConfigurationInterface
1616
{
17-
/**
18-
* @return TreeBuilder
19-
*/
20-
public function getConfigTreeBuilder()
17+
public function getConfigTreeBuilder(): TreeBuilder
2118
{
2219
$treeBuilder = new TreeBuilder('nelmio_js_logger');
2320

24-
if (method_exists($treeBuilder, 'getRootNode')) {
25-
$rootNode = $treeBuilder->getRootNode();
26-
} else {
27-
// BC layer for symfony/config 4.1 and older
28-
$rootNode = $treeBuilder->root('nelmio_js_logger');
29-
}
21+
$rootNode = $treeBuilder->getRootNode();
3022

3123
$levels = array('DEBUG', 'INFO', 'NOTICE', 'WARNING', 'ERROR', 'CRITICAL', 'ALERT', 'EMERGENCY');
3224
$levelsCI = array_merge($levels, array_map('strtolower', $levels));

Diff for: TwigExtension.php

+25-28
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ public function __construct(UrlGeneratorInterface $router, $stackTracePath = nul
2121
$this->stackTracePath = $stackTracePath;
2222
}
2323

24-
/**
25-
* @return array
26-
*/
27-
public function getFunctions()
24+
public function getFunctions(): array
2825
{
2926
return array(
3027
new TwigFunction('nelmio_js_error_logger', array($this, 'initErrorLogger'), array('is_safe' => array('html', 'js'))),
@@ -39,14 +36,14 @@ public function initErrorLogger($level = 'error', $includeScriptTag = true)
3936
$addStackTraceJs = <<<JS
4037
var stackTraceJsModule = (function (basicModule) {
4138
var stackTraceJs = {};
42-
39+
4340
stackTraceJs.appended = false;
4441
stackTraceJs.queue = [];
4542
4643
stackTraceJs.isScriptPresent = function isScriptPresent() {
4744
return ((typeof StackTrace !== 'undefined') && (typeof StackTrace.fromError === 'function'));
4845
};
49-
46+
5047
stackTraceJs.sendLogData = function sendLogData(errorMsg, file, line, col, error) {
5148
StackTrace.fromError(error).then(
5249
function(stackframes) {
@@ -75,14 +72,14 @@ function(stackframes) {
7572
req.setRequestHeader('Content-Type', 'application/json');
7673
req.send(JSON.stringify(
7774
{
78-
stack: stackframes,
79-
msg: errorMsg,
80-
level: '$level',
75+
stack: stackframes,
76+
msg: errorMsg,
77+
level: '$level',
8178
context: {
82-
file: file,
83-
line: line,
84-
column: col,
85-
userAgent: navigator.userAgent,
79+
file: file,
80+
line: line,
81+
column: col,
82+
userAgent: navigator.userAgent,
8683
platform: navigator.platform,
8784
customContext: basicModule.fetchCustomContext()
8885
}
@@ -96,8 +93,8 @@ function(stackframes) {
9693
basicModule.callSimpleLogger(errorMsg, file, line, col, error);
9794
});
9895
};
99-
100-
96+
97+
10198
stackTraceJs.callStackTraceJs = function callStackTraceJs(errorMsg, file, line, col, error) {
10299
if (stackTraceJs.isScriptPresent()) {
103100
stackTraceJs.sendLogData(errorMsg, file, line, col, error);
@@ -109,7 +106,7 @@ function(stackframes) {
109106
script.src = '$this->stackTracePath';
110107
document.documentElement.appendChild(script);
111108
stackTraceJs.appended = true;
112-
109+
113110
script.onload = function() {
114111
if (stackTraceJs.isScriptPresent()) {
115112
if (!this.executed) {
@@ -121,20 +118,20 @@ function(stackframes) {
121118
continue;
122119
}
123120
var entry = queue[i];
124-
stackTraceJs.sendLogData(entry[0], entry[1], entry[2], entry[3], entry[4]);
121+
stackTraceJs.sendLogData(entry[0], entry[1], entry[2], entry[3], entry[4]);
125122
}
126-
}
123+
}
127124
} else {
128125
console.log(script);
129126
this.onerror();
130127
}
131128
};
132-
129+
133130
script.onerror = function() {
134131
console.log("StackTrace loading has failed, call default logger");
135132
basicModule.callSimpleLogger(errorMsg, file, line, col, error)
136133
};
137-
134+
138135
script.onreadystatechange = function() {
139136
var self = this;
140137
if (this.readyState == "complete" || this.readyState == "loaded") {
@@ -162,15 +159,15 @@ function(stackframes) {
162159
if (oldErrorHandler) {
163160
oldErrorHandler(errorMsg, file, line, col, error);
164161
}
165-
162+
166163
if (typeof stackTraceJsModule !== 'undefined') {
167164
stackTraceJsModule.callStackTraceJs(errorMsg, file, line, col, error);
168165
return;
169166
}
170-
167+
171168
basic.callSimpleLogger(errorMsg, file, line, col, error);
172169
};
173-
170+
174171
basic.callSimpleLogger = function callSimpleLogger(errorMsg, file, line, col, error) {
175172
var e = encodeURIComponent;
176173
@@ -182,22 +179,22 @@ function(stackframes) {
182179
'&context[browser]=' + e(navigator.userAgent) +
183180
'&context[page]=' + e(document.location.href) + basic.fetchCustomContext();
184181
};
185-
182+
186183
basic.fetchCustomContext = function fetchCustomContext() {
187184
var key,
188185
e = encodeURIComponent,
189186
customContext = window.nelmio_js_logger_custom_context,
190187
customContextStr = '';
191-
188+
192189
if ('object' === typeof customContext) {
193190
for (key in customContext) {
194191
customContextStr += '&context[' + e(key) + ']=' + e(customContext[key]);
195192
}
196-
}
197-
193+
}
194+
198195
return customContextStr;
199196
};
200-
197+
201198
return basic;
202199
}());
203200
JS;

Diff for: composer.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515
}
1616
],
1717
"require": {
18-
"php": ">=7",
18+
"php": ">=7.2.5",
1919
"ext-json": "*",
2020
"psr/log": "^1.0 || ^2.0 || ^3.0",
21-
"symfony/config": "^4.4 || ^5.3 || ^6.0",
22-
"symfony/dependency-injection": "^4.4 || ^5.3 || ^6.0",
23-
"symfony/http-foundation": "^4.4 || ^5.3 || ^6.0",
24-
"symfony/http-kernel": "^4.4 || ^5.3 || ^6.0",
25-
"symfony/routing": "^4.4 || ^5.3 || ^6.0"
21+
"symfony/config": "^4.4 || ^5.3 || ^6.0 || ^7.0",
22+
"symfony/dependency-injection": "^4.4 || ^5.3 || ^6.0 || ^7.0",
23+
"symfony/http-foundation": "^4.4 || ^5.3 || ^6.0 || ^7.0",
24+
"symfony/http-kernel": "^4.4 || ^5.3 || ^6.0 || ^7.0",
25+
"symfony/routing": "^4.4 || ^5.3 || ^6.0 || ^7.0"
2626
},
2727
"require-dev": {
28-
"twig/twig": "^1.40 || ^2.10"
28+
"twig/twig": "^1.40 || ^2.10 || ^3.0"
2929
},
3030
"autoload": {
3131
"psr-4": { "Nelmio\\JsLoggerBundle\\": "" }

0 commit comments

Comments
 (0)