comparison cake/libs/overloadable_php4.php @ 0:261e66bd5a0c

hg init
author Shoshi TAMAKI <shoshi@cr.ie.u-ryukyu.ac.jp>
date Sun, 24 Jul 2011 21:08:31 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:261e66bd5a0c
1 <?php
2 /**
3 * Overload abstraction interface. Merges differences between PHP4 and 5.
4 *
5 * PHP versions 4 and 5
6 *
7 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
8 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
9 *
10 * Licensed under The MIT License
11 * Redistributions of files must retain the above copyright notice.
12 *
13 * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
14 * @link http://cakephp.org CakePHP(tm) Project
15 * @package cake
16 * @subpackage cake.cake.libs
17 * @since CakePHP(tm) v 1.2
18 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
19 */
20
21 /**
22 * Overloadable class selector
23 *
24 * Load the interface class based on the version of PHP.
25 *
26 * @package cake
27 * @subpackage cake.cake.libs
28 */
29 class Overloadable extends Object {
30
31 /**
32 * Constructor.
33 *
34 * @access private
35 */
36 function __construct() {
37 $this->overload();
38 parent::__construct();
39 }
40
41 /**
42 * Overload implementation.
43 *
44 * @access public
45 */
46 function overload() {
47 if (function_exists('overload')) {
48 if (func_num_args() > 0) {
49 foreach (func_get_args() as $class) {
50 if (is_object($class)) {
51 overload(get_class($class));
52 } elseif (is_string($class)) {
53 overload($class);
54 }
55 }
56 } else {
57 overload(get_class($this));
58 }
59 }
60 }
61
62 /**
63 * Magic method handler.
64 *
65 * @param string $method Method name
66 * @param array $params Parameters to send to method
67 * @param mixed $return Where to store return value from method
68 * @return boolean Success
69 * @access private
70 */
71 function __call($method, $params, &$return) {
72 if (!method_exists($this, 'call__')) {
73 trigger_error(sprintf(__('Magic method handler call__ not defined in %s', true), get_class($this)), E_USER_ERROR);
74 }
75 $return = $this->call__($method, $params);
76 return true;
77 }
78 }
79 Overloadable::overload('Overloadable');
80
81 /**
82 * Overloadable2 class selector
83 *
84 * Load the interface class based on the version of PHP.
85 *
86 * @package cake
87 * @subpackage cake.cake.libs
88 */
89 class Overloadable2 extends Object {
90
91 /**
92 * Constructor
93 *
94 * @access private
95 */
96 function __construct() {
97 $this->overload();
98 parent::__construct();
99 }
100
101 /**
102 * Overload implementation.
103 *
104 * @access public
105 */
106 function overload() {
107 if (function_exists('overload')) {
108 if (func_num_args() > 0) {
109 foreach (func_get_args() as $class) {
110 if (is_object($class)) {
111 overload(get_class($class));
112 } elseif (is_string($class)) {
113 overload($class);
114 }
115 }
116 } else {
117 overload(get_class($this));
118 }
119 }
120 }
121
122 /**
123 * Magic method handler.
124 *
125 * @param string $method Method name
126 * @param array $params Parameters to send to method
127 * @param mixed $return Where to store return value from method
128 * @return boolean Success
129 * @access private
130 */
131 function __call($method, $params, &$return) {
132 if (!method_exists($this, 'call__')) {
133 trigger_error(sprintf(__('Magic method handler call__ not defined in %s', true), get_class($this)), E_USER_ERROR);
134 }
135 $return = $this->call__($method, $params);
136 return true;
137 }
138
139 /**
140 * Getter.
141 *
142 * @param mixed $name What to get
143 * @param mixed $value Where to store returned value
144 * @return boolean Success
145 * @access private
146 */
147 function __get($name, &$value) {
148 $value = $this->get__($name);
149 return true;
150 }
151
152 /**
153 * Setter.
154 *
155 * @param mixed $name What to set
156 * @param mixed $value Value to set
157 * @return boolean Success
158 * @access private
159 */
160 function __set($name, $value) {
161 $this->set__($name, $value);
162 return true;
163 }
164 }
165 Overloadable::overload('Overloadable2');