1 | <?php |
||
2 | |||
3 | namespace Jackal\ImageMerge\Metadata\Parser; |
||
4 | |||
5 | /** |
||
6 | * Class AbstractParser |
||
7 | * @package Jackal\ImageMerge\Metadata\Parser |
||
8 | */ |
||
9 | abstract class AbstractParser implements ParserInterface |
||
10 | { |
||
11 | /** |
||
12 | * @var array |
||
13 | */ |
||
14 | protected $data = []; |
||
15 | |||
16 | /** |
||
17 | * @return bool |
||
18 | */ |
||
19 | public function isEmpty() |
||
20 | { |
||
21 | return !$this->data; |
||
22 | } |
||
23 | |||
24 | /** |
||
25 | * @param $key |
||
26 | * @return string|null|array |
||
27 | */ |
||
28 | protected function getValue($key) |
||
29 | { |
||
30 | if (isset($this->data[$key])) { |
||
31 | return $this->data[$key]; |
||
32 | } |
||
33 | |||
34 | return null; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @param $key |
||
39 | * @return int|string |
||
40 | */ |
||
41 | protected function getDivisionValue($key) |
||
42 | { |
||
43 | $value = $this->getValue($key); |
||
44 | if (strpos($value, '/1') !== false) { |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
45 | return (int) str_replace('/1', '', $value); |
||
46 | } |
||
47 | |||
48 | return $value; |
||
0 ignored issues
–
show
|
|||
49 | |||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @param $key |
||
54 | * @return bool|null |
||
55 | */ |
||
56 | protected function getBooleanValue($key) |
||
57 | { |
||
58 | $value = $this->getSingleValue($key); |
||
59 | if (is_null($value)) { |
||
60 | return $value; |
||
61 | } |
||
62 | |||
63 | return $value == true and strtolower($value) != 'false'; |
||
0 ignored issues
–
show
|
|||
64 | } |
||
65 | |||
66 | /** |
||
67 | * @param $data |
||
68 | * @return string|null |
||
69 | */ |
||
70 | protected function removeEmptyData($data) |
||
71 | { |
||
72 | if (is_string($data) and $data == '') { |
||
73 | return null; |
||
74 | } |
||
75 | |||
76 | return $data; |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * @param $key |
||
81 | * @return string|null |
||
82 | */ |
||
83 | protected function getSingleValue($key) |
||
84 | { |
||
85 | $value = $this->getValue($key); |
||
86 | if (is_array($value)) { |
||
87 | $value = array_shift($value); |
||
88 | } |
||
89 | $value = preg_replace('/[\r\n]/', "\n", $value); |
||
90 | |||
91 | return $value; |
||
92 | } |
||
93 | } |
||
94 |