Skip to content

Commit 4f4779c

Browse files
committed
Fix php 8 build (Bump willdurand/negotiation + Update tokens used for namespaces)
1 parent 06249eb commit 4f4779c

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

Negotiation/FormatNegotiator.php

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@
1919
use Symfony\Component\HttpFoundation\RequestStack;
2020

2121
/**
22-
* @author Ener-Getick <[email protected]>
23-
*
24-
* @final since 2.8
22+
* @internal
2523
*/
26-
class FormatNegotiator extends BaseNegotiator
24+
class BaseFormatNegotiator extends BaseNegotiator
2725
{
2826
private $map = [];
2927
private $requestStack;
@@ -40,7 +38,10 @@ public function add(RequestMatcherInterface $requestMatcher, array $options = []
4038
$this->map[] = [$requestMatcher, $options];
4139
}
4240

43-
public function getBest($header, array $priorities = [])
41+
/**
42+
* @internal
43+
*/
44+
protected function doGetBest($header, array $priorities = [])
4445
{
4546
$request = $this->getRequest();
4647
$header = $header ?: $request->headers->get('Accept');
@@ -153,3 +154,31 @@ private function getRequest(): Request
153154
return $request;
154155
}
155156
}
157+
158+
if (method_exists(BaseNegotiator::class, 'getOrderedElements')) {
159+
/**
160+
* @author Guilhem Niot <[email protected]>
161+
*
162+
* @final since 2.8
163+
*/
164+
class FormatNegotiator extends BaseFormatNegotiator
165+
{
166+
public function getBest($header, array $priorities = [], $strict = false)
167+
{
168+
return $this->doGetBest($header, $priorities);
169+
}
170+
}
171+
} else {
172+
/**
173+
* @author Guilhem Niot <[email protected]>
174+
*
175+
* @final since 2.8
176+
*/
177+
class FormatNegotiator extends BaseFormatNegotiator
178+
{
179+
public function getBest($header, array $priorities = [])
180+
{
181+
return $this->doGetBest($header, $priorities);
182+
}
183+
}
184+
}

Routing/Loader/ClassUtils.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ public static function findClassInFile(string $file): ?string
2323
$class = false;
2424
$namespace = false;
2525
$tokens = token_get_all(file_get_contents($file));
26+
27+
if (defined('T_NAME_QUALIFIED')) {
28+
$namespaceToken = T_NAME_QUALIFIED;
29+
} else {
30+
$namespaceToken = T_STRING;
31+
}
32+
2633
for ($i = 0, $count = count($tokens); $i < $count; ++$i) {
2734
$token = $tokens[$i];
2835

@@ -34,12 +41,12 @@ public static function findClassInFile(string $file): ?string
3441
return $namespace.'\\'.$token[1];
3542
}
3643

37-
if (true === $namespace && T_STRING === $token[0]) {
44+
if (true === $namespace && $namespaceToken === $token[0]) {
3845
$namespace = '';
3946
do {
4047
$namespace .= $token[1];
4148
$token = $tokens[++$i];
42-
} while ($i < $count && is_array($token) && in_array($token[0], [T_NS_SEPARATOR, T_STRING]));
49+
} while ($i < $count && is_array($token) && in_array($token[0], [T_NS_SEPARATOR, $namespaceToken]));
4350
}
4451

4552
if (T_CLASS === $token[0]) {

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"symfony/routing": "^3.4|^4.3",
4343
"symfony/security-core": "^3.4|^4.3",
4444
"doctrine/inflector": "^1.0",
45-
"willdurand/negotiation": "^2.0",
45+
"willdurand/negotiation": "^2.0|^3.0",
4646
"willdurand/jsonp-callback-validator": "^1.0"
4747
},
4848
"require-dev": {

0 commit comments

Comments
 (0)