blob: 01022a1dc69baf2909cc2dae829cb1748268a706 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
<?php
namespace ParamProcessor\PackagePrivate;
use ParamProcessor\ParamDefinition;
use ValueParsers\NullParser;
use ValueValidators\NullValidator;
/**
* Package private
*/
class ParamType {
private $typeId;
private $className;
private $stringParser;
private $typedParser;
private $validator;
private $validationCallback;
private function __construct( string $typeId ) {
$this->typeId = $typeId;
}
public static function newFromArray( string $typeId, array $spec ): self {
$type = new self( $typeId );
$type->className = array_key_exists( 'definition', $spec ) ? $spec['definition'] : ParamDefinition::class;
$type->stringParser = array_key_exists( 'string-parser', $spec ) ? $spec['string-parser'] : NullParser::class;
$type->typedParser = array_key_exists( 'typed-parser', $spec ) ? $spec['typed-parser'] : NullParser::class;
$type->validator = array_key_exists( 'validator', $spec ) ? $spec['validator'] : NullValidator::class;
$type->validationCallback = array_key_exists( 'validation-callback', $spec ) ? $spec['validation-callback'] : null;
return $type;
}
public function getClassName(): string {
return $this->className;
}
public function getValidatorClass(): string {
return $this->validator;
}
public function getValidationCallback(): ?callable {
return $this->validationCallback;
}
public function getStringParserClass(): string {
return $this->stringParser;
}
public function getTypedParserClass(): string {
return $this->typedParser;
}
}
|