1 | <?php |
||
15 | class EraParser extends StringValueParser { |
||
16 | |||
17 | const FORMAT_NAME = 'era'; |
||
18 | |||
19 | /** |
||
20 | * @since 0.8 |
||
21 | */ |
||
22 | const BEFORE_COMMON_ERA = '-'; |
||
23 | |||
24 | /** |
||
25 | * @since 0.8 |
||
26 | */ |
||
27 | const COMMON_ERA = '+'; |
||
28 | |||
29 | /** |
||
30 | * @param string $value |
||
31 | * |
||
32 | * @throws ParseException |
||
33 | * @return string[] Array of the parsed era constant and the value with the era stripped. |
||
34 | */ |
||
35 | 38 | protected function stringParse( $value ) { |
|
36 | 38 | $value = trim( $value ); |
|
37 | |||
38 | 38 | $eraFromSign = $this->parseEraFromSign( $value ); |
|
39 | 38 | $eraFromSuffix = $this->parseEraFromSuffix( $value ); |
|
40 | |||
41 | 38 | if ( $eraFromSign && $eraFromSuffix ) { |
|
42 | 8 | throw new ParseException( |
|
43 | 8 | 'Parsed two eras from the same string', |
|
44 | 8 | $value, |
|
45 | 8 | self::FORMAT_NAME |
|
46 | ); |
||
47 | } |
||
48 | |||
49 | // Default to CE |
||
50 | 30 | return $eraFromSign ?: $eraFromSuffix ?: array( self::COMMON_ERA, $value ); |
|
51 | } |
||
52 | |||
53 | /** |
||
54 | * @param string $value |
||
55 | * |
||
56 | * @return string[]|null Array of the era constant and the value with the era stripped, or null |
||
57 | * if not successful. |
||
58 | */ |
||
59 | 38 | private function parseEraFromSign( $value ) { |
|
71 | |||
72 | /** |
||
73 | * @param string $value |
||
74 | * |
||
75 | * @return string[]|null Array of the era constant and the value with the era stripped, or null |
||
76 | * if not successful. |
||
77 | */ |
||
78 | 38 | private function parseEraFromSuffix( $value ) { |
|
103 | |||
104 | } |
||
105 |