17 public function __construct($filename,$mode =
'r',$delimiter =
',',$enclosure =
'"',$escape =
'\\'){
18 $this->_handle = fopen($filename,$mode);
19 $this->_delimiter = $delimiter;
20 $this->_enclosure = $enclosure;
21 $this->_escape = $escape;
32 public function get($filler = null){
33 $data = fgetcsv($this->_handle,0,$this->_delimiter,$this->_enclosure,$this->_escape);
34 return $this->keys && ($data !==
false) ? \
Rsi\
Record::combine($this->keys,$data,$filler) : $data;
42 public function put($fields,$filler = null){
45 foreach($this->keys as $key) $record[] = \Rsi\Record::get($fields,$key,$filler);
48 return fputcsv($this->_handle,$fields,$this->_delimiter,$this->_enclosure,$this->_escape);
56 return $this->keys = $this->
get();
72 public function getAll($filler = null){
74 while(!$this->eof())
if(($record = $this->
get($filler)) !==
false) $records[] = $record;
81 if($this->_handle) fclose($this->_handle);
82 $this->_handle = null;
85 public function __call($func_name,$params){
86 return call_user_func_array(
'f' . \
Rsi\
Str::snake($func_name),array_merge([$this->_handle],$params));
__call($func_name, $params)
getAll($filler=null)
Return all remaining records from the file.
putKeys($keys)
Write the keys to the file and store them.
__construct($filename, $mode='r', $delimiter=',', $enclosure='"',$escape = '\)
static combine($keys, $values, $filler=null)
Creates an array by using one array for keys and another for its values.
static snake($str, $delimiter='_')
Converts a CamelCased string to snake_case.
getKeys()
Read the keys from the file and store them.
put($fields, $filler=null)
Write a single record to the file.