Skip to content

Commit 299ac1c

Browse files
committed
[Routing] Add Requirement, a collection of universal regular expressions to use as routes parameters requirements
1 parent a14eb3f commit 299ac1c

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 expressions constants to use as routes parameters 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 expressions constants to use as routes parameters requirements.
16+
*/
17+
final class Requirement
18+
{
19+
public const BASE32 = '[0123456789ABCDEFGHJKMNPQRSTVWXYZabcdefghjkmnpqrstvwxyz]{26}';
20+
public const BASE58 = '[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{22}';
21+
public const RFC4122 = '[0-9A-Fa-f]{8}(?:-[0-9A-Fa-f]{4}){3}-[0-9A-Fa-f]{12}';
22+
public const ULID = self::BASE32;
23+
public const UUID = self::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