1 | <?php |
||
19 | abstract class StringValueParser implements ValueParser { |
||
20 | |||
21 | /** |
||
22 | * @var ParserOptions |
||
23 | */ |
||
24 | protected $options; |
||
25 | |||
26 | /** |
||
27 | * @param ParserOptions|null $options |
||
28 | */ |
||
29 | 87 | public function __construct( ParserOptions $options = null ) { |
|
34 | |||
35 | /** |
||
36 | * @see ValueParser::parse |
||
37 | * |
||
38 | * @param string $value |
||
39 | * |
||
40 | * @return mixed |
||
41 | * @throws ParseException if the provided value is not a string |
||
42 | */ |
||
43 | 84 | public function parse( $value ) { |
|
50 | |||
51 | /** |
||
52 | * Parses the provided string and returns the result. |
||
53 | * |
||
54 | * @param string $value |
||
55 | * |
||
56 | * @return mixed |
||
57 | */ |
||
58 | abstract protected function stringParse( $value ); |
||
59 | |||
60 | 3 | public function setOptions( ParserOptions $options ) { |
|
63 | |||
64 | /** |
||
65 | * @return ParserOptions |
||
66 | */ |
||
67 | 3 | public function getOptions() { |
|
70 | |||
71 | /** |
||
72 | * Shortcut to $this->options->getOption. |
||
73 | * |
||
74 | * @param string $option |
||
75 | * |
||
76 | * @throws InvalidArgumentException |
||
77 | * @return mixed |
||
78 | */ |
||
79 | final protected function getOption( $option ) { |
||
82 | |||
83 | /** |
||
84 | * Shortcut to $this->options->requireOption. |
||
85 | * |
||
86 | * @param string $option |
||
87 | * |
||
88 | * @throws RuntimeException |
||
89 | */ |
||
90 | final protected function requireOption( $option ) { |
||
93 | |||
94 | /** |
||
95 | * Shortcut to $this->options->defaultOption. |
||
96 | * |
||
97 | * @param string $option |
||
98 | * @param mixed $default |
||
99 | */ |
||
100 | 87 | final protected function defaultOption( $option, $default ) { |
|
103 | |||
104 | } |
||
105 |