|
1 | 1 | <?php |
2 | | - |
3 | 2 | namespace mikehaertl\pdftk; |
4 | 3 |
|
5 | 4 | use ArrayObject; |
@@ -27,7 +26,7 @@ class InfoFields extends ArrayObject |
27 | 26 | public function __construct($input = null, $flags = 0, $iterator_class = "ArrayIterator") |
28 | 27 | { |
29 | 28 | $this->_string = $input ?: ''; |
30 | | - $this->_array = $this->parseData($this->_string); |
| 29 | + $this->_array = $this->parseData($this->_string); |
31 | 30 |
|
32 | 31 | return parent::__construct($this->_array, $flags, $iterator_class); |
33 | 32 | } |
@@ -70,66 +69,61 @@ public function __toArray() |
70 | 69 | private function parseData($dataString) |
71 | 70 | { |
72 | 71 | $expectType = null; |
73 | | - $output = array('Info'=>array(),'Bookmark'=>array(),'PageMedia'=>array()); |
74 | | - $field = array(); |
| 72 | + $output = array('Info' => array(),'Bookmark' => array(),'PageMedia' => array()); |
| 73 | + $field = array(); |
75 | 74 | $buffer = array(); |
76 | 75 | foreach (explode(PHP_EOL, $dataString) as $line) { |
77 | 76 | $trimmedLine = trim($line); |
78 | | - if($trimmedLine === 'InfoBegin') { |
| 77 | + if ($trimmedLine === 'InfoBegin') { |
79 | 78 | $expectType = 'Info'; |
80 | 79 | continue; |
81 | 80 | } |
82 | | - if($trimmedLine === 'BookmarkBegin') { |
| 81 | + if ($trimmedLine === 'BookmarkBegin') { |
83 | 82 | $expectType = 'Bookmark'; |
84 | 83 | continue; |
85 | 84 | } |
86 | | - if($trimmedLine === 'PageMediaBegin') { |
| 85 | + if ($trimmedLine === 'PageMediaBegin') { |
87 | 86 | $expectType = 'PageMedia'; |
88 | 87 | continue; |
89 | 88 | } |
90 | | - |
| 89 | + |
91 | 90 | preg_match('/([^:]*): ?(.*)/', $trimmedLine, $match); |
92 | 91 | $key = $match[1]; |
93 | 92 | $value = $match[2]; |
94 | | - |
95 | | - if($expectType == 'Info'){ |
96 | | - if($key == 'InfoKey') { |
| 93 | + |
| 94 | + if ($expectType === 'Info') { |
| 95 | + if ($key === 'InfoKey') { |
97 | 96 | $buffer['Key'] = $value; |
98 | | - } |
99 | | - elseif($key == 'InfoValue') { |
| 97 | + } elseif ($key === 'InfoValue') { |
100 | 98 | $buffer['Value'] = $value; |
101 | 99 | } |
102 | | - if(isset($buffer['Value']) && isset($buffer['Key'])) { |
| 100 | + if (isset($buffer['Value'], $buffer['Key'])) { |
103 | 101 | $output['Info'][$buffer['Key']] = $buffer['Value']; |
104 | 102 | $buffer = array(); |
105 | 103 | $expectType = null; |
106 | 104 | } |
107 | 105 | continue; |
108 | 106 | } |
109 | | - if(!is_null($expectType)){ |
110 | | - if(strpos($key, $expectType) === 0) { |
| 107 | + if ($expectType !== null) { |
| 108 | + if (strpos($key, $expectType) === 0) { |
111 | 109 | $buffer[str_replace($expectType, '', $key)] = $value; |
112 | | - } |
113 | | - else{ |
| 110 | + } else { |
114 | 111 | throw new \Exception("Unexpected input"); |
115 | 112 | } |
116 | | - if($expectType == 'Bookmark' && isset($buffer['Level']) && isset($buffer['Title']) && isset($buffer['PageNumber'])) { |
| 113 | + if ($expectType === 'Bookmark' && isset($buffer['Level'], $buffer['Title'], $buffer['PageNumber'])) { |
117 | 114 | $output[$expectType][] = $buffer; |
118 | 115 | $buffer = array(); |
119 | 116 | $expectType = null; |
120 | | - } |
121 | | - elseif($expectType == 'PageMedia' && isset($buffer['Number']) && isset($buffer['Rotation']) && isset($buffer['Rect']) && isset($buffer['Dimensions'])) { |
| 117 | + } elseif ($expectType === 'PageMedia' && isset($buffer['Number'], $buffer['Rotation'], $buffer['Rect'], $buffer['Dimensions'])) { |
122 | 118 | $output[$expectType][] = $buffer; |
123 | 119 | $buffer = array(); |
124 | 120 | $expectType = null; |
125 | 121 | } |
126 | 122 | continue; |
127 | | - } |
128 | | - else{ |
| 123 | + } else { |
129 | 124 | $output[$key] = $value; |
130 | 125 | } |
131 | 126 | } |
132 | 127 | return $output; |
133 | 128 | } |
134 | | - |
135 | 129 | } |
0 commit comments