Skip to content

Commit e869573

Browse files
authored
Merge pull request #271 from symfony-cmf/static-typing
static type declarations
2 parents cc05a17 + 3dbedc9 commit e869573

File tree

55 files changed

+595
-1231
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+595
-1231
lines changed

.github/workflows/test-application.yaml

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111

1212
jobs:
1313
test:
14-
name: "PHP ${{ matrix.php-version }}, Symfony ${{ matrix.symfony-require }} ${{ matrix.dependencies }}"
14+
name: "PHP ${{ matrix.php-version }}, Symfony ${{ matrix.symfony-version }} ${{ matrix.dependencies }}"
1515
runs-on: "ubuntu-20.04"
1616
env:
1717
SYMFONY_DEPRECATIONS_HELPER: weak
@@ -20,24 +20,14 @@ jobs:
2020
fail-fast: false
2121
matrix:
2222
include:
23-
- php-version: "7.2"
24-
dependencies: "lowest"
25-
symfony-require: "4.4.*"
26-
27-
- php-version: "7.4"
28-
symfony-require: "4.4.*"
29-
30-
- php-version: "7.4"
31-
symfony-require: "5.0.*"
32-
3323
- php-version: "8.0"
34-
symfony-require: "5.0.*"
24+
dependencies: "lowest"
3525

3626
- php-version: "8.0"
37-
symfony-require: "6.0.*"
27+
symfony-version: "6"
3828

3929
- php-version: "8.1"
40-
symfony-require: "6.0.*"
30+
symfony-version: "6"
4131

4232
steps:
4333
- name: "Checkout project"
@@ -52,14 +42,17 @@ jobs:
5242

5343
- name: "Require Specific Symfony Version"
5444
if: "${{ matrix.symfony-version }}"
55-
run: "composer require --no-update symfony/symfony:${{ matrix.symfony-version }}"
45+
run: composer require --no-update symfony/flex && composer config extra.symfony.require ${{ matrix.symfony-version}}
5646

5747
- name: "Install dependencies with Composer"
5848
uses: "ramsey/composer-install@v1"
5949
with:
6050
dependency-versions: "${{ matrix.dependencies }}"
6151
composer-options: "--prefer-dist"
6252

53+
- name: "Install phpunit"
54+
run: vendor/bin/simple-phpunit install
55+
6356
- name: "Execute test cases"
6457
run: |
6558
if [[ $SYMFONY_PHPUNIT_VERSION == '' ]]; then unset SYMFONY_PHPUNIT_VERSION; fi;

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ Changelog
66

77
* [BC Break] Removed deprecated VersatileRouterInterface::supports, as only string route names are
88
allowed since Symfony 6.
9+
* [BC Break] As with Symfony itself, the route name now must be a `string`. As noted in
10+
the changes for CMF Routing 2.3, to generate a route from an object is to use
11+
`RouteObjectInterface::OBJECT_BASED_ROUTE_NAME` (`cmf_routing_object`) as
12+
route name and pass the route object in the parameters with key
13+
`RouteObjectInterface::ROUTE_OBJECT` (`_route_object`).
14+
* [BC Break] Added static type declarations to interfaces and classes.
915
* Revoked the deprecation on Router::match because Symfony keeps offering the match without request
1016
object.
11-
* Support Symfony 6
17+
* Support Symfony 6, dropped support for older Symfony versions.
1218

1319
2.3.4
1420
-----

composer.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@
1515
}
1616
],
1717
"require": {
18-
"php": "^7.2 || ^8.0",
19-
"symfony/routing": "^4.4 || ^5.0 || ^6.0",
20-
"symfony/http-kernel": "^4.4 || ^5.0 || ^6.0",
18+
"php": "^8.0",
19+
"symfony/routing": "^6.0",
20+
"symfony/http-kernel": "^6.0",
2121
"psr/log": "^1.0 || ^2.0 || ^3.0"
2222
},
2323
"require-dev": {
2424
"doctrine/annotations": "^1.5",
25-
"symfony/phpunit-bridge": "^5.4 || ^6.0",
26-
"symfony/dependency-injection": "^4.4 || ^5.0 || ^6.0",
27-
"symfony/config": "^4.4 || ^5.0 || ^6.0",
28-
"symfony/event-dispatcher": "^4.4 || ^5.0 || ^6.0",
29-
"symfony-cmf/testing": "^3@dev"
25+
"symfony/phpunit-bridge": "^6.0",
26+
"symfony/dependency-injection": "^6.0",
27+
"symfony/config": "^6.0",
28+
"symfony/event-dispatcher": "^6.0",
29+
"symfony-cmf/testing": "dev-master as 4.2"
3030
},
3131
"suggest": {
32-
"symfony/event-dispatcher": "DynamicRouter can optionally trigger an event at the start of matching. Minimal version (^4.4 || ^5.0)"
32+
"symfony/event-dispatcher": "DynamicRouter can optionally trigger an event at the start of matching. Minimal version ^6.0"
3333
},
3434
"autoload": {
3535
"psr-4": {

src/Candidates/Candidates.php

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,24 @@
2424
class Candidates implements CandidatesInterface
2525
{
2626
/**
27-
* @var array
27+
* @var string[]
2828
*/
29-
protected $locales;
29+
protected array $locales;
3030

3131
/**
3232
* A limit to apply to the number of candidates generated.
3333
*
3434
* This is to prevent abusive requests with a lot of "/". The limit is per
3535
* batch, that is if a locale matches you could get as many as 2 * $limit
3636
* candidates if the URL has that many slashes.
37-
*
38-
* @var int
3937
*/
40-
protected $limit;
38+
protected int $limit;
4139

4240
/**
43-
* @param array $locales The locales to support
44-
* @param int $limit A limit to apply to the candidates generated
41+
* @param string[] $locales The locales to support
42+
* @param int $limit A limit to apply to the candidates generated
4543
*/
46-
public function __construct(array $locales = [], $limit = 20)
44+
public function __construct(array $locales = [], int $limit = 20)
4745
{
4846
$this->setLocales($locales);
4947
$this->limit = $limit;
@@ -52,9 +50,9 @@ public function __construct(array $locales = [], $limit = 20)
5250
/**
5351
* Set the locales to support by this strategy.
5452
*
55-
* @param array $locales The locales to support
53+
* @param string[] $locales The locales to support
5654
*/
57-
public function setLocales(array $locales)
55+
public function setLocales(array $locales): void
5856
{
5957
$this->locales = $locales;
6058
}
@@ -64,7 +62,7 @@ public function setLocales(array $locales)
6462
*
6563
* Always returns true.
6664
*/
67-
public function isCandidate($name)
65+
public function isCandidate(string $name): bool
6866
{
6967
return true;
7068
}
@@ -74,14 +72,11 @@ public function isCandidate($name)
7472
*
7573
* Does nothing.
7674
*/
77-
public function restrictQuery($queryBuilder)
75+
public function restrictQuery(object $queryBuilder): void
7876
{
7977
}
8078

81-
/**
82-
* {@inheritdoc}
83-
*/
84-
public function getCandidates(Request $request)
79+
public function getCandidates(Request $request): array
8580
{
8681
$url = $request->getPathInfo();
8782
$candidates = $this->getCandidatesFor($url);
@@ -97,11 +92,9 @@ public function getCandidates(Request $request)
9792
/**
9893
* Determine the locale of this URL.
9994
*
100-
* @param string $url The url to determine the locale from
101-
*
10295
* @return string|bool The locale if $url starts with one of the allowed locales
10396
*/
104-
protected function determineLocale($url)
97+
protected function determineLocale(string $url): string|bool
10598
{
10699
if (!count($this->locales)) {
107100
return false;
@@ -120,13 +113,10 @@ protected function determineLocale($url)
120113
*
121114
* $prefix is prepended to every candidate generated.
122115
*
123-
* @param string $url The URL to split
124-
* @param string $prefix A prefix to prepend to every pattern
125-
*
126-
* @return array Paths that could represent routes that match $url and are
127-
* child of $prefix
116+
* @return string[] Paths that could represent routes that match $url and are
117+
* child of $prefix
128118
*/
129-
protected function getCandidatesFor($url, $prefix = '')
119+
protected function getCandidatesFor(string $url, string $prefix = ''): array
130120
{
131121
$candidates = [];
132122
if ('/' !== $url) {

src/Candidates/CandidatesInterface.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,20 @@
2222
interface CandidatesInterface
2323
{
2424
/**
25-
* @return array a list of paths
25+
* @return string[] a list of paths
2626
*/
27-
public function getCandidates(Request $request);
27+
public function getCandidates(Request $request): array;
2828

2929
/**
3030
* Determine if $name is a valid candidate, e.g. in getRouteByName.
31-
*
32-
* @param string $name
33-
*
34-
* @return bool
3531
*/
36-
public function isCandidate($name);
32+
public function isCandidate(string $name): bool;
3733

3834
/**
3935
* Provide a best effort query restriction to limit a query to only find
4036
* routes that are supported.
4137
*
4238
* @param object $queryBuilder A query builder suited for the storage backend
4339
*/
44-
public function restrictQuery($queryBuilder);
40+
public function restrictQuery(object $queryBuilder): void;
4541
}

0 commit comments

Comments
 (0)