1 : <?php
2 :
3 : /**
4 : * Helper class to wrap an object with a modified interface created by
5 : * a partial application of its existing methods.
6 : *
7 : * @category Services
8 : * @package Services_Twilio
9 : * @author Neuman Vong <neuman@twilio.com>
10 : * @license http://creativecommons.org/licenses/MIT/ MIT
11 : * @link http://pear.php.net/package/Services_Twilio
12 : */
13 : class Services_Twilio_PartialApplicationHelper
14 : {
15 : private $callbacks;
16 :
17 : public function __construct()
18 : {
19 1 : $this->callbacks = array();
20 1 : }
21 :
22 : public function set($method, $callback, array $args)
23 : {
24 1 : if (!is_callable($callback)) {
25 0 : return FALSE;
26 : }
27 1 : $this->callbacks[$method] = array($callback, $args);
28 1 : }
29 :
30 : public function __call($method, $args)
31 : {
32 1 : if (!isset($this->callbacks[$method])) {
33 0 : throw new Exception("Method not found: $method");
34 : }
35 1 : list($callback, $cb_args) = $this->callbacks[$method];
36 1 : return call_user_func_array(
37 1 : $callback,
38 1 : array_merge($cb_args, $args)
39 1 : );
40 : }
41 : }
|