Created
January 12, 2012 03:06
-
-
Save jmg/1598318 to your computer and use it in GitHub Desktop.
Proxy Dispatcher using php call_user_func_array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Proxy Dispatcher using php call_user_func_array (http://us2.php.net/manual/en/function.call-user-func-array.php) | |
* */ | |
class Foo { | |
function bar1($arg, $arg2, $arg3, $arg4) { | |
return "arg: $arg, arg2: $arg2, arg3: $arg3, arg4: $arg4\n"; | |
} | |
function bar2($arg, $arg2) { | |
return "arg: $arg, arg2: $arg2\n"; | |
} | |
function bar3($arg) { | |
return "arg: $arg\n"; | |
} | |
} | |
class FooWrapper { | |
public function __construct() { | |
$this->_foo = new Foo(); | |
} | |
public function __call($method, $arguments) { | |
return call_user_func_array(array($this->_foo, $method), $arguments); | |
} | |
} | |
$fooWrapper = new FooWrapper(); | |
echo $fooWrapper->bar1(1,2,3,4); | |
echo $fooWrapper->bar2(1,2); | |
echo $fooWrapper->bar3(1); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment