FRED™  3.0
FRED™: Framework for Rapid and Easy Development
Container.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Rsi\Fred\Storage;
4 
5 abstract class Container extends \Rsi\Thing{
6 
7  protected $_storage = null;
8  protected $_key = null;
9 
10  protected $_data = null;
11  protected $_changed = false;
12 
13  public function __construct($storage,$options,$key){
14  $this->_storage = $storage;
15  $this->configure($options);
16  $this->_key = $key;
17  }
18 
19  public function __destruct(){
20  $this->commit();
21  }
22 
23  abstract protected function open();
24 
25  abstract protected function save();
26 
27  public function read($key,$default = null){
28  return \Rsi\Record::get($this->data,$key,$default);
29  }
30 
31  public function write($key,$value){
32  if($value !== $this->read($key)){
33  \Rsi\Record::set($this->_data,$key,$value);
34  $this->_changed = true;
35  }
36  }
37 
38  public function remove($key){
39  if(\Rsi\Record::exists($this->data,$key)){
40  \Rsi\Record::delete($this->_data,$key);
41  $this->_changed = true;
42  }
43  }
44 
45  public function clear(){
46  $this->_data = null;
47  $this->_changed = true;
48  }
49 
50  public function commit(){
51  if($this->_changed) $this->save();
52  $this->_changed = false;
53  }
54 
55  public function rollback(){
56  $this->_data = null;
57  $this->_changed = false;
58  }
59 
60  protected function _get($key){
61  return $this->read($key);
62  }
63 
64  protected function _set($key,$value){
65  $this->write($key,$value);
66  }
67 
68  protected function getData(){
69  if($this->_data === null) $this->open();
70  return $this->_data;
71  }
72 
73 }
Rsi\Thing
Basic object.
Definition: Thing.php:13
Rsi\Fred\Storage\Container\getData
getData()
Definition: Container.php:68
Rsi
Rsi\Fred\Storage\Container\read
read($key, $default=null)
Definition: Container.php:27
Rsi\Fred\Storage\Container\$_key
$_key
Definition: Container.php:8
Rsi\Fred\Storage\Container\$_storage
$_storage
Definition: Container.php:7
Rsi\Fred\Storage\Container\commit
commit()
Definition: Container.php:50
Rsi\Fred\Storage\Container
Definition: Container.php:5
Rsi\Fred\Storage\Container\_set
_set($key, $value)
Default setter if no specific setter is defined, and the property is also not published (writeable).
Definition: Container.php:64
Rsi\Fred\Storage\Container\save
save()
Rsi\Fred\Storage\Container\clear
clear()
Definition: Container.php:45
Rsi\Thing\configure
configure($config)
Configure the object.
Definition: Thing.php:55
Rsi\Fred\Storage\Container\rollback
rollback()
Definition: Container.php:55
Rsi\Fred\Storage\Container\$_data
$_data
Definition: Container.php:10
Rsi\Fred\Storage\Container\write
write($key, $value)
Definition: Container.php:31
Rsi\Fred\Storage\Container\open
open()
Rsi\Fred\Storage\Container\_get
_get($key)
Default getter if no specific setter is defined, and the property is also not published (readable).
Definition: Container.php:60
Rsi\Fred\Storage\Container\$_changed
$_changed
Definition: Container.php:11
Rsi\Fred\Storage\Container\__construct
__construct($storage, $options, $key)
Definition: Container.php:13
Rsi\Fred\Storage
Rsi\Fred\Storage\Container\__destruct
__destruct()
Definition: Container.php:19