Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Csv.php
Go to the documentation of this file.
1 <?php
24 #require_once 'Zend/Locale.php';
25 
27 #require_once 'Zend/Translate/Adapter.php';
28 
29 
37 {
38  private $_data = array();
39 
45  public function __construct($options = array())
46  {
47  $this->_options['delimiter'] = ";";
48  $this->_options['length'] = 0;
49  $this->_options['enclosure'] = '"';
50 
51  if ($options instanceof Zend_Config) {
52  $options = $options->toArray();
53  } else if (func_num_args() > 1) {
54  $args = func_get_args();
55  $options = array();
56  $options['content'] = array_shift($args);
57 
58  if (!empty($args)) {
59  $options['locale'] = array_shift($args);
60  }
61 
62  if (!empty($args)) {
63  $opt = array_shift($args);
64  $options = array_merge($opt, $options);
65  }
66  } else if (!is_array($options)) {
67  $options = array('content' => $options);
68  }
69 
70  parent::__construct($options);
71  }
72 
82  protected function _loadTranslationData($filename, $locale, array $options = array())
83  {
84  $this->_data = array();
86  $this->_file = @fopen($filename, 'rb');
87  if (!$this->_file) {
88  #require_once 'Zend/Translate/Exception.php';
89  throw new Zend_Translate_Exception('Error opening translation file \'' . $filename . '\'.');
90  }
91 
92  while(($data = fgetcsv($this->_file, $options['length'], $options['delimiter'], $options['enclosure'])) !== false) {
93  if (substr($data[0], 0, 1) === '#') {
94  continue;
95  }
96 
97  if (!isset($data[1])) {
98  continue;
99  }
100 
101  if (count($data) == 2) {
102  $this->_data[$locale][$data[0]] = $data[1];
103  } else {
104  $singular = array_shift($data);
105  $this->_data[$locale][$singular] = $data;
106  }
107  }
108 
109  return $this->_data;
110  }
111 
117  public function toString()
118  {
119  return "Csv";
120  }
121 }
_loadTranslationData($filename, $locale, array $options=array())
Definition: Csv.php:82
__construct($options=array())
Definition: Csv.php:45