|
4 | 4 |
|
5 | 5 | class ParameterConstraints |
6 | 6 | { |
7 | | - private array $constraints; |
8 | | - |
9 | | - /** |
10 | | - * Constructs a container for swagger constraints. |
11 | | - * Constructor parameter names match swagger keywords, see |
12 | | - * https://swagger.io/docs/specification/v3_0/data-models/keywords/. |
13 | | - * @param ?string $pattern String regex pattern. |
14 | | - * @param ?int $minLength String min length. |
15 | | - * @param ?int $maxLength String max length. |
16 | | - */ |
17 | | - public function __construct(?string $pattern = null, ?int $minLength = null, ?int $maxLength = null) |
18 | | - { |
19 | | - $this->constraints["pattern"] = $pattern; |
20 | | - $this->constraints["minLength"] = $minLength; |
21 | | - $this->constraints["maxLength"] = $maxLength; |
22 | | - } |
| 7 | + private array $constraints; |
23 | 8 |
|
24 | | - /** |
25 | | - * Adds constraints to a ParenthesesBuilder for swagger doc construction. |
26 | | - * @param \App\Helpers\Swagger\ParenthesesBuilder $container The container for keywords and values. |
27 | | - */ |
28 | | - public function addConstraints(ParenthesesBuilder $container) |
29 | | - { |
30 | | - foreach ($this->constraints as $keyword=>$value) { |
31 | | - // skip null values |
32 | | - if ($value === null) { |
33 | | - continue; |
34 | | - } |
| 9 | + /** |
| 10 | + * Constructs a container for swagger constraints. |
| 11 | + * Constructor parameter names match swagger keywords, see |
| 12 | + * https://swagger.io/docs/specification/v3_0/data-models/keywords/. |
| 13 | + * @param ?string $pattern String regex pattern. |
| 14 | + * @param ?int $minLength String min length. |
| 15 | + * @param ?int $maxLength String max length. |
| 16 | + */ |
| 17 | + public function __construct(?string $pattern = null, ?int $minLength = null, ?int $maxLength = null) |
| 18 | + { |
| 19 | + # swagger patterns must not contain the bounding '/.../' slashes |
| 20 | + if ($pattern != null && strlen($pattern) >= 2) { |
| 21 | + $pattern = substr($pattern, 1, -1); |
| 22 | + } |
35 | 23 |
|
36 | | - $container->addKeyValue($keyword, $value); |
| 24 | + $this->constraints["pattern"] = $pattern; |
| 25 | + $this->constraints["minLength"] = $minLength; |
| 26 | + $this->constraints["maxLength"] = $maxLength; |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * Adds constraints to a ParenthesesBuilder for swagger doc construction. |
| 31 | + * @param \App\Helpers\Swagger\ParenthesesBuilder $container The container for keywords and values. |
| 32 | + */ |
| 33 | + public function addConstraints(ParenthesesBuilder $container) |
| 34 | + { |
| 35 | + foreach ($this->constraints as $keyword => $value) { |
| 36 | + // skip null values |
| 37 | + if ($value === null) { |
| 38 | + continue; |
| 39 | + } |
| 40 | + |
| 41 | + $container->addKeyValue($keyword, $value); |
| 42 | + } |
37 | 43 | } |
38 | | - } |
39 | 44 | } |
0 commit comments