Skip to content

Commit 1530a42

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

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

src/Symfony/Component/Routing/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
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
---
Lines changed: 24 additions & 0 deletions
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 = '[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}';
20+
public const UID_BASE58 = '[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{22}';
21+
public const UID_RFC4122 = '[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}';
22+
public const ULID = self::UID_BASE32;
23+
public const UUID = self::UID_RFC4122;
24+
}
Lines changed: 26 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy