Neevo Public API
  • Namespace
  • Class
  • Tree

Namespaces

  • Neevo
    • Nette
  • None
  • PHP

Classes

  • Neevo
  • NeevoBaseStmt
  • NeevoCacheFile
  • NeevoCacheMemcache
  • NeevoCacheMemory
  • NeevoCacheSession
  • NeevoConnection
  • NeevoDriverMySQL
  • NeevoDriverMySQLi
  • NeevoDriverPgSQL
  • NeevoDriverSQLite2
  • NeevoDriverSQLite3
  • NeevoLiteral
  • NeevoLoader
  • NeevoObserverMap
  • NeevoParser
  • NeevoResult
  • NeevoResultIterator
  • NeevoRow
  • NeevoStmt

Interfaces

  • INeevoCache
  • INeevoDriver
  • INeevoObservable
  • INeevoObserver

Exceptions

  • NeevoDriverException
  • NeevoException
  • NeevoImplementationException
  1 <?php
  2 /**
  3  * Neevo - Tiny database layer for PHP. (http://neevo.smasty.net)
  4  *
  5  * This source file is subject to the MIT license that is bundled
  6  * with this package in the file license.txt.
  7  *
  8  * Copyright (c) 2011 Martin Srank (http://smasty.net)
  9  *
 10  */
 11 
 12 
 13 /**
 14  * Neevo cache storage interface.
 15  * @author Martin Srank
 16  * @package Neevo\Cache
 17  */
 18 interface INeevoCache {
 19 
 20 
 21     /**
 22      * Fetch stored data.
 23      * @param string $key
 24      * @return mixed|null null if not found
 25      */
 26     public function fetch($key);
 27 
 28 
 29     /**
 30      * Store data in cache.
 31      * @param string $key
 32      * @param mixed $value
 33      * @return void
 34      */
 35     public function store($key, $value);
 36 
 37 
 38 }
 39 
 40 
 41 
 42 /**
 43  * Memory cache storage.
 44  * Default implementation of INeevoCache.
 45  * @author Martin Srank
 46  * @package Neevo\Cache
 47  */
 48 class NeevoCacheMemory implements INeevoCache {
 49 
 50 
 51     /** @var array */
 52     private $data = array();
 53 
 54 
 55     public function fetch($key){
 56         return array_key_exists($key, $this->data) ? $this->data[$key] : null;
 57     }
 58 
 59 
 60     public function store($key, $value){
 61         $this->data[$key] = $value;
 62     }
 63 
 64 
 65     public function flush(){
 66         return !$this->data = array();
 67     }
 68 
 69 
 70 }
 71 
 72 
 73 
 74 /**
 75  * Session cache storage.
 76  * @author Martin Srank
 77  * @package Neevo\Cache
 78  */
 79 class NeevoCacheSession implements INeevoCache {
 80 
 81 
 82     public function fetch($key){
 83         return array_key_exists($key, $_SESSION['NeevoCache']) ? $_SESSION['NeevoCache'][$key] : null;
 84     }
 85 
 86 
 87     public function store($key, $value){
 88         $_SESSION['NeevoCache'][$key] = $value;
 89     }
 90 
 91 
 92     public function flush(){
 93         return !$_SESSION['NeevoCache'] = array();
 94     }
 95 
 96 
 97 }
 98 
 99 
100 
101 /**
102  * File cache storage.
103  * @author Martin Srank
104  * @package Neevo\Cache
105  */
106 class NeevoCacheFile implements INeevoCache {
107 
108 
109     /** @var string */
110     private $filename;
111 
112     /** @var array */
113     private $data = array();
114 
115 
116     public function __construct($filename){
117         $this->filename = $filename;
118         $this->data = (array) unserialize(@file_get_contents($filename));
119     }
120 
121 
122     public function fetch($key){
123         return array_key_exists($key, $this->data) ? $this->data[$key] : null;
124     }
125 
126 
127     public function store($key, $value){
128         if(!array_key_exists($key, $this->data) || $this->data[$key] !== $value){
129             $this->data[$key] = $value;
130             @file_put_contents($this->filename, serialize($this->data), LOCK_EX);
131         }
132     }
133 
134 
135     public function flush(){
136         $this->data = array();
137         return @file_put_contents($this->filename, serialize($this->data), LOCK_EX);
138     }
139 
140 
141 }
142 
143 
144 
145 /**
146  * Memcache cache storage.
147  * @author Martin Srank
148  * @package Neevo\Cache
149  */
150 class NeevoCacheMemcache implements INeevoCache {
151 
152 
153     /** @var Memcache */
154     private $memcache;
155 
156     public function __construct(Memcache $memcache){
157         $this->memcache = $memcache;
158     }
159 
160 
161     public function fetch($key){
162         $value = $this->memcache->get("NeevoCache.$key");
163         return $value !== false ? $value : null;
164     }
165 
166 
167     public function store($key, $value){
168         $this->memcache->set("NeevoCache.$key", $value);
169     }
170 
171 
172     public function flush(){
173         return $this->memcache->flush();
174     }
175 
176 
177 }
178 
Neevo Public API API documentation generated by ApiGen 2.8.0