1 | <?php declare(strict_types=1); |
||
30 | class ParameterSpecBuilder implements ParameterSpecBuilderInterface |
||
31 | { |
||
32 | protected $regexp = '/ |
||
33 | ^ |
||
34 | (?: |
||
35 | (?<rest>\.{3}) |
||
36 | \s* |
||
37 | )? |
||
38 | (?<name>[_a-z]\w*) |
||
39 | \s* |
||
40 | (?<nullable>\?)? |
||
41 | \s* |
||
42 | (?: |
||
43 | \s* = \s* |
||
44 | (?<default> |
||
45 | (?:[+-]?[0-9]+\.?[0-9]*) # numbers (no exponential notation) |
||
46 | | |
||
47 | (?:\\\'[^\\\']*\\\') # single-quoted string |
||
48 | | |
||
49 | (?:\"[^\"]*\") # double-quoted string |
||
50 | | |
||
51 | (?:\[\s*\]) # empty array |
||
52 | | |
||
53 | (?:\{\s*\}) # empty object |
||
54 | | |
||
55 | true | false | null |
||
56 | ) |
||
57 | \s* |
||
58 | )? |
||
59 | (?: |
||
60 | \s* |
||
61 | \: |
||
62 | \s* |
||
63 | (?<type>(\w*(?:\(.*\))?(?:\[\s*\])?)(?:\s*\|\s*(?-1))*) |
||
64 | \s* |
||
65 | )? |
||
66 | $ |
||
67 | /xi'; |
||
68 | /** |
||
69 | * @var ExtractorDefinitionBuilderInterface |
||
70 | */ |
||
71 | private $extractor; |
||
72 | /** |
||
73 | * @var ArgumentValueBuilderInterface |
||
74 | */ |
||
75 | private $argument; |
||
76 | |||
77 | /** |
||
78 | * @param ExtractorDefinitionBuilderInterface $extractor |
||
79 | * @param ArgumentValueBuilderInterface $argument |
||
80 | */ |
||
81 | 14 | public function __construct(ExtractorDefinitionBuilderInterface $extractor, ArgumentValueBuilderInterface $argument) |
|
86 | |||
87 | /** |
||
88 | * @param string $definition |
||
89 | * |
||
90 | * @return ParameterSpecInterface |
||
91 | * @throws ParameterSpecBuilderException |
||
92 | */ |
||
93 | 14 | public function build(string $definition): ParameterSpecInterface |
|
126 | |||
127 | 1 | protected function buildVariadicParameterSpec(array $matches): VariadicParameterSpec |
|
131 | |||
132 | 3 | protected function buildOptionalParameterSpec(array $matches, ?string $default): OptionalParameterSpec |
|
145 | |||
146 | 5 | protected function buildMandatoryParameterSpec(array $matches): MandatoryParameterSpec |
|
150 | |||
151 | 12 | protected function prepareDefinition(array $matches): array |
|
171 | |||
172 | 9 | private function hasType(array $matches): bool |
|
176 | |||
177 | 12 | private function hasNullable(array $matches): bool |
|
181 | |||
182 | 12 | private function hasRest(array $matches): bool |
|
186 | |||
187 | 11 | private function hasDefault(array $matches): bool |
|
191 | } |
||
192 |