Commit a3b2aa93ca3b1c7a85e9419318a67015236814cd
1 parent
5140c757
change meaning of has_header_row attr, redid isEmptyRow method
Showing
6 changed files
with
82 additions
and
195 deletions
Show diff stats
lib/CsvParser.php
@@ -17,7 +17,7 @@ class CsvParser extends TableParser | @@ -17,7 +17,7 @@ class CsvParser extends TableParser | ||
17 | 17 | ||
18 | 18 | ||
19 | /** | 19 | /** |
20 | - * метод устанвливает нужные настройки объекта SplFileObject, для работы с csv | 20 | + * метод устанавливает настройки конвертера |
21 | */ | 21 | */ |
22 | public function setup() | 22 | public function setup() |
23 | { | 23 | { |
@@ -40,33 +40,6 @@ class CsvParser extends TableParser | @@ -40,33 +40,6 @@ class CsvParser extends TableParser | ||
40 | $this->row = fgetcsv( $this->file, 0, $this->delimiter ); | 40 | $this->row = fgetcsv( $this->file, 0, $this->delimiter ); |
41 | } | 41 | } |
42 | 42 | ||
43 | - protected function isEmptyRow(){ | ||
44 | - | ||
45 | - $is_empty = false; | ||
46 | - | ||
47 | - if ($this->row === false || $this->row === NULL ) { | ||
48 | - return true; | ||
49 | - } | ||
50 | - | ||
51 | - $j = 0; | ||
52 | - for ($i = 1; $i <= count( $this->row ); $i++) { | ||
53 | - | ||
54 | - if ( !isset( $this->row[ $i - 1 ] ) ) { | ||
55 | - continue; | ||
56 | - } | ||
57 | - | ||
58 | - if ( $this->isEmptyColumn( $this->row[$i - 1] ) ) { | ||
59 | - $j++; | ||
60 | - } | ||
61 | - | ||
62 | - if ( $j >= $this->min_column_quantity ) { | ||
63 | - $is_empty = true; | ||
64 | - break; | ||
65 | - } | ||
66 | - } | ||
67 | - | ||
68 | - return $is_empty; | ||
69 | - } | ||
70 | 43 | ||
71 | protected function isEmptyColumn( $val ){ | 44 | protected function isEmptyColumn( $val ){ |
72 | return $val == ''; | 45 | return $val == ''; |
lib/Parser.php
@@ -9,8 +9,6 @@ | @@ -9,8 +9,6 @@ | ||
9 | namespace yii\multiparser; | 9 | namespace yii\multiparser; |
10 | 10 | ||
11 | //@todo - заменить read на parse | 11 | //@todo - заменить read на parse |
12 | -//@todo - xml - убрать из названий функций xml и array - это и так понятно | ||
13 | - | ||
14 | 12 | ||
15 | use common\components\CustomVarDamp; | 13 | use common\components\CustomVarDamp; |
16 | 14 | ||
@@ -32,20 +30,8 @@ abstract class Parser | @@ -32,20 +30,8 @@ abstract class Parser | ||
32 | /** @var array - массив с заголовком, | 30 | /** @var array - массив с заголовком, |
33 | * */ | 31 | * */ |
34 | public $keys = NULL; | 32 | public $keys = NULL; |
35 | - /** @var bool | ||
36 | - имеет ли файл заголовок который будет установлен ключами возвращемого массива*/ | ||
37 | - public $has_header_row = false; | ||
38 | - /* | ||
39 | - *если есть ключи, то колонки с пустыми значениями будут пропускаться (из ряда такие значения будут удаляться), | ||
40 | - * например если в файле вторая колонка пустая то она будет удалена | ||
41 | - * если есть $has_header_row - то первая значимая строка становится ключами, но пустые колонки не удаляются из ряда | ||
42 | - * например если в файле вторая колонка пустая то ей будет назначен соответсвующий ключ (второй) из первой строки | ||
43 | - * все описаное выше реализуется в дочернем семействе классов TableParser в методе filterRow() | ||
44 | - * для xml происходит просто сопоставление переданных ключей с прочитанными | ||
45 | - */ | ||
46 | - | ||
47 | - | ||
48 | 33 | ||
34 | + public abstract function read(); | ||
49 | 35 | ||
50 | public function setup() | 36 | public function setup() |
51 | { | 37 | { |
@@ -54,7 +40,7 @@ abstract class Parser | @@ -54,7 +40,7 @@ abstract class Parser | ||
54 | 40 | ||
55 | protected function setupConverter() | 41 | protected function setupConverter() |
56 | { | 42 | { |
57 | - if ( $this->has_header_row || $this->keys !== NULL ) { | 43 | + if ( !empty( $this->keys ) ) { |
58 | // если у файла есть заголовок, то в результате имеем ассоциативный массив | 44 | // если у файла есть заголовок, то в результате имеем ассоциативный массив |
59 | $this->converter_conf['hasKey'] = 1; | 45 | $this->converter_conf['hasKey'] = 1; |
60 | } | 46 | } |
@@ -67,12 +53,8 @@ abstract class Parser | @@ -67,12 +53,8 @@ abstract class Parser | ||
67 | 53 | ||
68 | } | 54 | } |
69 | } | 55 | } |
70 | - | ||
71 | - | ||
72 | } | 56 | } |
73 | 57 | ||
74 | - public abstract function read(); | ||
75 | - | ||
76 | /** | 58 | /** |
77 | * @param $arr | 59 | * @param $arr |
78 | * @return mixed | 60 | * @return mixed |
@@ -80,32 +62,24 @@ abstract class Parser | @@ -80,32 +62,24 @@ abstract class Parser | ||
80 | */ | 62 | */ |
81 | protected function convert( $arr ) | 63 | protected function convert( $arr ) |
82 | { | 64 | { |
83 | - | ||
84 | if ($this->converter !== NULL) { | 65 | if ($this->converter !== NULL) { |
85 | 66 | ||
86 | $arr = $this->converter->convertByConfiguration( $arr, $this->converter_conf ); | 67 | $arr = $this->converter->convertByConfiguration( $arr, $this->converter_conf ); |
87 | 68 | ||
88 | } | 69 | } |
89 | - | ||
90 | - | ||
91 | return $arr; | 70 | return $arr; |
92 | - | ||
93 | } | 71 | } |
94 | 72 | ||
95 | public final static function supportedExtension() | 73 | public final static function supportedExtension() |
96 | { | 74 | { |
97 | - return ['csv','xml','xlsx','txt']; | 75 | + return ['csv','xml','xlsx','txt','xls']; |
98 | } | 76 | } |
99 | 77 | ||
100 | protected function cleanUp( ) | 78 | protected function cleanUp( ) |
101 | { | 79 | { |
102 | - | ||
103 | unset( $this->file ); | 80 | unset( $this->file ); |
104 | unset( $this->converter ); | 81 | unset( $this->converter ); |
105 | unset( $this->converter_conf ); | 82 | unset( $this->converter_conf ); |
106 | - | ||
107 | - | ||
108 | } | 83 | } |
109 | 84 | ||
110 | - | ||
111 | } | 85 | } |
112 | \ No newline at end of file | 86 | \ No newline at end of file |
lib/TableParser.php
@@ -13,14 +13,19 @@ use common\components\CustomVarDamp; | @@ -13,14 +13,19 @@ use common\components\CustomVarDamp; | ||
13 | 13 | ||
14 | abstract class TableParser extends Parser | 14 | abstract class TableParser extends Parser |
15 | { | 15 | { |
16 | - | ||
17 | - | ||
18 | /** | 16 | /** |
19 | * @var array - текущий отпарсенный ряд | 17 | * @var array - текущий отпарсенный ряд |
18 | + *если есть ключи, то колонки с пустыми значениями будут пропускаться (из ряда такие значения будут удаляться), | ||
19 | + * например если в файле вторая колонка пустая то она будет удалена | ||
20 | + * в остальных случаях парсятся все колонки (не проверяется - пустая ли колонка) и попадёт в итоговый массив | ||
20 | */ | 21 | */ |
21 | protected $row = []; | 22 | protected $row = []; |
22 | 23 | ||
23 | - /** @var int - первая строка с которой начинать парсить */ | 24 | + /** @var int - первая строка с которой начинать парсить |
25 | + * эта строка будет считаться первой значимой строкой | ||
26 | + * если установлен аттрибут $has_header_row, | ||
27 | + * тогда следующая строка будет считаться заголовком и будет пропущена | ||
28 | + */ | ||
24 | public $first_line = 0; | 29 | public $first_line = 0; |
25 | 30 | ||
26 | /** @var int - последняя строка до которой парсить | 31 | /** @var int - последняя строка до которой парсить |
@@ -32,9 +37,11 @@ abstract class TableParser extends Parser | @@ -32,9 +37,11 @@ abstract class TableParser extends Parser | ||
32 | 37 | ||
33 | 38 | ||
34 | /** @var bool | 39 | /** @var bool |
35 | - нужно ли искать автоматически первоую значисмую строку (не пустая строка) | ||
36 | - * иначе первая строка будет взята из аттрибута $first_line */ | ||
37 | - public $auto_detect_first_line = false; | 40 | + * имеет ли файл заголовок в первой значимой строке |
41 | + * true - первая значимая строка будет пропущена | ||
42 | + */ | ||
43 | + public $has_header_row = true; | ||
44 | + | ||
38 | 45 | ||
39 | /** @var int - количество значимых колонок, что бы определить первую значимую строку | 46 | /** @var int - количество значимых колонок, что бы определить первую значимую строку |
40 | * используется при автоопределении первой строки*/ | 47 | * используется при автоопределении первой строки*/ |
@@ -48,8 +55,6 @@ abstract class TableParser extends Parser | @@ -48,8 +55,6 @@ abstract class TableParser extends Parser | ||
48 | protected $current_row_number = 0; | 55 | protected $current_row_number = 0; |
49 | 56 | ||
50 | 57 | ||
51 | - protected abstract function isEmptyRow(); | ||
52 | - | ||
53 | protected abstract function isEmptyColumn($column_value); | 58 | protected abstract function isEmptyColumn($column_value); |
54 | 59 | ||
55 | protected abstract function readRow(); | 60 | protected abstract function readRow(); |
@@ -59,69 +64,71 @@ abstract class TableParser extends Parser | @@ -59,69 +64,71 @@ abstract class TableParser extends Parser | ||
59 | 64 | ||
60 | public function read() | 65 | public function read() |
61 | { | 66 | { |
62 | - if ($this->auto_detect_first_line) { | ||
63 | - $this->shiftToFirstValuableLine(); | ||
64 | - } | 67 | + // получим первую значимую строку |
68 | + $this->shiftToFirstValuableLine(); | ||
69 | + | ||
70 | + // первый проход, строка прочитана в shiftToFirstValuableLine | ||
71 | + $first_circle = true; | ||
65 | 72 | ||
66 | // будем считать количество пустых строк подряд - при достижении $empty_lines_quantity - считаем что это конец файла и выходим | 73 | // будем считать количество пустых строк подряд - при достижении $empty_lines_quantity - считаем что это конец файла и выходим |
67 | $empty_lines = 0; | 74 | $empty_lines = 0; |
68 | while ($empty_lines < $this->empty_lines_quantity) { | 75 | while ($empty_lines < $this->empty_lines_quantity) { |
69 | - // прочтем строку из файла | ||
70 | - $this->readRow(); | ||
71 | 76 | ||
72 | - if ($this->isEmptyRow()) { | ||
73 | - //счетчик пустых строк | ||
74 | - $empty_lines++; | ||
75 | - $this->current_row_number++; | ||
76 | - continue; | 77 | + // прочтем строку из файла, если это не первый проход |
78 | + if (!$first_circle){ | ||
79 | + $this->readRow(); | ||
77 | } | 80 | } |
78 | 81 | ||
82 | + $first_circle = false; | ||
83 | + | ||
79 | // уберем пустые колонки из ряда | 84 | // уберем пустые колонки из ряда |
80 | if ($this->keys === NULL) { | 85 | if ($this->keys === NULL) { |
81 | $this->filterRow(); | 86 | $this->filterRow(); |
82 | } | 87 | } |
83 | 88 | ||
89 | + if ($this->isEmptyRow()) { | ||
90 | + //счетчик пустых строк | ||
91 | + $empty_lines++; | ||
92 | + $this->current_row_number++; | ||
93 | + continue; | ||
94 | + } | ||
84 | 95 | ||
96 | + // запустим конвертирование | ||
85 | $this->adjustRowToSettings(); | 97 | $this->adjustRowToSettings(); |
86 | 98 | ||
99 | + // установим отпарсенную строку в итоговый массив результата | ||
100 | + $this->setResult(); | ||
87 | // строка не пустая, имеем прочитанный массив значений | 101 | // строка не пустая, имеем прочитанный массив значений |
88 | $this->current_row_number++; | 102 | $this->current_row_number++; |
89 | 103 | ||
90 | - // для первой строки утановим ключи из заголовка | ||
91 | - if (!$this->setKeysFromHeader()) { | ||
92 | - $this->setResult(); | ||
93 | - } | ||
94 | - | ||
95 | - | ||
96 | // если у нас установлен лимит, при его достижении прекращаем парсинг | 104 | // если у нас установлен лимит, при его достижении прекращаем парсинг |
97 | if ($this->isLastLine()) | 105 | if ($this->isLastLine()) |
98 | break; | 106 | break; |
99 | 107 | ||
100 | // обнуляем счетчик, так как считаюся пустые строки ПОДРЯД | 108 | // обнуляем счетчик, так как считаюся пустые строки ПОДРЯД |
101 | $empty_lines = 0; | 109 | $empty_lines = 0; |
102 | - | ||
103 | } | 110 | } |
104 | } | 111 | } |
105 | 112 | ||
106 | /** | 113 | /** |
107 | * определяет первую значимую строку, | 114 | * определяет первую значимую строку, |
108 | * считывается файл пока в нем не встретится строка с непустыми колонками | 115 | * считывается файл пока в нем не встретится строка с непустыми колонками |
109 | - * в количестве указанном в атрибуте min_column_quantity | ||
110 | - * в результате выполнения $current_row_number будет находится на последней незначимой строке | 116 | + * или пока не дойдет до first_line |
117 | + * пропускает заголовок если он указан | ||
111 | */ | 118 | */ |
112 | protected function shiftToFirstValuableLine() | 119 | protected function shiftToFirstValuableLine() |
113 | { | 120 | { |
121 | + // читаем пока не встретим значимую строку, или пока не дойдем до first_line | ||
114 | do { | 122 | do { |
115 | - | ||
116 | $this->current_row_number++; | 123 | $this->current_row_number++; |
117 | $this->readRow(); | 124 | $this->readRow(); |
125 | + } while ( $this->isEmptyRow() && ( $this->first_line < $this->current_row_number ) ); | ||
118 | 126 | ||
119 | - } while ($this->isEmptyRow()); | ||
120 | - | ||
121 | - // @todo - сделать опционально | ||
122 | - // код для того что бы парсить первую строку, закомментировано как предполагается что первая значимая строка это заголовок | ||
123 | - // $this->current_row_number --; | ||
124 | -// $this->file->seek( $this->current_row_number ); | 127 | + // если указан заголовок, то его мы тоже пропускаем (читаем далее) |
128 | + if( $this->has_header_row ) { | ||
129 | + $this->current_row_number++; | ||
130 | + $this->readRow(); | ||
131 | + } | ||
125 | } | 132 | } |
126 | 133 | ||
127 | /** | 134 | /** |
@@ -129,7 +136,6 @@ abstract class TableParser extends Parser | @@ -129,7 +136,6 @@ abstract class TableParser extends Parser | ||
129 | */ | 136 | */ |
130 | protected function adjustRowToSettings() | 137 | protected function adjustRowToSettings() |
131 | { | 138 | { |
132 | - | ||
133 | // если есть заголовок, то перед конвертацией его нужно назначить | 139 | // если есть заголовок, то перед конвертацией его нужно назначить |
134 | if ($this->keys !== NULL) { | 140 | if ($this->keys !== NULL) { |
135 | // adjust row to keys | 141 | // adjust row to keys |
@@ -150,22 +156,43 @@ abstract class TableParser extends Parser | @@ -150,22 +156,43 @@ abstract class TableParser extends Parser | ||
150 | 156 | ||
151 | } | 157 | } |
152 | 158 | ||
153 | - protected function setKeysFromHeader() | ||
154 | - { | ||
155 | - if ($this->has_header_row) { | ||
156 | - // в файле есть заголовок, но он еще не назначен - назначим | ||
157 | - if ($this->keys === NULL) { | ||
158 | - $this->keys = array_values($this->row); | ||
159 | - return true; | 159 | + protected function isEmptyRow(){ |
160 | + | ||
161 | + $is_empty = false; | ||
162 | + | ||
163 | + if ( empty( $this->row ) ) { | ||
164 | + return true; | ||
165 | + } | ||
166 | + if ( count( $this->row ) < $this->min_column_quantity ) { | ||
167 | + return true; | ||
168 | + } | ||
169 | + | ||
170 | + $j = 0; | ||
171 | + for ($i = 1; $i <= count( $this->row ); $i++) { | ||
172 | + | ||
173 | + if ( !isset( $this->row[ $i - 1 ] ) ) { | ||
174 | + continue; | ||
175 | + } | ||
176 | + | ||
177 | + if ( $this->isEmptyColumn( $this->row[$i - 1] ) ) { | ||
178 | + $j++; | ||
179 | + } | ||
180 | + | ||
181 | + if ( $j >= $this->min_column_quantity ) { | ||
182 | + $is_empty = true; | ||
183 | + break; | ||
160 | } | 184 | } |
161 | } | 185 | } |
162 | - return false; | 186 | + |
187 | + return $is_empty; | ||
163 | } | 188 | } |
164 | 189 | ||
190 | + | ||
191 | + | ||
165 | protected function filterRow() | 192 | protected function filterRow() |
166 | { | 193 | { |
167 | - // если есть заголовок - все значения нужны, не фильтруем | ||
168 | - if ($this->has_header_row || !is_array($this->row)) { | 194 | + // нет строки - нет фильтрации |
195 | + if ( empty( $this->row ) ) { | ||
169 | return; | 196 | return; |
170 | } | 197 | } |
171 | $this->row = array_filter($this->row, function ($val) { | 198 | $this->row = array_filter($this->row, function ($val) { |
lib/XlsParser.php
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | /** | 2 | /** |
3 | 3 | ||
4 | */ | 4 | */ |
5 | -namespace common\components\parsers; | 5 | +namespace yii\multiparser; |
6 | 6 | ||
7 | /** | 7 | /** |
8 | * Class XlsParser | 8 | * Class XlsParser |
@@ -66,36 +66,6 @@ class XlsParser extends TableParser | @@ -66,36 +66,6 @@ class XlsParser extends TableParser | ||
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | - protected function isEmptyRow(){ | ||
70 | - | ||
71 | - $is_empty = false; | ||
72 | - | ||
73 | - if ( !$this->row ) { | ||
74 | - return true; | ||
75 | - } | ||
76 | - if ( count( $this->row ) < $this->min_column_quantity ) { | ||
77 | - return true; | ||
78 | - } | ||
79 | - | ||
80 | - $j = 0; | ||
81 | - for ($i = 1; $i <= count( $this->row ); $i++) { | ||
82 | - | ||
83 | - if ( !isset( $this->row[ $i - 1 ] ) ) { | ||
84 | - continue; | ||
85 | - } | ||
86 | - | ||
87 | - if ( $this->isEmptyColumn( $this->row[$i - 1] ) ) { | ||
88 | - $j++; | ||
89 | - } | ||
90 | - | ||
91 | - if ( $j >= $this->min_column_quantity ) { | ||
92 | - $is_empty = true; | ||
93 | - break; | ||
94 | - } | ||
95 | - } | ||
96 | - | ||
97 | - return $is_empty; | ||
98 | - } | ||
99 | 69 | ||
100 | protected function isEmptyColumn( $val ){ | 70 | protected function isEmptyColumn( $val ){ |
101 | return $val == ''; | 71 | return $val == ''; |
lib/XlsxParser.php
@@ -175,58 +175,17 @@ class XlsxParser extends TableParser | @@ -175,58 +175,17 @@ class XlsxParser extends TableParser | ||
175 | $value = (string)round( $value, $this->float_precision ); | 175 | $value = (string)round( $value, $this->float_precision ); |
176 | } | 176 | } |
177 | 177 | ||
178 | - | ||
179 | } else { | 178 | } else { |
180 | $value = ''; | 179 | $value = ''; |
181 | } | 180 | } |
182 | - | ||
183 | // set | 181 | // set |
184 | $this->row[$i] = $value; | 182 | $this->row[$i] = $value; |
185 | - | ||
186 | } | 183 | } |
187 | -// // fill the row by empty values for keys that we are missed in previous step | ||
188 | - // only for 'has_header_row = true' mode | ||
189 | - if ( $this->has_header_row && $this->keys !== Null ) { | ||
190 | - $extra_column = count( $this->keys ) - count( $this->row ); | ||
191 | - if ( $extra_column ) { | ||
192 | - foreach ( $this->keys as $key => $key ) { | ||
193 | - | ||
194 | - if ( isset( $this->row[$key] ) ) { | ||
195 | - continue; | ||
196 | - } | ||
197 | - $this->row[$key] = ''; | ||
198 | - } | ||
199 | - } | ||
200 | 184 | ||
201 | - } | ||
202 | ksort( $this->row ); | 185 | ksort( $this->row ); |
203 | $this->current_node->next(); | 186 | $this->current_node->next(); |
204 | } | 187 | } |
205 | 188 | ||
206 | - protected function isEmptyRow() | ||
207 | - { | ||
208 | - | ||
209 | - $is_empty = false; | ||
210 | - | ||
211 | - if (!count($this->row)) { | ||
212 | - return true; | ||
213 | - } | ||
214 | - | ||
215 | - $j = 0; | ||
216 | - for ($i = 1; $i <= count($this->row); $i++) { | ||
217 | - | ||
218 | - if (isset($this->row[$i - 1]) && $this->isEmptyColumn($this->row[$i - 1])) { | ||
219 | - $j++; | ||
220 | - } | ||
221 | - | ||
222 | - if ($j >= $this->min_column_quantity) { | ||
223 | - $is_empty = true; | ||
224 | - break; | ||
225 | - } | ||
226 | - } | ||
227 | - | ||
228 | - return $is_empty; | ||
229 | - } | ||
230 | 189 | ||
231 | protected function isEmptyColumn($val) | 190 | protected function isEmptyColumn($val) |
232 | { | 191 | { |
@@ -261,7 +220,6 @@ class XlsxParser extends TableParser | @@ -261,7 +220,6 @@ class XlsxParser extends TableParser | ||
261 | } | 220 | } |
262 | } | 221 | } |
263 | 222 | ||
264 | - | ||
265 | /** | 223 | /** |
266 | * @param $cell_address - string with address like A1, B1 ... | 224 | * @param $cell_address - string with address like A1, B1 ... |
267 | * @return int - integer index | 225 | * @return int - integer index |
@@ -281,17 +239,7 @@ class XlsxParser extends TableParser | @@ -281,17 +239,7 @@ class XlsxParser extends TableParser | ||
281 | return $index; | 239 | return $index; |
282 | 240 | ||
283 | } | 241 | } |
284 | -// @todo - переписать родительский метод в универсальной манере а не переопределять его | ||
285 | - protected function setKeysFromHeader(){ | ||
286 | - if ( $this->has_header_row ) { | ||
287 | 242 | ||
288 | - if ($this->keys === NULL) { | ||
289 | - $this->keys = $this->row; | ||
290 | - return true; | ||
291 | - } | ||
292 | - } | ||
293 | - return false; | ||
294 | - } | ||
295 | protected function cleanUp() | 243 | protected function cleanUp() |
296 | { | 244 | { |
297 | parent::cleanUp(); | 245 | parent::cleanUp(); |
lib/XmlParser.php
@@ -15,15 +15,13 @@ class XmlParser extends Parser{ | @@ -15,15 +15,13 @@ class XmlParser extends Parser{ | ||
15 | 15 | ||
16 | public function read() | 16 | public function read() |
17 | { | 17 | { |
18 | - //$file = $this->file; | ||
19 | - $result = $this->xmlToArray( ); | 18 | + $result = $this->parseToArray( ); |
20 | 19 | ||
21 | if ( isset($this->node) ) { | 20 | if ( isset($this->node) ) { |
22 | 21 | ||
23 | $result = $result[ $this->node ]; | 22 | $result = $result[ $this->node ]; |
24 | 23 | ||
25 | } | 24 | } |
26 | - | ||
27 | $this->cleanUp(); | 25 | $this->cleanUp(); |
28 | return $result; | 26 | return $result; |
29 | } | 27 | } |
@@ -36,17 +34,15 @@ class XmlParser extends Parser{ | @@ -36,17 +34,15 @@ class XmlParser extends Parser{ | ||
36 | * @throws Exception | 34 | * @throws Exception |
37 | * @throws \Exception | 35 | * @throws \Exception |
38 | */ | 36 | */ |
39 | - protected function xmlToArray( ) { | ||
40 | - | 37 | + protected function parseToArray( ) { |
41 | try { | 38 | try { |
42 | $xml = new \SimpleXMLElement( $this->file_path, 0, true ); | 39 | $xml = new \SimpleXMLElement( $this->file_path, 0, true ); |
43 | //\common\components\CustomVarDamp::dumpAndDie($xml->children()->children()); | 40 | //\common\components\CustomVarDamp::dumpAndDie($xml->children()->children()); |
44 | - $result = $this->recursiveXMLToArray( $xml ); | 41 | + $result = $this->recursiveParseToArray( $xml ); |
45 | } catch(\Exception $ex) { | 42 | } catch(\Exception $ex) { |
46 | 43 | ||
47 | throw $ex; | 44 | throw $ex; |
48 | } | 45 | } |
49 | - | ||
50 | return $result; | 46 | return $result; |
51 | } | 47 | } |
52 | 48 | ||
@@ -58,7 +54,7 @@ class XmlParser extends Parser{ | @@ -58,7 +54,7 @@ class XmlParser extends Parser{ | ||
58 | * | 54 | * |
59 | * @return mixed | 55 | * @return mixed |
60 | */ | 56 | */ |
61 | - protected function recursiveXMLToArray($xml) { | 57 | + protected function recursiveParseToArray($xml) { |
62 | if( $xml instanceof \SimpleXMLElement ) { | 58 | if( $xml instanceof \SimpleXMLElement ) { |
63 | $attributes = $xml->attributes(); | 59 | $attributes = $xml->attributes(); |
64 | 60 | ||
@@ -77,7 +73,7 @@ class XmlParser extends Parser{ | @@ -77,7 +73,7 @@ class XmlParser extends Parser{ | ||
77 | return (string) $previous_xml; // for CDATA | 73 | return (string) $previous_xml; // for CDATA |
78 | 74 | ||
79 | foreach($xml as $key => $value) { | 75 | foreach($xml as $key => $value) { |
80 | - $row[$key] = $this->recursiveXMLToArray($value); | 76 | + $row[$key] = $this->recursiveParseToArray($value); |
81 | } | 77 | } |
82 | if ( is_string($value) ) { | 78 | if ( is_string($value) ) { |
83 | // дошли до конца рекурсии | 79 | // дошли до конца рекурсии |
@@ -90,7 +86,6 @@ class XmlParser extends Parser{ | @@ -90,7 +86,6 @@ class XmlParser extends Parser{ | ||
90 | 86 | ||
91 | } | 87 | } |
92 | 88 | ||
93 | - | ||
94 | if( isset( $attribute_array ) ) | 89 | if( isset( $attribute_array ) ) |
95 | $row['@'] = $attribute_array; // Attributes | 90 | $row['@'] = $attribute_array; // Attributes |
96 | 91 |