diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4ea66c5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2015 Mihail Tsurkanov + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..c49d989 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +#YII2 Multiparser + + +Flexible bunch of parsers for YII 2. + +##Requirements## + +The Multiparser library has the following requirements: + + - artweb/multiparser + diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..cb4083f --- /dev/null +++ b/composer.json @@ -0,0 +1,25 @@ +{ + "name": "artweb/yii-multiparser", + "type": "library", + "description": "Flexible bunch of parsers for PHP 5.3", + "keywords": [ "yii", "parser", "csv", "xml" ], + "homepage": "https://github.com/tsurkanovm/multiparser.git", + "license": "MIT", + "authors": [ + { + "name": "Mihail Tsurkanov", + "email": "tsurkanovm@gmail.com", + "homepage": "http://samoinvestor.ru", + "role": "Developer" + } + ], + "require": { + "yiisoft/yii2": "*", + "artweb/multiparser": "0.5.*" + }, + "autoload": { + "psr-4": { + "yii\\multiparser\\": "" + } + } +} diff --git a/lib/DynamicFormHelper.php b/lib/DynamicFormHelper.php new file mode 100644 index 0000000..4f337b1 --- /dev/null +++ b/lib/DynamicFormHelper.php @@ -0,0 +1,70 @@ + $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/lib/YiiMultiparser.php b/lib/YiiMultiparser.php new file mode 100644 index 0000000..58ff2d7 --- /dev/null +++ b/lib/YiiMultiparser.php @@ -0,0 +1,43 @@ +configuration[$extension] )){ + throw new \ErrorException( "Parser do not maintain file with extension {$extension}"); + } + if (!isset( $this->configuration[$extension][$conf_parameter] )){ + throw new \ErrorException( "Parser configurator do not have settings for {$conf_parameter} parameter"); + } + + return $this->configuration[$extension][$conf_parameter]; + + } + + + public function parse( $filePath, $options = [] ){ + + $parser = new YiiParserHandler( $filePath, $options ); + return $parser->run(); + + } + + +} \ No newline at end of file diff --git a/lib/YiiParserHandler.php b/lib/YiiParserHandler.php new file mode 100644 index 0000000..5bf86ad --- /dev/null +++ b/lib/YiiParserHandler.php @@ -0,0 +1,84 @@ +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 = \Yii::$app->multiparser->getConfiguration($this->extension, $this->mode); + $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; + } + +} \ No newline at end of file -- libgit2 0.21.4