*/ class LSioFormatCSV extends LSioFormatDriver { // File_CSV_DataSource object private $csv=false; /** * Load file * * @param[in] string $file The file path to load * * @retval boolean True if file is loaded, false otherwise **/ public function loadFile($path) { $this->csv=new File_CSV_DataSource; if (is_array($this -> options)) { foreach ($this -> options as $opt_key => $opt_val) { if (isset($this->csv -> settings[$opt_key])) $this->csv -> settings[$opt_key] = $opt_val; } } if ($this->csv->load($path)) { return True; } return false; } /** * Check if loaded file data are valid * * @retval boolean True if loaded file data are valid, false otherwise **/ public function isValid() { if ($this -> csv && $this -> csv -> isSymmetric()) { return True; } return False; } /** * Retreive all object data contained by the loaded file * * The objects are returned in array : * * array ( * array ( // Object 1 * '[field1]' => '[value1]', * '[field2]' => '[value2]', * [...] * ), * array ( // Object 2 * '[field1]' => '[value1]', * '[field2]' => '[value2]', * [...] * ), * ) * * @retval array The objects contained by the loaded file **/ public function getAll() { return $this -> csv -> connect(); } /** * Retreive fields names of the loaded file * * The fields names are returned in array : * * array ( * '[field1]', * '[field2]', * [...] * ) * * @retval array The fields names of the loaded file **/ public function getFieldNames() { return $this -> csv -> getHeaders(); } }