1 | <?php |
||
9 | class ParamType { |
||
10 | |||
11 | private $typeId; |
||
12 | |||
13 | private $className; |
||
14 | private $stringParser; |
||
15 | private $typedParser; |
||
16 | private $validator; |
||
17 | private $validationCallback; |
||
18 | |||
19 | 14 | private function __construct( string $typeId ) { |
|
20 | 14 | $this->typeId = $typeId; |
|
21 | 14 | } |
|
22 | |||
23 | 14 | public static function newFromArray( string $typeId, array $spec ): self { |
|
24 | 14 | $type = new self( $typeId ); |
|
25 | |||
26 | 14 | $type->className = array_key_exists( 'definition', $spec ) ? $spec['definition'] : ParamDefinition::class; |
|
27 | 14 | $type->stringParser = array_key_exists( 'string-parser', $spec ) ? $spec['string-parser'] : NullParser::class; |
|
28 | 14 | $type->typedParser = array_key_exists( 'typed-parser', $spec ) ? $spec['typed-parser'] : NullParser::class; |
|
29 | 14 | $type->validator = array_key_exists( 'validator', $spec ) ? $spec['validator'] : NullValidator::class; |
|
30 | 14 | $type->validationCallback = array_key_exists( 'validation-callback', $spec ) ? $spec['validation-callback'] : null; |
|
31 | |||
32 | 14 | return $type; |
|
33 | } |
||
34 | |||
35 | 50 | public function getClassName(): string { |
|
38 | |||
39 | 50 | public function getValidatorClass(): string { |
|
42 | |||
43 | 50 | public function getValidationCallback(): ?callable { |
|
46 | |||
47 | 78 | public function getStringParserClass(): string { |
|
50 | |||
51 | 50 | public function getTypedParserClass(): string { |
|
54 | |||
55 | } |
||
56 |