Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Cache / Pattern / ClassCache.php
blob32561e723c0148e026253edec9c65b160b33de63
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Cache\Pattern;
12 use Zend\Cache;
13 use Zend\Cache\Exception;
15 class ClassCache extends CallbackCache
17 /**
18 * Set options
20 * @param PatternOptions $options
21 * @return ClassCache
22 * @throws Exception\InvalidArgumentException if missing 'class' or 'storage' options
24 public function setOptions(PatternOptions $options)
26 parent::setOptions($options);
28 if (!$options->getClass()) {
29 throw new Exception\InvalidArgumentException("Missing option 'class'");
30 } elseif (!$options->getStorage()) {
31 throw new Exception\InvalidArgumentException("Missing option 'storage'");
33 return $this;
36 /**
37 * Call and cache a class method
39 * @param string $method Method name to call
40 * @param array $args Method arguments
41 * @return mixed
42 * @throws Exception\RuntimeException
43 * @throws \Exception
45 public function call($method, array $args = array())
47 $options = $this->getOptions();
48 $classname = $options->getClass();
49 $method = strtolower($method);
50 $callback = $classname . '::' . $method;
52 $cache = $options->getCacheByDefault();
53 if ($cache) {
54 $cache = !in_array($method, $options->getClassNonCacheMethods());
55 } else {
56 $cache = in_array($method, $options->getClassCacheMethods());
59 if (!$cache) {
60 if ($args) {
61 return call_user_func_array($callback, $args);
62 } else {
63 return $classname::$method();
67 return parent::call($callback, $args);
70 /**
71 * Generate a unique key in base of a key representing the callback part
72 * and a key representing the arguments part.
74 * @param string $method The method
75 * @param array $args Callback arguments
76 * @return string
77 * @throws Exception\RuntimeException
79 public function generateKey($method, array $args = array())
81 return $this->generateCallbackKey(
82 $this->getOptions()->getClass() . '::' . $method,
83 $args
87 /**
88 * Generate a unique key in base of a key representing the callback part
89 * and a key representing the arguments part.
91 * @param callable $callback A valid callback
92 * @param array $args Callback arguments
93 * @return string
94 * @throws Exception\RuntimeException
96 protected function generateCallbackKey($callback, array $args)
98 $callbackKey = md5(strtolower($callback));
99 $argumentKey = $this->generateArgumentsKey($args);
100 return $callbackKey . $argumentKey;
104 * Calling a method of the entity.
106 * @param string $method Method name to call
107 * @param array $args Method arguments
108 * @return mixed
109 * @throws Exception\RuntimeException
110 * @throws \Exception
112 public function __call($method, array $args)
114 return $this->call($method, $args);
118 * Set a static property
120 * @param string $name
121 * @param mixed $value
122 * @return void
123 * @see http://php.net/manual/language.oop5.overloading.php#language.oop5.overloading.members
125 public function __set($name, $value)
127 $class = $this->getOptions()->getClass();
128 $class::$name = $value;
132 * Get a static property
134 * @param string $name
135 * @return mixed
136 * @see http://php.net/manual/language.oop5.overloading.php#language.oop5.overloading.members
138 public function __get($name)
140 $class = $this->getOptions()->getClass();
141 return $class::$name;
145 * Is a static property exists.
147 * @param string $name
148 * @return bool
150 public function __isset($name)
152 $class = $this->getOptions()->getClass();
153 return isset($class::$name);
157 * Unset a static property
159 * @param string $name
160 * @return void
162 public function __unset($name)
164 $class = $this->getOptions()->getClass();
165 unset($class::$name);