Skip to content

Commit 864d560

Browse files
authored
Merge pull request #269 from acrobat/allow-sf6
Prepare major release and allow symfony 6
2 parents bbcdf2f + 89ae391 commit 864d560

16 files changed

+105
-275
lines changed

.github/workflows/test-application.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ jobs:
3131
symfony-require: "5.0.*"
3232

3333
- php-version: "8.0"
34-
symfony-require: "*"
34+
symfony-require: "5.0.*"
35+
36+
- php-version: "8.0"
37+
symfony-require: "6.0.*"
3538

3639
steps:
3740
- name: "Checkout project"

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
],
1717
"require": {
1818
"php": "^7.2 || ^8.0",
19-
"symfony/routing": "^4.4 || ^5.0",
20-
"symfony/http-kernel": "^4.4 || ^5.0",
19+
"symfony/routing": "^4.4 || ^5.0 || ^6.0",
20+
"symfony/http-kernel": "^4.4 || ^5.0 || ^6.0",
2121
"psr/log": "^1.0 || ^2.0 || ^3.0"
2222
},
2323
"require-dev": {
24-
"symfony/phpunit-bridge": "^5.0",
25-
"symfony/dependency-injection": "^4.4 || ^5.0",
26-
"symfony/config": "^4.4 || ^5.0",
27-
"symfony/event-dispatcher": "^4.4 || ^5.0",
24+
"symfony/phpunit-bridge": "^5.4 || ^6.0",
25+
"symfony/dependency-injection": "^4.4 || ^5.0 || ^6.0",
26+
"symfony/config": "^4.4 || ^5.0 || ^6.0",
27+
"symfony/event-dispatcher": "^4.4 || ^5.0 || ^6.0",
2828
"symfony-cmf/testing": "^3@dev"
2929
},
3030
"suggest": {

src/ChainRouteCollection.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,15 @@ public function __clone()
4343
*
4444
* @return \ArrayIterator An \ArrayIterator object for iterating over routes
4545
*/
46-
public function getIterator()
46+
public function getIterator(): \ArrayIterator
4747
{
4848
return new \ArrayIterator($this->all());
4949
}
5050

5151
/**
5252
* Gets the number of Routes in this collection.
53-
*
54-
* @return int The number of routes
5553
*/
56-
public function count()
54+
public function count(): int
5755
{
5856
$count = 0;
5957
foreach ($this->routeCollections as $routeCollection) {
@@ -81,7 +79,7 @@ public function add($name, Route $route, int $priority = 0)
8179
*
8280
* @return Route[] An array of routes
8381
*/
84-
public function all()
82+
public function all(): array
8583
{
8684
$routeCollectionAll = new RouteCollection();
8785
foreach ($this->routeCollections as $routeCollection) {
@@ -95,17 +93,17 @@ public function all()
9593
* Gets a route by name.
9694
*
9795
* @param string $name The route name
98-
*
99-
* @return Route|null A Route instance or null when not found
10096
*/
101-
public function get($name)
97+
public function get($name): ?Route
10298
{
10399
foreach ($this->routeCollections as $routeCollection) {
104100
$route = $routeCollection->get($name);
105101
if (null !== $route) {
106102
return $route;
107103
}
108104
}
105+
106+
return null;
109107
}
110108

111109
/**
@@ -240,7 +238,7 @@ public function setMethods($methods)
240238
*
241239
* @return ResourceInterface[] An array of resources
242240
*/
243-
public function getResources()
241+
public function getResources(): array
244242
{
245243
if (0 === count($this->routeCollections)) {
246244
return [];

src/ChainRouter.php

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ public function __construct(LoggerInterface $logger = null)
6767
$this->logger = $logger;
6868
}
6969

70-
/**
71-
* @return RequestContext
72-
*/
73-
public function getContext()
70+
public function getContext(): RequestContext
7471
{
7572
if (!$this->context) {
7673
$this->context = new RequestContext();
@@ -143,7 +140,7 @@ protected function sortRouters()
143140
*
144141
* Note: You should use matchRequest if you can.
145142
*/
146-
public function match($pathinfo)
143+
public function match($pathinfo): array
147144
{
148145
return $this->doMatch($pathinfo);
149146
}
@@ -153,7 +150,7 @@ public function match($pathinfo)
153150
*
154151
* Loops through all routes and tries to match the passed request.
155152
*/
156-
public function matchRequest(Request $request)
153+
public function matchRequest(Request $request): array
157154
{
158155
return $this->doMatch($request->getPathInfo(), $request);
159156
}
@@ -213,21 +210,15 @@ private function doMatch($pathinfo, Request $request = null)
213210
/**
214211
* {@inheritdoc}
215212
*
216-
* @param mixed $name
217-
*
218-
* The CMF routing system used to allow to pass route objects as $name to generate the route.
219-
* Since Symfony 5.0, the UrlGeneratorInterface declares $name as string. We widen the contract
220-
* for BC but deprecate passing non-strings.
221-
* Instead, Pass the RouteObjectInterface::OBJECT_BASED_ROUTE_NAME as route name and the object
222-
* in the parameters with key RouteObjectInterface::ROUTE_OBJECT.
213+
* @param string $name
223214
*
224215
* Loops through all registered routers and returns a router if one is found.
225216
* It will always return the first route generated.
226217
*/
227-
public function generate($name, $parameters = [], $absolute = UrlGeneratorInterface::ABSOLUTE_PATH)
218+
public function generate($name, $parameters = [], $absolute = UrlGeneratorInterface::ABSOLUTE_PATH): string
228219
{
229-
if (is_object($name)) {
230-
@trigger_error('Passing an object as route name is deprecated since version 2.3. Pass the `RouteObjectInterface::OBJECT_BASED_ROUTE_NAME` as route name and the object in the parameters with key `RouteObjectInterface::ROUTE_OBJECT`.', E_USER_DEPRECATED);
220+
if (!is_string($name)) {
221+
throw new \InvalidArgumentException('The "$name" parameter should of type string.');
231222
}
232223

233224
$debug = [];

src/ContentAwareGenerator.php

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -56,36 +56,28 @@ public function setContentRepository(ContentRepositoryInterface $contentReposito
5656
/**
5757
* {@inheritdoc}
5858
*
59-
* The CMF routing system used to allow to pass route objects as $name to generate the route.
60-
* Since Symfony 5.0, the UrlGeneratorInterface declares $name as string. We widen the contract
61-
* for BC but deprecate passing non-strings.
62-
* Instead, Pass the RouteObjectInterface::OBJECT_BASED_ROUTE_NAME as route name and the object
63-
* in the parameters with key RouteObjectInterface::ROUTE_OBJECT or the ID of a
64-
* RouteReferrersReadInterface in 'content_id.
65-
*
66-
* @param mixed $name ignored
67-
* @param array $parameters must either contain the field 'route' with a
68-
* RouteObjectInterface or the field 'content_id'
69-
* with the id of a document implementing
70-
* RouteReferrersReadInterface
59+
* @param string $name ignored
60+
* @param array $parameters must either contain the field 'route' with a
61+
* RouteObjectInterface or the field 'content_id'
62+
* with the id of a document implementing RouteReferrersReadInterface
7163
*
7264
* @throws RouteNotFoundException If there is no such route in the database
7365
*/
74-
public function generate($name, $parameters = [], $absolute = UrlGeneratorInterface::ABSOLUTE_PATH)
66+
public function generate($name, $parameters = [], $absolute = UrlGeneratorInterface::ABSOLUTE_PATH): string
7567
{
76-
if ($name instanceof SymfonyRoute) {
77-
@trigger_error('Passing an object as route name is deprecated since version 2.3. Pass the `RouteObjectInterface::OBJECT_BASED_ROUTE_NAME` as route name and the object in the parameters with key `RouteObjectInterface::ROUTE_OBJECT` resp the content id with content_id.', E_USER_DEPRECATED);
68+
if (!is_string($name)) {
69+
throw new \InvalidArgumentException('The "$name" parameter should of type string.');
70+
}
7871

79-
$route = $this->getBestLocaleRoute($name, $parameters);
80-
} elseif (RouteObjectInterface::OBJECT_BASED_ROUTE_NAME === $name) {
72+
if (RouteObjectInterface::OBJECT_BASED_ROUTE_NAME === $name) {
8173
if (array_key_exists(RouteObjectInterface::ROUTE_OBJECT, $parameters)
8274
&& $parameters[RouteObjectInterface::ROUTE_OBJECT] instanceof SymfonyRoute
8375
) {
8476
$route = $this->getBestLocaleRoute($parameters[RouteObjectInterface::ROUTE_OBJECT], $parameters);
8577
} else {
8678
$route = $this->getRouteByContent($name, $parameters);
8779
}
88-
} elseif (is_string($name) && $name) {
80+
} elseif (!empty($name)) {
8981
$route = $this->getRouteByName($name, $parameters);
9082
} else {
9183
$route = $this->getRouteByContent($name, $parameters);
@@ -167,21 +159,16 @@ protected function getBestLocaleRoute(SymfonyRoute $route, $parameters)
167159
* If no route with matching locale is found, falls back to just return the
168160
* first route.
169161
*
170-
* @param mixed $name
171162
* @param array $parameters which should contain a content field containing
172163
* a RouteReferrersReadInterface object
173164
*
174165
* @return SymfonyRoute the route instance
175166
*
176167
* @throws RouteNotFoundException if no route can be determined
177168
*/
178-
protected function getRouteByContent($name, &$parameters)
169+
protected function getRouteByContent(string $name, &$parameters)
179170
{
180-
if ($name instanceof RouteReferrersReadInterface) {
181-
@trigger_error('Passing an object as route name is deprecated since version 2.3. Pass the `RouteObjectInterface::OBJECT_BASED_ROUTE_NAME` as route name and the object in the parameters with key `RouteObjectInterface::ROUTE_OBJECT`.', E_USER_DEPRECATED);
182-
183-
$content = $name;
184-
} elseif (RouteObjectInterface::OBJECT_BASED_ROUTE_NAME === $name
171+
if (RouteObjectInterface::OBJECT_BASED_ROUTE_NAME === $name
185172
&& array_key_exists(RouteObjectInterface::ROUTE_OBJECT, $parameters)
186173
&& $parameters[RouteObjectInterface::ROUTE_OBJECT] instanceof RouteReferrersReadInterface
187174
) {
@@ -197,9 +184,7 @@ protected function getRouteByContent($name, &$parameters)
197184
throw new RouteNotFoundException('Content repository did not return a RouteReferrersReadInterface instance for id '.$parameters['content_id']);
198185
}
199186
} else {
200-
$hint = is_object($name) ? get_class($name) : gettype($name);
201-
202-
throw new RouteNotFoundException("The route name argument '$hint' is not a RouteReferrersReadInterface instance and there is no 'content_id' parameter");
187+
throw new RouteNotFoundException(sprintf("The route name argument '%s' is not a RouteReferrersReadInterface instance and there is no 'content_id' parameter", gettype($name)));
203188
}
204189

205190
$routes = $content->getRoutes();

src/DynamicRouter.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,14 @@ public function getGenerator()
159159
* Instead, Pass the RouteObjectInterface::OBJECT_BASED_ROUTE_NAME as route name and the object
160160
* in the parameters with key RouteObjectInterface::ROUTE_OBJECT.
161161
*
162-
* @param string|Route $name The name of the route or the Route instance
162+
* @param string $name The name of the route
163163
*
164164
* @throws RouteNotFoundException if route doesn't exist
165165
*/
166-
public function generate($name, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
166+
public function generate($name, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH): string
167167
{
168-
if (is_object($name)) {
169-
@trigger_error('Passing an object as route name is deprecated since version 2.3. Pass the `RouteObjectInterface::OBJECT_BASED_ROUTE_NAME` as route name and the object in the parameters with key `RouteObjectInterface::ROUTE_OBJECT', E_USER_DEPRECATED);
168+
if (!is_string($name)) {
169+
throw new \InvalidArgumentException('The "$name" parameter should of type string.');
170170
}
171171

172172
if ($this->eventDispatcher) {
@@ -213,7 +213,7 @@ public function supports($name)
213213
*
214214
* @api
215215
*/
216-
public function match($pathinfo)
216+
public function match($pathinfo): array
217217
{
218218
@trigger_error(__METHOD__.'() is deprecated since version 1.3 and will be removed in 2.0. Use matchRequest() instead.', E_USER_DEPRECATED);
219219

@@ -252,7 +252,7 @@ public function match($pathinfo)
252252
* @throws MethodNotAllowedException If a matching resource was found but
253253
* the request method is not allowed
254254
*/
255-
public function matchRequest(Request $request)
255+
public function matchRequest(Request $request): array
256256
{
257257
if ($this->eventDispatcher) {
258258
$event = new RouterMatchEvent($request);
@@ -294,7 +294,7 @@ public function setContext(RequestContext $context)
294294
*
295295
* @api
296296
*/
297-
public function getContext()
297+
public function getContext(): RequestContext
298298
{
299299
return $this->context;
300300
}

src/LazyRouteCollection.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,15 @@ public function __construct(RouteProviderInterface $provider)
3232
/**
3333
* {@inheritdoc}
3434
*/
35-
public function getIterator()
35+
public function getIterator(): \ArrayIterator
3636
{
3737
return new \ArrayIterator($this->all());
3838
}
3939

4040
/**
4141
* Gets the number of Routes in this collection.
42-
*
43-
* @return int The number of routes
4442
*/
45-
public function count()
43+
public function count(): int
4644
{
4745
return count($this->all());
4846
}
@@ -52,7 +50,7 @@ public function count()
5250
*
5351
* @return Route[] An array of routes
5452
*/
55-
public function all()
53+
public function all(): array
5654
{
5755
return $this->provider->getRoutesByNames(null);
5856
}
@@ -61,15 +59,13 @@ public function all()
6159
* Gets a route by name.
6260
*
6361
* @param string $name The route name
64-
*
65-
* @return Route|null A Route instance or null when not found
6662
*/
67-
public function get($name)
63+
public function get($name): ?Route
6864
{
6965
try {
7066
return $this->provider->getRouteByName($name);
7167
} catch (RouteNotFoundException $e) {
72-
return;
68+
return null;
7369
}
7470
}
7571
}

src/NestedMatcher/NestedMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function setFinalMatcher(FinalMatcherInterface $final)
135135
/**
136136
* {@inheritdoc}
137137
*/
138-
public function matchRequest(Request $request)
138+
public function matchRequest(Request $request): array
139139
{
140140
$collection = $this->routeProvider->getRouteCollectionForRequest($request);
141141
if (!count($collection)) {

src/NestedMatcher/UrlMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function finalMatch(RouteCollection $collection, Request $request)
4343
/**
4444
* {@inheritdoc}
4545
*/
46-
protected function getAttributes(Route $route, $name, array $attributes)
46+
protected function getAttributes(Route $route, $name, array $attributes): array
4747
{
4848
if ($route instanceof RouteObjectInterface && is_string($route->getRouteKey())) {
4949
$name = $route->getRouteKey();

src/PagedRouteCollection.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ protected function loadNextElements($offset)
6969
}
7070

7171
/**
72-
* {@inheritdoc}
72+
* @return mixed
7373
*/
74+
#[\ReturnTypeWillChange]
7475
public function current()
7576
{
7677
return current($this->currentRoutes);
@@ -79,7 +80,7 @@ public function current()
7980
/**
8081
* {@inheritdoc}
8182
*/
82-
public function next()
83+
public function next(): void
8384
{
8485
$result = next($this->currentRoutes);
8586
if (false === $result) {
@@ -89,8 +90,9 @@ public function next()
8990
}
9091

9192
/**
92-
* {@inheritdoc}
93+
* @return mixed
9394
*/
95+
#[\ReturnTypeWillChange]
9496
public function key()
9597
{
9698
return key($this->currentRoutes);
@@ -99,15 +101,15 @@ public function key()
99101
/**
100102
* {@inheritdoc}
101103
*/
102-
public function valid()
104+
public function valid(): bool
103105
{
104-
return key($this->currentRoutes);
106+
return null !== key($this->currentRoutes);
105107
}
106108

107109
/**
108110
* {@inheritdoc}
109111
*/
110-
public function rewind()
112+
public function rewind(): void
111113
{
112114
$this->current = 0;
113115
$this->currentRoutes = null;

0 commit comments

Comments
 (0)