/var/www/hkosl.com/b2b2c/webadmin/libraies/twilio/sdk/Services/Twilio/PartialApplicationHelper.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php

/**
 * Helper class to wrap an object with a modified interface created by
 * a partial application of its existing methods.
 *
 * @category Services
 * @package  Services_Twilio
 * @author   Neuman Vong <neuman@twilio.com>
 * @license  http://creativecommons.org/licenses/MIT/ MIT
 * @link     http://pear.php.net/package/Services_Twilio
 */ 
class Services_Twilio_PartialApplicationHelper
{
    private 
$callbacks;

    public function 
__construct()
    {
        
$this->callbacks = array();
    }

    public function 
set($method$callback, array $args)
    {
        if (!
is_callable($callback)) {
            return 
FALSE;
        }
        
$this->callbacks[$method] = array($callback$args);
    }

    public function 
__call($method$args)
    {
        if (!isset(
$this->callbacks[$method])) {
            throw new 
Exception("Method not found: $method");
        }
        list(
$callback$cb_args) = $this->callbacks[$method];
        return 
call_user_func_array(
            
$callback,
            
array_merge($cb_args$args)
        );
    }
}