1: <?php
2: /**
3: * Pinoco: makes existing static web site dynamic transparently.
4: * Copyright 2010-2012, Hisateru Tanaka <tanakahisateru@gmail.com>
5: *
6: * Licensed under The MIT License
7: * Redistributions of files must retain the above copyright notice.
8: *
9: * PHP Version 5
10: *
11: * @author Hisateru Tanaka <tanakahisateru@gmail.com>
12: * @copyright Copyright 2010-2012, Hisateru Tanaka <tanakahisateru@gmail.com>
13: * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
14: * @package Pinoco
15: */
16:
17: /**
18: * Delegate class base
19: *
20: * @package Pinoco
21: * @abstract
22: */
23: class Pinoco_Delegate
24: {
25: protected $__delegatee__;
26:
27: /**
28: * Creates an object with delegation target. This method
29: * should be called in constructor in inherited class.
30: * <code>
31: * public function __construct(..., $delegatee, ...)
32: * {
33: * parent::__construct($delegatee);
34: * }
35: * </code>
36: *
37: * @param object $delegatee;
38: */
39: public function __construct($delegatee=null)
40: {
41: if (is_null($delegatee)) {
42: $delegatee = Pinoco::instance();
43: }
44: $this->__delegatee__ = $delegatee;
45: }
46:
47: public function __get($name)
48: {
49: return $this->__delegatee__->$name;
50: }
51:
52: public function __set($name, $value)
53: {
54: $this->__delegatee__->$name = $value;
55: }
56:
57: public function __isset($name)
58: {
59: return isset($this->__delegatee__->$name);
60: }
61:
62: public function __call($name, $args)
63: {
64: return call_user_func_array(array($this->__delegatee__, $name), $args);
65: }
66: }
67:
68: