From 1cc27986a6333a36df95b8027b73f208b3e7b08d Mon Sep 17 00:00:00 2001 From: tsurkanovm Date: Thu, 29 Oct 2015 09:42:08 +0200 Subject: [PATCH] merge with server --- .gitignore | 3 ++- backend/controllers/ParserController.php | 2 ++ common/components/parsers/config.php | 4 ++-- composer.json | 1 + composer.lock | 308 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------------------------------------------------------------------------- vendor/composer/autoload_psr4.php | 1 + vendor/composer/installed.json | 47 +++++++++++++++++++++++++++++++++++++++++++++++ vendor/yiisoft/multiparser/Converter.php | 176 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- vendor/yiisoft/multiparser/ConverterInterface.php | 16 ---------------- vendor/yiisoft/multiparser/CsvParser.php | 75 --------------------------------------------------------------------------- vendor/yiisoft/multiparser/DynamicFormHelper.php | 70 ---------------------------------------------------------------------- vendor/yiisoft/multiparser/Encoder.php | 59 ----------------------------------------------------------- vendor/yiisoft/multiparser/ObjectCreator.php | 30 ------------------------------ vendor/yiisoft/multiparser/Parser.php | 83 ----------------------------------------------------------------------------------- vendor/yiisoft/multiparser/ParserHandler.php | 112 ---------------------------------------------------------------------------------------------------------------- vendor/yiisoft/multiparser/TableParser.php | 173 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- vendor/yiisoft/multiparser/XlsxParser.php | 178 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- vendor/yiisoft/multiparser/XmlParser.php | 118 ---------------------------------------------------------------------------------------------------------------------- vendor/yiisoft/multiparser/YiiConverter.php | 51 --------------------------------------------------- vendor/yiisoft/multiparser/YiiMultiparser.php | 45 --------------------------------------------- vendor/yiisoft/multiparser/YiiParserHandler.php | 90 ------------------------------------------------------------------------------------------ vendor/yiisoft/multiparser/config.php | 20 -------------------- 22 files changed, 211 insertions(+), 1451 deletions(-) delete mode 100644 vendor/yiisoft/multiparser/Converter.php delete mode 100644 vendor/yiisoft/multiparser/ConverterInterface.php delete mode 100644 vendor/yiisoft/multiparser/CsvParser.php delete mode 100644 vendor/yiisoft/multiparser/DynamicFormHelper.php delete mode 100644 vendor/yiisoft/multiparser/Encoder.php delete mode 100644 vendor/yiisoft/multiparser/ObjectCreator.php delete mode 100644 vendor/yiisoft/multiparser/Parser.php delete mode 100644 vendor/yiisoft/multiparser/ParserHandler.php delete mode 100644 vendor/yiisoft/multiparser/TableParser.php delete mode 100644 vendor/yiisoft/multiparser/XlsxParser.php delete mode 100644 vendor/yiisoft/multiparser/XmlParser.php delete mode 100644 vendor/yiisoft/multiparser/YiiConverter.php delete mode 100644 vendor/yiisoft/multiparser/YiiMultiparser.php delete mode 100644 vendor/yiisoft/multiparser/YiiParserHandler.php delete mode 100644 vendor/yiisoft/multiparser/config.php diff --git a/.gitignore b/.gitignore index 5d27534..7f736e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea -/uploads \ No newline at end of file +/uploads +/vendor \ No newline at end of file diff --git a/backend/controllers/ParserController.php b/backend/controllers/ParserController.php index 7ae4546..f7596bd 100644 --- a/backend/controllers/ParserController.php +++ b/backend/controllers/ParserController.php @@ -1,6 +1,7 @@ mode = $mode; return $this->render('index', ['model' => $model]); diff --git a/common/components/parsers/config.php b/common/components/parsers/config.php index 144350d..749b5a5 100644 --- a/common/components/parsers/config.php +++ b/common/components/parsers/config.php @@ -52,7 +52,7 @@ ['console' => ['class' => 'yii\multiparser\XmlParser', 'node' => 'Товар', - 'hasHeaderRow' => true, + 'has_header_row' => true, 'keys' => [ "BRAND" => 'Производитель', "ARTICLE"=> 'Код', @@ -72,9 +72,9 @@ ['web' => ['class' => 'yii\multiparser\XlsxParser', 'path_for_extract_files' => \Yii::getAlias('@temp_upload') . '/', + 'has_header_row' => true, 'converter_conf' => [ 'class' => 'common\components\parsers\CustomConverter', - 'hasHeaderRow' => true, 'configuration' => ["string" => []], ] ], diff --git a/composer.json b/composer.json index 35aa241..866af0c 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,7 @@ "yiisoft/yii2": ">=2.0.6", "yiisoft/yii2-bootstrap": "*", "yiisoft/yii2-swiftmailer": "*", + "artweb/yii2-multiparser": "master-dev", "yiisoft/yii2-imagine": "*" }, "require-dev": { diff --git a/composer.lock b/composer.lock index b0a1f37..fa7a3d8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,9 +4,55 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "8580bd82955b1fbb80d47024e184056e", + "hash": "0a5f8749ae4c46cb2b7dd9d3f777c97c", + "content-hash": "4c396673df5a5e19daaa0f887579444c", "packages": [ { + "name": "artweb/yii2-multiparser", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/tsurkanovm/yii-multiparser.git", + "reference": "7a3cd2728c4b0c9db1b6bcea411f8df87b69ecd3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/tsurkanovm/yii-multiparser/zipball/7a3cd2728c4b0c9db1b6bcea411f8df87b69ecd3", + "reference": "7a3cd2728c4b0c9db1b6bcea411f8df87b69ecd3", + "shasum": "" + }, + "require": { + "yiisoft/yii2": "*" + }, + "type": "library", + "autoload": { + "psr-4": { + "yii\\multiparser\\": "lib\\" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mihail Tsurkanov", + "email": "tsurkanovm@gmail.com", + "role": "Developer" + } + ], + "description": "This extension provides a Multiparser solution for Yii framework 2.0.", + "homepage": "https://github.com/tsurkanovm/yii-multiparser.git", + "keywords": [ + "csv", + "parser", + "xlsx", + "xml", + "yii2" + ], + "time": "2015-10-26 10:04:39" + }, + { "name": "bower-asset/bootstrap", "version": "v3.3.5", "source": { @@ -317,6 +363,58 @@ "time": "2013-11-30 08:25:19" }, { + "name": "imagine/imagine", + "version": "v0.5.0", + "source": { + "type": "git", + "url": "https://github.com/avalanche123/Imagine.git", + "reference": "f64ec666baaa800edcbf237db41121a569230709" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/avalanche123/Imagine/zipball/f64ec666baaa800edcbf237db41121a569230709", + "reference": "f64ec666baaa800edcbf237db41121a569230709", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "sami/sami": "dev-master" + }, + "suggest": { + "ext-gd": "to use the GD implementation", + "ext-gmagick": "to use the Gmagick implementation", + "ext-imagick": "to use the Imagick implementation" + }, + "type": "library", + "autoload": { + "psr-0": { + "Imagine": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bulat Shakirzyanov", + "email": "mallluhuct@gmail.com", + "homepage": "http://avalanche123.com" + } + ], + "description": "Image processing for PHP 5.3", + "homepage": "http://imagine.readthedocs.org/", + "keywords": [ + "drawing", + "graphics", + "image manipulation", + "image processing" + ], + "time": "2013-07-10 17:25:36" + }, + { "name": "swiftmailer/swiftmailer", "version": "v5.4.1", "source": { @@ -459,21 +557,21 @@ }, { "name": "yiisoft/yii2-bootstrap", - "version": "2.0.4", + "version": "2.0.5", "source": { "type": "git", "url": "https://github.com/yiisoft/yii2-bootstrap.git", - "reference": "1b6b1e61cf91c3cdd517d6a7e71d30bb212e4af0" + "reference": "1464f93834b1d5edb1f5625f7ffd6c3723fa4923" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/yiisoft/yii2-bootstrap/zipball/1b6b1e61cf91c3cdd517d6a7e71d30bb212e4af0", - "reference": "1b6b1e61cf91c3cdd517d6a7e71d30bb212e4af0", + "url": "https://api.github.com/repos/yiisoft/yii2-bootstrap/zipball/1464f93834b1d5edb1f5625f7ffd6c3723fa4923", + "reference": "1464f93834b1d5edb1f5625f7ffd6c3723fa4923", "shasum": "" }, "require": { "bower-asset/bootstrap": "3.3.* | 3.2.* | 3.1.*", - "yiisoft/yii2": ">=2.0.4" + "yiisoft/yii2": ">=2.0.6" }, "type": "yii2-extension", "extra": { @@ -505,7 +603,7 @@ "bootstrap", "yii2" ], - "time": "2015-05-10 22:08:17" + "time": "2015-09-23 17:48:24" }, { "name": "yiisoft/yii2-composer", @@ -555,6 +653,54 @@ "time": "2015-03-01 06:22:44" }, { + "name": "yiisoft/yii2-imagine", + "version": "2.0.3", + "source": { + "type": "git", + "url": "https://github.com/yiisoft/yii2-imagine.git", + "reference": "0961343138b65bba447de84b2b300899617e6acc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/yiisoft/yii2-imagine/zipball/0961343138b65bba447de84b2b300899617e6acc", + "reference": "0961343138b65bba447de84b2b300899617e6acc", + "shasum": "" + }, + "require": { + "imagine/imagine": "0.5.*", + "yiisoft/yii2": "*" + }, + "type": "yii2-extension", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "yii\\imagine\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Antonio Ramirez", + "email": "amigo.cobos@gmail.com" + } + ], + "description": "The Imagine integration for the Yii framework", + "keywords": [ + "helper", + "image", + "imagine", + "yii2" + ], + "time": "2015-03-01 06:22:44" + }, + { "name": "yiisoft/yii2-swiftmailer", "version": "2.0.4", "source": { @@ -634,101 +780,6 @@ } }, { - "name": "composer/installers", - "version": "v1.0.21", - "source": { - "type": "git", - "url": "https://github.com/composer/installers.git", - "reference": "d64e23fce42a4063d63262b19b8e7c0f3b5e4c45" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/composer/installers/zipball/d64e23fce42a4063d63262b19b8e7c0f3b5e4c45", - "reference": "d64e23fce42a4063d63262b19b8e7c0f3b5e4c45", - "shasum": "" - }, - "replace": { - "roundcube/plugin-installer": "*", - "shama/baton": "*" - }, - "require-dev": { - "composer/composer": "1.0.*@dev", - "phpunit/phpunit": "4.1.*" - }, - "type": "composer-installer", - "extra": { - "class": "Composer\\Installers\\Installer", - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "psr-0": { - "Composer\\Installers\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Kyle Robinson Young", - "email": "kyle@dontkry.com", - "homepage": "https://github.com/shama" - } - ], - "description": "A multi-framework Composer library installer", - "homepage": "http://composer.github.com/installers/", - "keywords": [ - "Craft", - "Dolibarr", - "Hurad", - "MODX Evo", - "OXID", - "SMF", - "Thelia", - "WolfCMS", - "agl", - "aimeos", - "annotatecms", - "bitrix", - "cakephp", - "chef", - "codeigniter", - "concrete5", - "croogo", - "dokuwiki", - "drupal", - "elgg", - "fuelphp", - "grav", - "installer", - "joomla", - "kohana", - "laravel", - "lithium", - "magento", - "mako", - "mediawiki", - "modulework", - "moodle", - "phpbb", - "piwik", - "ppi", - "puppet", - "roundcube", - "shopware", - "silverstripe", - "symfony", - "typo3", - "wordpress", - "zend", - "zikula" - ], - "time": "2015-02-18 17:17:01" - }, - { "name": "fzaninotto/faker", "version": "v1.5.0", "source": { @@ -815,55 +866,6 @@ "time": "2013-11-01 13:02:21" }, { - "name": "silverstripe/framework", - "version": "3.1.13", - "source": { - "type": "git", - "url": "https://github.com/silverstripe/silverstripe-framework.git", - "reference": "04b803dfc6dc60f2e6a38fa74f957156230b54be" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/silverstripe/silverstripe-framework/zipball/04b803dfc6dc60f2e6a38fa74f957156230b54be", - "reference": "04b803dfc6dc60f2e6a38fa74f957156230b54be", - "shasum": "" - }, - "require": { - "composer/installers": "*", - "php": ">=5.3.2" - }, - "require-dev": { - "phpunit/phpunit": "~3.7@stable" - }, - "type": "silverstripe-module", - "autoload": { - "classmap": [ - "tests/behat/features/bootstrap" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "SilverStripe", - "homepage": "http://silverstripe.com" - }, - { - "name": "The SilverStripe Community", - "homepage": "http://silverstripe.org" - } - ], - "description": "The SilverStripe framework", - "homepage": "http://silverstripe.org", - "keywords": [ - "framework", - "silverstripe" - ], - "time": "2015-05-28 06:59:11" - }, - { "name": "yiisoft/yii2-codeception", "version": "2.0.4", "source": { @@ -1058,7 +1060,9 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "artweb/yii2-multiparser": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/vendor/composer/autoload_psr4.php b/vendor/composer/autoload_psr4.php index c5e2036..b6e9819 100644 --- a/vendor/composer/autoload_psr4.php +++ b/vendor/composer/autoload_psr4.php @@ -7,6 +7,7 @@ $baseDir = dirname($vendorDir); return array( 'yii\\swiftmailer\\' => array($vendorDir . '/yiisoft/yii2-swiftmailer'), + 'yii\\multiparser\\' => array($vendorDir . '/artweb/yii2-multiparser/lib'), 'yii\\imagine\\' => array($vendorDir . '/yiisoft/yii2-imagine'), 'yii\\gii\\' => array($vendorDir . '/yiisoft/yii2-gii'), 'yii\\faker\\' => array($vendorDir . '/yiisoft/yii2-faker'), diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 88927fc..993cfad 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -1043,5 +1043,52 @@ "imagine", "yii2" ] + }, + { + "name": "artweb/yii2-multiparser", + "version": "dev-master", + "version_normalized": "9999999-dev", + "source": { + "type": "git", + "url": "https://github.com/tsurkanovm/yii-multiparser.git", + "reference": "7a3cd2728c4b0c9db1b6bcea411f8df87b69ecd3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/tsurkanovm/yii-multiparser/zipball/7a3cd2728c4b0c9db1b6bcea411f8df87b69ecd3", + "reference": "7a3cd2728c4b0c9db1b6bcea411f8df87b69ecd3", + "shasum": "" + }, + "require": { + "yiisoft/yii2": "*" + }, + "time": "2015-10-26 10:04:39", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-4": { + "yii\\multiparser\\": "lib\\" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mihail Tsurkanov", + "email": "tsurkanovm@gmail.com", + "role": "Developer" + } + ], + "description": "This extension provides a Multiparser solution for Yii framework 2.0.", + "homepage": "https://github.com/tsurkanovm/yii-multiparser.git", + "keywords": [ + "csv", + "parser", + "xlsx", + "xml", + "yii2" + ] } ] diff --git a/vendor/yiisoft/multiparser/Converter.php b/vendor/yiisoft/multiparser/Converter.php deleted file mode 100644 index 66289c9..0000000 --- a/vendor/yiisoft/multiparser/Converter.php +++ /dev/null @@ -1,176 +0,0 @@ -', '\\'), '', $value_to_convert); - }; - - if( is_string( $value ) ){ - $value = $convert_func( $value ); - } - - if( is_array( $value ) ){ - array_walk( $value, $convert_func ); - } - - return $value; - } - - /** - * @param $name - имя метода конвертации - * @param $value - значение на конвертацию - * @return mixed - */ - public static function __callStatic($name, $value) - { - $method_name = self::METHOD_PREFIX . $name; - - if (method_exists(static::class, $method_name)) { - return static::$method_name($value[0]); - - } else { - // если такого метода конвертации не предусмотрено, то возвращаем не конвертируя - return $value[0]; - - } - } - - public function __call($name, $params) - { - return self::__callStatic($name, $params); - } - - - /** - * @param $arr - массив для конвертирования - * @param $configuration - массив конфигурация конвертирования - * @return mixed - * конвертирует массив по полученным настройкам, вызывая последовательно функции конвертации (указанные в конфигурации) - */ - public static function convertByConfiguration($arr, $configuration) - { - if ($hasKey = isset($configuration['hasKey'])) - unset($configuration['hasKey']); - - if (isset($configuration['configuration'])) { - $arr_config = $configuration['configuration']; - unset($configuration['configuration']); - } else { - throw new \Exception('Не указан обязательный параметр конфигурационного файла - converter_conf[configuration]'); - } - - // проставим аттрибуты из конфига{}{} - self::setAttributes($configuration); - - foreach ($arr_config as $key => $value) { - if ($hasKey) { - // у нас ассоциативный массив, и мы можем конвертировать каждое значение в отдельности - if (is_array($value)) { - //если пустой массив то конвертируем всю строку - if (count($value) === 0) { - - $arr = self::$key($arr); - continue; - } - // иначе конвертируем каждую ячейку в отдельности - foreach ($value as $sub_value) { - if (isset($arr[$sub_value])) { - // конвертируем только те ячейки которые сопоставлены в прочитанном массиве с колонками в конфигурационном файле - $arr[$sub_value] = self::$key($arr[$sub_value]); - } - - } - } else { - - if (isset($arr[$value])) { - // конвертируем только те ячейки которые сопоставлены в прочитанном массиве с колонками в конфигурационном файле - $arr[$value] = self::$key($arr[$value]); - // CustomVarDamp::dump($result); - } - - } - - } else { - // нет заголовка - мы можем конвертировать только строку в целом - $arr = self::$key($arr); - } - - } - - return $arr; - } - - public static function setAttributes($configuration) - { - foreach ($configuration as $key_setting => $setting) { - if (property_exists(static::class, $key_setting)) - static::$$key_setting = $setting; - } - - } - - -} \ No newline at end of file diff --git a/vendor/yiisoft/multiparser/ConverterInterface.php b/vendor/yiisoft/multiparser/ConverterInterface.php deleted file mode 100644 index 2fb22b8..0000000 --- a/vendor/yiisoft/multiparser/ConverterInterface.php +++ /dev/null @@ -1,16 +0,0 @@ -file->setCsvControl($this->delimiter); - $this->file->setFlags(\SplFileObject::READ_CSV); - $this->file->setFlags(\SplFileObject::SKIP_EMPTY); - - parent::setup(); - - } - - public function read() - { - parent::read(); - - return $this->result; - } - - - protected function readRow( ) - { - $this->row = $this->file->fgetcsv(); - } - - protected function isEmptyRow(){ - - $is_empty = false; - - if ($this->row === false || $this->row === NULL ) { - return true; - } - - $j = 0; - for ($i = 1; $i <= count( $this->row ); $i++) { - - if ( $this->isEmptyColumn( $this->row[$i - 1] ) ) { - $j++; - } - - if ( $j >= $this->min_column_quantity ) { - $is_empty = true; - break; - } - } - - return $is_empty; - } - - protected function isEmptyColumn( $val ){ - return $val == ''; - } -} \ No newline at end of file diff --git a/vendor/yiisoft/multiparser/DynamicFormHelper.php b/vendor/yiisoft/multiparser/DynamicFormHelper.php deleted file mode 100644 index 4f337b1..0000000 --- a/vendor/yiisoft/multiparser/DynamicFormHelper.php +++ /dev/null @@ -1,70 +0,0 @@ - $i) { - $arr_keys[] = self::KEY_PREFIX . $i; - $i++; - } - array_flip($arr_keys); - - } - - $model = new DynamicModel($arr_keys); - - return $model; - } - - // @todo add comments - public static function CreateGridWithDropDownListHeader( $dataProvider, $form, $header_model, $arr_header_values ) - { - $columns_config = [['class' => SerialColumn::className()]]; - $i = 0; - foreach( $header_model as $key => $value ) { - - $columns_config[] = ['header' => $form->field($header_model, $key, ['inputOptions' => ['label' => '']])->dropDownList($arr_header_values), 'attribute' => $i]; - $i++; - } - $dynamic_grid_view = GridView::widget( ['dataProvider' => $dataProvider, - 'columns' => $columns_config ] ); - - return $dynamic_grid_view; - - } - -} \ No newline at end of file diff --git a/vendor/yiisoft/multiparser/Encoder.php b/vendor/yiisoft/multiparser/Encoder.php deleted file mode 100644 index 1565ef3..0000000 --- a/vendor/yiisoft/multiparser/Encoder.php +++ /dev/null @@ -1,59 +0,0 @@ - $value) { - $object->$name = $value; - } - - return $object; - } -} \ No newline at end of file diff --git a/vendor/yiisoft/multiparser/Parser.php b/vendor/yiisoft/multiparser/Parser.php deleted file mode 100644 index 283c36f..0000000 --- a/vendor/yiisoft/multiparser/Parser.php +++ /dev/null @@ -1,83 +0,0 @@ -setupConverter(); - } - - protected function setupConverter() - { - if ( $this->has_header_row || $this->keys !== NULL ) { - // если у файла есть заголовок, то в результате имеем ассоциативный массив - $this->converter_conf['hasKey'] = 1; - } - - if ( $this->converter_conf ) { - $converter = ObjectCreator::build( $this->converter_conf ); - if ( $converter instanceof ConverterInterface ) { - - $this->converter = $converter; - - } - } - - - } - - public abstract function read(); - - /** - * @param $arr - * @return mixed - * преобразовует значения прочитанного массива в нужные типы, согласно конфигурации конвертера - */ - protected function convert( $arr ) - { - - if ($this->converter !== NULL) { - - $arr = $this->converter->convertByConfiguration( $arr, $this->converter_conf ); - - } - - - return $arr; - - } -} \ No newline at end of file diff --git a/vendor/yiisoft/multiparser/ParserHandler.php b/vendor/yiisoft/multiparser/ParserHandler.php deleted file mode 100644 index d94dda3..0000000 --- a/vendor/yiisoft/multiparser/ParserHandler.php +++ /dev/null @@ -1,112 +0,0 @@ -filePath = $filePath; - if (isset($options['mode'])) { - - $this->mode = $options['mode']; - unset($options['mode']); - - } else { - - $this->mode = self::DEFAULT_MODE; - - } - - $this->options = $options; - - $this->fileObject = new \SplFileObject($this->filePath, 'r'); - - $options['file'] = $this->fileObject; - $this->extension = $this->fileObject->getExtension(); - - $this->custom_configuration = $this->getCustomConfiguration($this->extension, $this->mode); - $this->custom_configuration = array_merge_recursive($this->custom_configuration, $options); - - } - - public function run() - { - $result = []; - if (count($this->custom_configuration)) { - - $parser = $this->createObjectByConfiguration($this->custom_configuration); - - try { - - $parser->setup(); - $result = $parser->read(); - - } catch (\ErrorException $e) { - - echo $e->getMessage(); - - } - - } - - return $result; - } - - public function getCustomConfiguration($extension, $parameter) - { - if (!count($this->configuration)) { - $this->setConfiguration(require(__DIR__ . '/config.php')); - } - - if (!isset($this->configuration[$extension])) { - throw new \ErrorException("Parser do not maintain file with extension {$extension}"); - } - if (!isset($this->configuration[$extension][$parameter])) { - throw new \ErrorException("Parser configurator do not have settings for {$parameter} parameter"); - } - - return $this->configuration[$extension][$parameter]; - } - - public function setConfiguration($configuration) - { - $this->configuration = $configuration; - } - - protected function createObjectByConfiguration($configuration) - { - return ObjectCreator::build($configuration); - } -} - - diff --git a/vendor/yiisoft/multiparser/TableParser.php b/vendor/yiisoft/multiparser/TableParser.php deleted file mode 100644 index 4a7d8f0..0000000 --- a/vendor/yiisoft/multiparser/TableParser.php +++ /dev/null @@ -1,173 +0,0 @@ -auto_detect_first_line) { - $this->shiftToFirstValuableLine(); - } - - // будем считать количество пустых строк подряд - при достижении $empty_lines_quantity - считаем что это конец файла и выходим - $empty_lines = 0; - while ( $empty_lines < $this->empty_lines_quantity ) { - // прочтем строку из файла - $this->readRow(); - - if ( $this->isEmptyRow() ) { - //счетчик пустых строк - $empty_lines++; - continue; - } - - // уберем пустые колонки из ряда - $this->filterRow(); - - - $this->adjustRowToSettings( ); - - // строка не пустая, имеем прочитанный массив значений - $this->current_row_number++; - - // для первой строки утановим ключи из заголовка - $this->setKeysFromHeader(); - - // если у нас установлен лимит, при его достижении прекращаем парсинг - if ( $this->isLastLine() ) - break; - - // обнуляем счетчик, так как считаюся пустые строки ПОДРЯД - $empty_lines = 0; - - $this->result[] = $this->row; - $this->row = []; - - } - - - } - /** - * определяет первую значимую строку, - * считывается файл пока в нем не встретится строка с непустыми колонками - * в количестве указанном в атрибуте min_column_quantity - * в результате выполнения $current_row_number будет находится на последней незначимой строке - */ - protected function shiftToFirstValuableLine() - { - do { - - $this->current_row_number ++; - $this->readRow(); - - } while( $this->isEmptyRow() ); - - // @todo - сделать опционально - // код для того что бы парсить первую строку, закомментировано как предполагается что первая значимая строка это заголовок - // $this->current_row_number --; -// $this->file->seek( $this->current_row_number ); - } - - /** - * @return array - одномерный массив результата парсинга строки - */ - protected function adjustRowToSettings( ) - { - - // если есть заголовок, то перед конвертацией его нужно назначить - if ( $this->keys !== NULL ) { - - if (count($this->keys) !== count($this->row)) { - throw new \Exception("Ошибка парсинга файла в строке # {$this->current_row_number}. Не соответсвие числа ключевых колонок (заголовка) - числу колонок с данными", 0, 1, $this->file->getBasename(), $this->current_row_number); - } - - $this->row = array_combine($this->keys, $this->row); - } - - // попытаемся конвертировать прочитанные значения согласно конфигурации котнвертера значений - $this->row = $this->convert($this->row); - - // обрежем массив к первой значимой колонке - if ( $this->first_column ) { - - $this->row = array_slice($this->row, $this->first_column); - - } - - } - - protected function setKeysFromHeader(){ - if ( $this->has_header_row ) { - // в файле есть заголовок, но он еще не назначен - назначим - if ($this->keys === NULL) { - $this->keys = array_values( $this->row ); - } - } - } - - protected function filterRow(){ - $this->row = array_filter( $this->row, function($val){ - return !$this->isEmptyColumn($val); - }); - } - - protected function isLastLine(){ - - if ( ( $this->last_line ) && ( $this->current_row_number > $this->last_line ) ) { - return true; - } - return false; - } - -} \ No newline at end of file diff --git a/vendor/yiisoft/multiparser/XlsxParser.php b/vendor/yiisoft/multiparser/XlsxParser.php deleted file mode 100644 index 73dca08..0000000 --- a/vendor/yiisoft/multiparser/XlsxParser.php +++ /dev/null @@ -1,178 +0,0 @@ -path_for_extract_files == '' ) { - $this->path_for_extract_files = sys_get_temp_dir(); - } - } - - - public function read() - { - - // $this->extractFiles(); - - $this->readSheets(); - $this->readStrings(); - - foreach ( $this->sheets_arr as $sheet ) { - //проходим по всем файлам из директории /xl/worksheets/ - - $sheet_path = $this->path_for_extract_files . '/xl/worksheets/' . $sheet . '.xml'; - if ( file_exists( $sheet_path ) && is_readable( $sheet_path ) ) { - - $xml = simplexml_load_file( $sheet_path, "SimpleXMLIterator" ); - $this->current_node = $xml->sheetData->row; - $this->current_node->rewind(); - - parent::read(); - - } - - } -CustomVarDamp::dumpAndDie($this->$result); - // return $this->$result_arr; - } - - protected function extractFiles () - { - $zip = new \ZipArchive; - if ( $zip->open( $this->file->getPathname() ) === TRUE ) { - $zip->extractTo( $this->path_for_extract_files ); - $zip->close(); - } else { - throw new \Exception( 'Ошибка чтения xlsx файла' ); - } - } - - protected function readSheets () - { - if ( $this->active_sheet ) { - $this->sheets_arr[ $this->active_sheet ] = 'Sheet' . $this->active_sheet; - return; - } - - $xml = simplexml_load_file( $this->path_for_extract_files . '/xl/workbook.xml' ); - foreach ( $xml->sheets->children() as $sheet ) { - $sheet_name = ''; - $sheet_id = 0; - $attr = $sheet->attributes(); - foreach ( $attr as $name => $value ) { - if ($name == 'name') - $sheet_name = (string)$value; - - if ($name == 'sheetId') - $sheet_id = $value; - - } - if ( $sheet_name && $sheet_id ) { - $this->sheets_arr[$sheet_name] = 'Sheet' . $sheet_id; - } -// - } - } - - protected function readStrings () - { - $xml = simplexml_load_file( $this->path_for_extract_files . '/xl/sharedStrings.xml' ); - foreach ( $xml->children() as $item ) { - $this->strings_arr[] = (string)$item->t; - } - } - - - - // protected function readRow ( $item, $sheet , $current_row ) - protected function readRow ( ) - { - $node = $this->current_node->getChildren(); - - foreach ( $node as $child ) { - $attr = $child->attributes(); - - if( isset($child->v) ) { - $value = (string)$child->v; - }else{ - $value = ''; - } - if ( isset( $attr['t'] ) ) { - // $this->result_arr[$sheet][$current_row][$cell] = $this->strings_arr[ $value ]; - $this->row[] = $this->strings_arr[ $value ]; - }else{ - // $this->result_arr[$sheet][$current_row][$cell] = $value; - $this->row[] = $value; - } - - } - $this->current_node->next(); - CustomVarDamp::dump($this->row); - } - - protected function isEmptyRow(){ - - $is_empty = false; - - if ( !count( $this->row ) || !$this->current_node->valid() ) { - return true; - } - - $j = 0; - for ($i = 1; $i <= count( $this->row ); $i++) { - - if ( $this->isEmptyColumn( $this->row[$i - 1] ) ) { - $j++; - } - - if ( $j >= $this->min_column_quantity ) { - $is_empty = true; - break; - } - } - - return $is_empty; - } - - protected function isEmptyColumn( $val ){ - return $val == ''; - } -} \ No newline at end of file diff --git a/vendor/yiisoft/multiparser/XmlParser.php b/vendor/yiisoft/multiparser/XmlParser.php deleted file mode 100644 index f96840d..0000000 --- a/vendor/yiisoft/multiparser/XmlParser.php +++ /dev/null @@ -1,118 +0,0 @@ -file; - $result = $this->xmlToArray( $file->getPathname() ); - - if ( isset($this->node) ) { - - $result = $result[ $this->node ]; - - } - - return $result; - } - - - /** - * Converts an XML string to a PHP array - * - * @uses recursiveXMLToArray() - * @param string $file_path - * @return array - */ - protected function xmlToArray( $file_path ) { - - try { - $xml = new \SimpleXMLElement( $file_path, 0, true ); - //\common\components\CustomVarDamp::dumpAndDie($xml->children()->children()); - $result = $this->recursiveXMLToArray( $xml ); - } catch(Exception $ex) { - - throw $ex; - } - - return $result; - } - - /** - * Convert a XML string to a PHP array recursively. Do not - * call this function directly - * - * @param SimpleXMLElement - * - * @return mixed - */ - protected function recursiveXMLToArray($xml) { - if( $xml instanceof \SimpleXMLElement ) { - $attributes = $xml->attributes(); - - foreach( $attributes as $key => $value ) { - if( $value ) { - $attribute_array[$key] = (string) $value; - } - } - $previous_xml = $xml; - $xml = get_object_vars($xml); - } - - if(is_array($xml)) { - - if( count($xml) == 0 ) - return (string) $previous_xml; // for CDATA - - foreach($xml as $key => $value) { - $row[$key] = $this->recursiveXMLToArray($value); - } - if ( is_string($value) ) { - // дошли до конца рекурсии - // преобразуем ряд согласно конфигурации - if ( $this->keys !== NULL ) { - // назначим ключи из конфигурации, согласно массиву $keys - $row = $this->compareArrayWithKeys( $row ); - } - $row = $this->convert( $row ); - - } - - - if( isset( $attribute_array ) ) - $row['@'] = $attribute_array; // Attributes - - return $row; - } - return (string) $xml; - } - - /** - * @param array $value_arr - текущий ряд, массив, которому нужно назначить конфигурационные ключи ($keys) - * @return array - */ - protected function compareArrayWithKeys( array $value_arr ){ - $res = $this->keys; - foreach ( $this->keys as $key => $value ) { - if ( array_key_exists( $value, $value_arr ) ) { - $res[$key] = $value_arr[$value]; - } - } - return $res; - } - -} \ No newline at end of file diff --git a/vendor/yiisoft/multiparser/YiiConverter.php b/vendor/yiisoft/multiparser/YiiConverter.php deleted file mode 100644 index 968b7b1..0000000 --- a/vendor/yiisoft/multiparser/YiiConverter.php +++ /dev/null @@ -1,51 +0,0 @@ -configuration ); - if ( $converter instanceof ConverterInterface ) { - - $this->converter = $converter; - }else{ - throw new ErrorException('Wrong type of converter'); - } - - - } - - public function convertTo( $method, $value, $attributes = [] ){ - - if ( $attributes ) { - $this->converter->setAttributes($attributes); - } - return $this->converter->$method( $value ); - - } - - public function convertByConfiguration( $value, $configuration ){ - - return $this->converter->convertByConfiguration( $value, $configuration ); - - } - - -} \ No newline at end of file diff --git a/vendor/yiisoft/multiparser/YiiMultiparser.php b/vendor/yiisoft/multiparser/YiiMultiparser.php deleted file mode 100644 index 18fdbb5..0000000 --- a/vendor/yiisoft/multiparser/YiiMultiparser.php +++ /dev/null @@ -1,45 +0,0 @@ -parserHandler = new YiiParserHandler( ); - $this->parserHandler->setConfiguration( $this->configuration ); - - } - - - public function parse( $filePath, $options = [] ){ - - $this->parserHandler->setup( $filePath, $options ); - - return $this->parserHandler->run(); - - } - - public function getConfiguration( $extension, $parameter ){ - - return $this->parserHandler->getCustomConfiguration( $extension, $parameter ); - - } - -} \ No newline at end of file diff --git a/vendor/yiisoft/multiparser/YiiParserHandler.php b/vendor/yiisoft/multiparser/YiiParserHandler.php deleted file mode 100644 index d23e2e3..0000000 --- a/vendor/yiisoft/multiparser/YiiParserHandler.php +++ /dev/null @@ -1,90 +0,0 @@ -filePath = $filePath; -// if (isset($options['mode'])) { -// -// $this->mode = $options['mode']; -// unset($options['mode']); -// -// } else { -// -// $this->mode = self::DEFAULT_MODE; -// -// } -// -// $this->options = $options; -// -// try { -// $this->fileObject = new \SplFileObject($this->filePath, 'r'); -// } catch (\ErrorException $e) { -// // Yii::warning("Ошибка открытия файла {$this->filePath}"); -// echo "Ошибка открытия файла {$this->filePath}"; -// return []; -// } -// -// $options['file'] = $this->fileObject; -// $this->extension = $this->fileObject->getExtension(); -// -// try { -// -// $this->configuration = array_merge_recursive ($this->configuration, $options); -// -// } catch (\ErrorException $e) { -// echo $e->getMessage(); -// return []; -// } -// -// } -// -// public function run() -// { -// -// $result = []; -// -// // \common\components\CustomVarDamp::dumpAndDie($this); -// if (count($this->configuration)) { -// $parser = \Yii::createObject($this->configuration); -// -// try { -// -// $parser->setup(); -// $result = $parser->read(); -// -// } catch (\ErrorException $e) { -// -// echo $e->getMessage(); -// -// } -// -// } -// -// return $result; -// } - protected function createObjectByConfiguration($configuration) - { - return \Yii::createObject($configuration); - } - - -} \ No newline at end of file diff --git a/vendor/yiisoft/multiparser/config.php b/vendor/yiisoft/multiparser/config.php deleted file mode 100644 index 950efaa..0000000 --- a/vendor/yiisoft/multiparser/config.php +++ /dev/null @@ -1,20 +0,0 @@ - - ['web' => - ['class' => 'yii\multiparser\CsvParser', - 'auto_detect_first_line' => true, - 'converter_conf' => [ - "float" => 'PRICE', - "integer" => 'QUANTITY', - "string" => 'DESCR' - ]], - 'basic_column' => [ - "ARTICLE" => 'Артикул', - "PRICE" => 'Цена', - "DESCR" => 'Наименование', - "QUANTITY" => 'Колво' - - ], - ]]; -- libgit2 0.21.4