Commit 735c416d56e4714656cd8ca37070af692439e770
1 parent
221da14e
add compatibility with php 5.5
Showing
2 changed files
with
14 additions
and
12 deletions
Show diff stats
lib/Converter.php
| @@ -9,13 +9,15 @@ | @@ -9,13 +9,15 @@ | ||
| 9 | namespace yii\multiparser; | 9 | namespace yii\multiparser; |
| 10 | 10 | ||
| 11 | // класс который содержит преобразователи значений (фильтры) используемые при парсинге | 11 | // класс который содержит преобразователи значений (фильтры) используемые при парсинге |
| 12 | +use common\components\CustomVarDamp; | ||
| 13 | + | ||
| 12 | class Converter implements ConverterInterface | 14 | class Converter implements ConverterInterface |
| 13 | { | 15 | { |
| 14 | 16 | ||
| 15 | const METHOD_PREFIX = 'convertTo'; | 17 | const METHOD_PREFIX = 'convertTo'; |
| 16 | 18 | ||
| 17 | //public $configuration = []; | 19 | //public $configuration = []; |
| 18 | - | 20 | + |
| 19 | public static function convertToFloat($value) | 21 | public static function convertToFloat($value) |
| 20 | { | 22 | { |
| 21 | if ($value == '') { | 23 | if ($value == '') { |
| @@ -87,7 +89,6 @@ class Converter implements ConverterInterface | @@ -87,7 +89,6 @@ class Converter implements ConverterInterface | ||
| 87 | public static function __callStatic($name, $value) | 89 | public static function __callStatic($name, $value) |
| 88 | { | 90 | { |
| 89 | $method_name = self::METHOD_PREFIX . $name; | 91 | $method_name = self::METHOD_PREFIX . $name; |
| 90 | - | ||
| 91 | if (method_exists(static::class, $method_name)) { | 92 | if (method_exists(static::class, $method_name)) { |
| 92 | return static::$method_name($value[0]); | 93 | return static::$method_name($value[0]); |
| 93 | 94 |
lib/XlsxParser.php
| @@ -7,7 +7,7 @@ | @@ -7,7 +7,7 @@ | ||
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | namespace yii\multiparser; | 9 | namespace yii\multiparser; |
| 10 | - | 10 | +use common\components\CustomVarDamp; |
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | /** | 13 | /** |
| @@ -47,17 +47,14 @@ class XlsxParser extends TableParser { | @@ -47,17 +47,14 @@ class XlsxParser extends TableParser { | ||
| 47 | 47 | ||
| 48 | public function read() | 48 | public function read() |
| 49 | { | 49 | { |
| 50 | - $this->extractFiles(); | ||
| 51 | - | 50 | + $this->extractFiles(); |
| 52 | $this->readSheets(); | 51 | $this->readSheets(); |
| 53 | $this->readStrings(); | 52 | $this->readStrings(); |
| 54 | - | ||
| 55 | foreach ( $this->sheets_arr as $sheet ) { | 53 | foreach ( $this->sheets_arr as $sheet ) { |
| 56 | //проходим по всем файлам из директории /xl/worksheets/ | 54 | //проходим по всем файлам из директории /xl/worksheets/ |
| 57 | $this->current_sheet = $sheet; | 55 | $this->current_sheet = $sheet; |
| 58 | $sheet_path = $this->path_for_extract_files . '/xl/worksheets/' . $sheet . '.xml'; | 56 | $sheet_path = $this->path_for_extract_files . '/xl/worksheets/' . $sheet . '.xml'; |
| 59 | if ( file_exists( $sheet_path ) && is_readable( $sheet_path ) ) { | 57 | if ( file_exists( $sheet_path ) && is_readable( $sheet_path ) ) { |
| 60 | - | ||
| 61 | $xml = simplexml_load_file( $sheet_path, "SimpleXMLIterator" ); | 58 | $xml = simplexml_load_file( $sheet_path, "SimpleXMLIterator" ); |
| 62 | $this->current_node = $xml->sheetData->row; | 59 | $this->current_node = $xml->sheetData->row; |
| 63 | $this->current_node->rewind(); | 60 | $this->current_node->rewind(); |
| @@ -68,8 +65,9 @@ class XlsxParser extends TableParser { | @@ -68,8 +65,9 @@ class XlsxParser extends TableParser { | ||
| 68 | } | 65 | } |
| 69 | 66 | ||
| 70 | $this->cleanUp(); | 67 | $this->cleanUp(); |
| 68 | + | ||
| 71 | if ( $this->active_sheet ) { | 69 | if ( $this->active_sheet ) { |
| 72 | - // в настройках указан конкретный лист с которогшо будем производить чтение, поэтому и возвращаем подмассив | 70 | + // в настройках указан конкретный лист с которого будем производить чтение, поэтому и возвращаем подмассив |
| 73 | return $this->result[ $this->current_sheet ]; | 71 | return $this->result[ $this->current_sheet ]; |
| 74 | }else{ | 72 | }else{ |
| 75 | return $this->result; | 73 | return $this->result; |
| @@ -80,16 +78,19 @@ class XlsxParser extends TableParser { | @@ -80,16 +78,19 @@ class XlsxParser extends TableParser { | ||
| 80 | protected function extractFiles () | 78 | protected function extractFiles () |
| 81 | { | 79 | { |
| 82 | $this->path_for_extract_files = $this->path_for_extract_files . session_id(); | 80 | $this->path_for_extract_files = $this->path_for_extract_files . session_id(); |
| 83 | - if ( !mkdir($this->path_for_extract_files) ) | ||
| 84 | - { | ||
| 85 | - throw new \Exception( 'Ошибка создания временного каталога - ' . $this->path_for_extract_files ); | 81 | + if ( !file_exists($this->path_for_extract_files )) { |
| 82 | + if ( !mkdir( $this->path_for_extract_files ) ) | ||
| 83 | + { | ||
| 84 | + throw new \Exception( 'Ошибка создания временного каталога - ' . $this->path_for_extract_files ); | ||
| 86 | } | 85 | } |
| 86 | + } | ||
| 87 | 87 | ||
| 88 | $zip = new \ZipArchive; | 88 | $zip = new \ZipArchive; |
| 89 | if ( $zip->open( $this->file_path ) === TRUE ) { | 89 | if ( $zip->open( $this->file_path ) === TRUE ) { |
| 90 | $zip->extractTo( $this->path_for_extract_files . '/' ); | 90 | $zip->extractTo( $this->path_for_extract_files . '/' ); |
| 91 | $zip->close(); | 91 | $zip->close(); |
| 92 | } else { | 92 | } else { |
| 93 | + | ||
| 93 | throw new \Exception( 'Ошибка чтения xlsx файла' ); | 94 | throw new \Exception( 'Ошибка чтения xlsx файла' ); |
| 94 | } | 95 | } |
| 95 | unset($zip); | 96 | unset($zip); |
| @@ -98,7 +99,7 @@ class XlsxParser extends TableParser { | @@ -98,7 +99,7 @@ class XlsxParser extends TableParser { | ||
| 98 | protected function readSheets () | 99 | protected function readSheets () |
| 99 | { | 100 | { |
| 100 | if ( $this->active_sheet ) { | 101 | if ( $this->active_sheet ) { |
| 101 | - $this->sheets_arr[ ] = 'Sheet' . $this->active_sheet; | 102 | + $this->sheets_arr[ ] = 'sheet' . $this->active_sheet; |
| 102 | return; | 103 | return; |
| 103 | } | 104 | } |
| 104 | 105 |