Skip to content

Commit 2d7d85d

Browse files
committed
[Routing] Add Requirement, a collection of universal regular-expression constants to use as route parameter requirements
1 parent 8a31425 commit 2d7d85d

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

src/Symfony/Component/Routing/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CHANGELOG
77
* Add `getMissingParameters` and `getRouteName` methods on `MissingMandatoryParametersException`
88
* Allow using UTF-8 parameter names
99
* Support the `attribute` type (alias of `annotation`) in annotation loaders
10+
* Add `Requirement`, a collection of universal regular-expression constants to use as route parameter requirements
1011

1112
5.3
1213
---
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Routing;
13+
14+
/**
15+
* A collection of universal regular-expression constants to use as route parameter requirements.
16+
*/
17+
final class Requirement
18+
{
19+
public const UID_BASE32 = '[0123456789ABCDEFGHJKMNPQRSTVWXYZabcdefghjkmnpqrstvwxyz]{26}';
20+
public const UID_BASE58 = '[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{22}';
21+
public const UID_RFC4122 = '[0-9A-Fa-f]{8}(?:-[0-9A-Fa-f]{4}){3}-[0-9A-Fa-f]{12}';
22+
public const ULID = self::UID_BASE32;
23+
public const UUID = self::UID_RFC4122;
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Routing\Tests;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Routing\Requirement;
16+
use Symfony\Component\Routing\Route;
17+
18+
class RequirementTest extends TestCase
19+
{
20+
public function testAllConstantsCompile()
21+
{
22+
foreach ((new \ReflectionClass(Requirement::class))->getConstants() as $constant) {
23+
$this->assertSame(0, preg_match((new Route('/{foo}', [], ['foo' => $constant]))->compile()->getRegex(), '/foo/bar/ccc'));
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)