diff --git a/src/Annotation/PatternAsciiSlug.php b/src/Annotation/PatternAsciiSlug.php new file mode 100644 index 00000000..07fd6334 --- /dev/null +++ b/src/Annotation/PatternAsciiSlug.php @@ -0,0 +1,29 @@ + + * @copyright Copyright (c) 2018, Anatoly Nekhay + * @license https://github.com/sunrise-php/http-router/blob/master/LICENSE + * @link https://github.com/sunrise-php/http-router + */ + +declare(strict_types=1); + +namespace Sunrise\Http\Router\Annotation; + +use Attribute; +use Sunrise\Http\Router\Dictionary\VariablePattern; + +/** + * @since 3.0.0 + */ +#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] +final class PatternAsciiSlug extends Pattern +{ + public function __construct(string $variableName) + { + parent::__construct($variableName, VariablePattern::ASCII_SLUG); + } +} diff --git a/src/Annotation/PatternPositiveInt.php b/src/Annotation/PatternPositiveInt.php new file mode 100644 index 00000000..1fbf4964 --- /dev/null +++ b/src/Annotation/PatternPositiveInt.php @@ -0,0 +1,29 @@ + + * @copyright Copyright (c) 2018, Anatoly Nekhay + * @license https://github.com/sunrise-php/http-router/blob/master/LICENSE + * @link https://github.com/sunrise-php/http-router + */ + +declare(strict_types=1); + +namespace Sunrise\Http\Router\Annotation; + +use Attribute; +use Sunrise\Http\Router\Dictionary\VariablePattern; + +/** + * @since 3.0.0 + */ +#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] +final class PatternPositiveInt extends Pattern +{ + public function __construct(string $variableName) + { + parent::__construct($variableName, VariablePattern::POSITIVE_INT); + } +} diff --git a/src/Dictionary/VariablePattern.php b/src/Dictionary/VariablePattern.php index 69532fff..1b499de5 100644 --- a/src/Dictionary/VariablePattern.php +++ b/src/Dictionary/VariablePattern.php @@ -18,5 +18,7 @@ */ final class VariablePattern { + public const POSITIVE_INT = '[0-9]+'; + public const ASCII_SLUG = '[0-9A-Za-z]+(?:-[0-9A-Za-z]+)*'; public const UUID = '[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}'; }