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 }
Rsi
Rsi\Fred\Storage\Container\File
Definition: File.php:5
Rsi\Fred\Storage\Container\$_key
$_key
Definition: Container.php:8
Rsi\Fred\Storage\Container\File\save
save()
Definition: File.php:17
Rsi\Fred\Storage\Container\File\open
open()
Definition: File.php:13
Rsi\Fred\Storage\Container\File\$ext
$ext
Definition: File.php:8
Rsi\Fred\Storage\Container\File\$_filename
$_filename
Definition: File.php:11
Rsi\Fred\Storage\Container\File\$path
$path
Definition: File.php:7
Rsi\Fred\Storage\Container\File\getFilename
getFilename()
Definition: File.php:22
Rsi\Fred\Storage\Container
Definition: File.php:3
Rsi\Fred\Storage\Container\File\$mode
$mode
Definition: File.php:9