| 6 | | class HermitProxy { |
| 7 | | protected $target; |
| 8 | | protected $pdo; |
| 9 | | protected function __construct(ReflectionClass $reflector, $targetClass, PDO $pdo = null){ |
| 10 | | $this->target = $targetClass; |
| 11 | | $this->reflector = $reflector; |
| 12 | | $this->pdo = $pdo; |
| 13 | | } |
| 14 | | public static function delegateInstance(PDO $pdo, $instance){ |
| 15 | | return new self(new ReflectionObject($reflector), $instance, $pdo); |
| 16 | | } |
| 17 | | public function __call($name, $params = array()){ |
| 18 | | $annote = HermitAnnote::create($this->reflector); |
| 19 | | if($annote->hasMethod($name, true)){ |
| 20 | | $method = $annote->getMethod($name); |
| 21 | | return $method->invokeArgs($this->target, $params); |
| 22 | | } |
| 23 | | switch(true){ |
| 24 | | case $annote->hasSql($name): |
| 25 | | break; |
| 26 | | case $annote->hasQuery($name): |
| 27 | | break; |
| 28 | | case $annote->hasFile($name): |
| 29 | | break; |
| 30 | | case $annote->hasPath($name): |
| 31 | | break; |
| 32 | | case $annote->hasDelegate($name): |
| 33 | | break; |
| 34 | | } |
| 35 | | throw new BadMethodCallException(get_class($this->target) . '::' . $name); |
| 36 | | } |
| | 6 | interface HermitProxy extends HermitDao { |
| | 7 | public static function delegate(PDO $pdo, ReflectionClass $reflector, $instance = null); |