Commit 735c416d56e4714656cd8ca37070af692439e770

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