Hoa central
Public Member Functions | Protected Attributes | List of all members
Hoa\Cache\Frontend\AClass Class Reference
Inheritance diagram for Hoa\Cache\Frontend\AClass:

Public Member Functions

 __construct ()
 
 __call ($method, Array $arguments)
 
 setCacheObject ($object=null)
 
- Public Member Functions inherited from Hoa\Cache\Frontend\Frontend
 __construct (Cache\Backend $backend)
 
 cleanCache ($lifetime=Cache::CLEAN_EXPIRED)
 
 getBackend ()
 
- Public Member Functions inherited from Hoa\Cache\Cache
 __construct (Array $parameters=[])
 
 getParameters ()
 
 ksort (Array &$array)
 

Protected Attributes

 $_object = null
 
 $_arguments = []
 
- Protected Attributes inherited from Hoa\Cache\Frontend\Frontend
 $_backend = null
 

Additional Inherited Members

- Public Attributes inherited from Hoa\Cache\Cache
const CLEAN_ALL = -1
 
const CLEAN_EXPIRED = 0
 
const CLEAN_USER = 1
 
- Protected Member Functions inherited from Hoa\Cache\Cache
 makeId ($id=null)
 
 setId ($id)
 
 getId ()
 
 getIdMd5 ()
 
 removeId ()
 
- Static Protected Attributes inherited from Hoa\Cache\Cache
static $_id = []
 

Detailed Description

Class .

Class catching system for frontend cache.

Definition at line 49 of file AClass.php.

Constructor & Destructor Documentation

Hoa\Cache\Frontend\AClass::__construct ( )

Redirect constructor call to __call method if necessary. Else, it's like the parent constructor.

Returns
mixed

Definition at line 73 of file AClass.php.

74  {
75  $arguments = func_get_args();
76 
77  if (null === $this->_object) {
78  if (isset($arguments[1])) {
79  return parent::__construct($arguments[0], $arguments[1]);
80  } else {
81  return parent::__construct($arguments[0]);
82  }
83  }
84 
85  return $this->__call('__construct', $arguments);
86  }
__call($method, Array $arguments)
Definition: AClass.php:98

Here is the call graph for this function:

Member Function Documentation

Hoa\Cache\Frontend\AClass::__call (   $method,
Array  $arguments 
)

Overload member class with __call. When we call method on this object, all should be redirected to set object.

Parameters
string$methodMethod called.
array$argumentsArguments of method.
Returns
mixed
Exceptions

Definition at line 98 of file AClass.php.

99  {
100  $gc =
101  is_string($this->_object)
102  ? $this->_object
103  : get_class($this->_object);
104 
105  if (!method_exists($this->_object, $method)) {
106  throw new Cache\Exception(
107  'Method %s of %s object does not exists.',
108  0,
109  [$method, $gc]
110  );
111  }
112 
113  $this->_arguments = $this->ksort($arguments);
114  $idExtra = serialize($this->_arguments);
115  $this->makeId($gc . '::' . $method . '/' . $idExtra);
116  $content = $this->_backend->load();
117 
118  if (false !== $content) {
119  echo $content[0]; // output
120 
121  return $content[1]; // return
122  }
123 
124  ob_start();
125  ob_implicit_flush(false);
126 
127  if (is_string($this->_object) && $method == '__construct') {
128  $reflection = new \ReflectionClass($this->_object);
129 
130  if (!$reflection->isInstantiable()) {
131  throw new Cache\Exception(
132  'Class %s is not instanciable.',
133  1,
134  $this->_object
135  );
136  }
137 
138  $this->_object = $reflection->newInstanceArgs($arguments);
139  $return = $this->_object;
140  } else {
141  $return = call_user_func_array(
142  [$this->_object, $method],
143  $arguments
144  );
145  }
146 
147  $output = ob_get_contents();
148  ob_end_clean();
149 
150  $this->_backend->store([$output, $return]);
151  $this->removeId();
152 
153  echo $output;
154 
155  return $return;
156  }
ksort(Array &$array)
Definition: Cache.php:258
$content
Definition: Hoa.php:119
makeId($id=null)
Definition: Cache.php:162

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Cache\Frontend\AClass::setCacheObject (   $object = null)

Set object to call.

Parameters
mixed$objectCould be an instance or a string for static call.
Returns
ojbect
Exceptions

Definition at line 165 of file AClass.php.

166  {
167  if (is_string($object) || is_object($object)) {
168  $this->_object = $object;
169 
170  return $this;
171  }
172 
173  throw new Cache\Exception(
174  '%s could be a string or a object.',
175  2,
176  $object
177  );
178  }

Member Data Documentation

Hoa\Cache\Frontend\AClass::$_arguments = []
protected

Definition at line 63 of file AClass.php.

Hoa\Cache\Frontend\AClass::$_object = null
protected

Definition at line 56 of file AClass.php.


The documentation for this class was generated from the following file: