FRED™  3.0
FRED™: Framework for Rapid and Easy Development
File.php
Go to the documentation of this file.
1 <?php
2 
4 
5 class File extends \Rsi\Fred\Storage\Container{
6 
7  public $path = null;
8  public $ext = '.dat';
9  public $mode = 0666;
10 
11  protected $_filename = null;
12 
13  protected function open(){
14  $this->_data = \Rsi\Record::get(\Rsi\File::unserialize($this->filename,[]),'data');
15  }
16 
17  protected function save(){
18  if($this->_data) \Rsi\File::serialize($this->filename,['key' => $this->_key,'data' => $this->_data],$this->mode);
19  else \Rsi\File::unlink($this->filename);
20  }
21 
22  protected function getFilename(){
23  if(!$this->_filename){
24  if(!$this->path) throw new \Exception('No path defined');
25  $key = is_array($this->_key) ? implode('/',$this->_key) : $this->_key;
26  $this->_filename = $this->path . preg_replace('/[^\\w\\-\\/]+/','-',strtolower($key)) . '-' . md5($key) . $this->ext;
27  \Rsi\File::mkdir(dirname($this->_filename));
28  }
29  return $this->_filename;
30  }
31 
32 }