Hoa central
Prototype.php
Go to the documentation of this file.
1 <?php
2 
37 namespace {
38 
39 from('Hoa')
40 
41 
44 -> import('Prototype.Exception');
45 
46 }
47 
48 namespace Hoa\Prototype {
49 
60 class Prototype {
61 
65  //public $prototype = null;
66 
72  private $_prototype = null;
73 
79  protected $_classType = '';
80 
86  protected $_objectType = '';
87 
88 
89 
100  public function __set ( $name, $value ) {
101 
102  if(true === property_exists($this, 'prototype'))
103  throw new Exception(
104  'You must not have a prototype attribute declared in your ' .
105  'class.', 0);
106 
107  if(strtolower($name) == 'prototype') {
108 
109  $out = is_object($value);
110 
111  if($out && $this->_objectType != '')
112  $out = $value instanceof $this->_objectType;
113 
114  if($out && $this->_classType != '')
115  $out &= strtolower(get_class($value))
116  == strtolower($this->_classType);
117 
118  if(false === (bool) $out)
119  throw new Exception(
120  'Cannot set the prototype %s; it must be an object of ' .
121  'type %s and a class of type %s.',
122  1, array(
123  get_class($value),
124  $this->_objectType,
125  $this->_classType
126  ));
127 
128  return $this->_prototype = $value;
129  }
130 
131  if(null === $this->_prototype)
132  throw new Exception(
133  'Undefined property: %s::%s.',
134  2, array(get_class($this), $name));
135 
136  return $this->_prototype->$name = $value;
137  }
138 
147  public function __get ( $name ) {
148 
149  if(true === property_exists($this, 'prototype'))
150  throw new Exception(
151  'You must not have a prototype attribute declared in your ' .
152  'class.', 3);
153 
154  if(null === $this->_prototype)
155  throw new Exception(
156  'Undefined property: %s::%s.',
157  4, array(get_class($this), $name));
158 
159  if(true === property_exists($this->_prototype, $name))
160  return $this->_prototype->$name;
161 
162  if($this->_prototype instanceof Prototype)
163  return $this->_prototype->__get($name);
164 
165  throw new Exception(
166  'Undefined property: %s::%s.',
167  5, array(get_class($this), $name));
168  }
169 
182  public function __call ( $name, Array $arguments ) {
183 
184  if(null === $this->_prototype)
185  throw new Exception(
186  'Call to undefined property: %s::%s().',
187  6, array(get_class($this), $name));
188 
189  $callback = array($this->_prototype, $name);
190 
191  if(is_callable($callback))
192  return call_user_func_array($callback, $arguments);
193 
194  if($this->_prototype instanceof Prototype)
195  return $this->_prototype->__call($name, $arguments);
196 
197  throw new Exception(
198  'Call to uncallable method %s::%s().', 7,
199  array(get_class($this), $name));
200  }
201 
209  protected function setPrototypeClassType ( $type ) {
210 
211  $old = $this->_classType;
212  $this->_classType = $type;
213 
214  return $old;
215  }
216 
224  protected function setPrototypeObjectType ( $type ) {
225 
226  $old = $this->_objectType;
227  $this->_objectType = $type;
228 
229  return $old;
230  }
231 
238  protected function disablePrototypeClassType ( ) {
239 
240  return $this->setPrototypeClassType(null);
241  }
242 
249  protected function disablePrototypeObjectType ( ) {
250 
251  return $this->setPrototypeObjectType(null);
252  }
253 }
254 
255 }
256 
257 namespace {
258 
262 Hoa\Core\Consistency::flexEntity('Hoa\Prototype\Prototype');
263 
264 }
__set($name, $value)
Definition: Prototype.php:100
__call($name, Array $arguments)
Definition: Prototype.php:182