1 | <?php |
||
11 | trait CustomMethods { |
||
12 | |||
13 | /** |
||
14 | * Custom method sources |
||
15 | * |
||
16 | * @var array |
||
17 | */ |
||
18 | protected static $extra_methods = array(); |
||
19 | |||
20 | /** |
||
21 | * Name of methods to invoke by defineMethods for this instance |
||
22 | * |
||
23 | * @var array |
||
24 | */ |
||
25 | protected $extra_method_registers = array(); |
||
26 | |||
27 | /** |
||
28 | * Non-custom methods |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | protected static $built_in_methods = array(); |
||
33 | |||
34 | /** |
||
35 | * Attempts to locate and call a method dynamically added to a class at runtime if a default cannot be located |
||
36 | * |
||
37 | * You can add extra methods to a class using {@link Extensions}, {@link Object::createMethod()} or |
||
38 | * {@link Object::addWrapperMethod()} |
||
39 | * |
||
40 | * @param string $method |
||
41 | * @param array $arguments |
||
42 | * @return mixed |
||
43 | * @throws BadMethodCallException |
||
44 | */ |
||
45 | public function __call($method, $arguments) { |
||
101 | |||
102 | /** |
||
103 | * Adds any methods from {@link Extension} instances attached to this object. |
||
104 | * All these methods can then be called directly on the instance (transparently |
||
105 | * mapped through {@link __call()}), or called explicitly through {@link extend()}. |
||
106 | * |
||
107 | * @uses addMethodsFrom() |
||
108 | */ |
||
109 | protected function defineMethods() { |
||
117 | |||
118 | /** |
||
119 | * Register an callback to invoke that defines extra methods |
||
120 | * |
||
121 | * @param string $name |
||
122 | * @param callable $callback |
||
123 | */ |
||
124 | protected function registerExtraMethodCallback($name, $callback) { |
||
129 | |||
130 | // -------------------------------------------------------------------------------------------------------------- |
||
131 | |||
132 | /** |
||
133 | * Return TRUE if a method exists on this object |
||
134 | * |
||
135 | * This should be used rather than PHP's inbuild method_exists() as it takes into account methods added via |
||
136 | * extensions |
||
137 | * |
||
138 | * @param string $method |
||
139 | * @return bool |
||
140 | */ |
||
141 | public function hasMethod($method) { |
||
145 | |||
146 | /** |
||
147 | * Return the names of all the methods available on this object |
||
148 | * |
||
149 | * @param bool $custom include methods added dynamically at runtime |
||
150 | * @return array |
||
151 | */ |
||
152 | public function allMethodNames($custom = false) { |
||
164 | |||
165 | |||
166 | |||
167 | /** |
||
168 | * Add all the methods from an object property (which is an {@link Extension}) to this object. |
||
169 | * |
||
170 | * @param string $property the property name |
||
171 | * @param string|int $index an index to use if the property is an array |
||
172 | * @throws InvalidArgumentException |
||
173 | */ |
||
174 | protected function addMethodsFrom($property, $index = null) { |
||
217 | |||
218 | /** |
||
219 | * Add a wrapper method - a method which points to another method with a different name. For example, Thumbnail(x) |
||
220 | * can be wrapped to generateThumbnail(x) |
||
221 | * |
||
222 | * @param string $method the method name to wrap |
||
223 | * @param string $wrap the method name to wrap to |
||
224 | */ |
||
225 | protected function addWrapperMethod($method, $wrap) { |
||
232 | |||
233 | /** |
||
234 | * Add an extra method using raw PHP code passed as a string |
||
235 | * |
||
236 | * @param string $method the method name |
||
237 | * @param string $code the PHP code - arguments will be in an array called $args, while you can access this object |
||
238 | * by using $obj. Note that you cannot call protected methods, as the method is actually an external |
||
239 | * function |
||
240 | */ |
||
241 | protected function createMethod($method, $code) { |
||
247 | } |
||
248 |
As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.