Blame view

vendor/yiisoft/multiparser/Parser.php 1.35 KB
6215a30d   Mihail   add converter int...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  <?php
  /**
   * Created by PhpStorm.
   * User: Cibermag
   * Date: 04.09.2015
   * Time: 18:25
   */
  
  namespace yii\multiparser;
  
  abstract class Parser
  {
      public $converter_conf  = [];
      protected $converter = NULL;
  
90ff40df   Mihail   fixed issue with ...
16
17
18
19
20
      /** @var array - массив с заголовком,
       * */
      public $keys = NULL;
      public $hasHeaderRow = false;
  
6215a30d   Mihail   add converter int...
21
22
23
24
25
26
27
      public function setup()
      {
          $this->setupConverter();
      }
  
      protected function setupConverter()
      {
90ff40df   Mihail   fixed issue with ...
28
29
30
31
32
          if ($this->hasHeaderRow) {
              // если у файла есть заголовок, то в результате имеем ассоциативный массив
              $this->converter_conf['hasKey'] = 1;
          }
  
6215a30d   Mihail   add converter int...
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
          $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;
  
      }
  }