Classes

File io/data/store/RAMDataStore.class.php

File io/data/store/RAMDataStore.class.php

 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 
<?php
/**
 * This is a very efficient data store, but its principal weakness is that it's life span
 * is very short, in fact it's the page's execution.
 * It's to use when you know that the data you want to store will be accessed several times during
 * the page execution.
 * @package     IO
 * @subpackage  Data\store
 * @copyright   &copy; 2005-2019 PHPBoost
 * @license     https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL-3.0
 * @author      Benoit SAUTEL <ben.popeye@phpboost.com>
 * @version     PHPBoost 5.2 - last update: 2014 12 22
 * @since       PHPBoost 3.0 - 2011 01 11
 * @contributor Loic ROUCHON <horn@phpboost.com>
*/

class RAMDataStore implements DataStore
{
    private $data = array();

    /**
     * {@inheritdoc}
     */
    public function get($id)
    {
        if ($this->contains($id))
        {
            return $this->data[$id];
        }
        throw new DataStoreException($id);
    }

    /**
     * {@inheritdoc}
     */
    public function contains($id)
    {
        return isset($this->data[$id]);
    }

    /**
     * {@inheritdoc}
     */
    public function store($id, $data)
    {
        $this->data[$id] = $data;
    }

    /**
     * {@inheritdoc}
     */
    public function delete($id)
    {
        unset($this->data[$id]);
    }

    /**
     * {@inheritdoc}
     */
    public function clear()
    {
        $this->data = array();
    }
}
?>