Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Mixin
- {
- private $__map=array();
- public function __call($method, $params)
- {
- if(!isset($this->__map[$method]))
- throw new BadMethodCallException("$method not defined");
- return $this->__map[$method]->__invoke($params);
- }
- public function __set($param, $value)
- {
- if(!is_a($value, 'MixinMethod'))
- $value = new MixinMethod($value);
- $this->__map[$param] = $value;
- }
- public static function decorate($object)
- {
- }
- }
- class MixinMethod
- {
- private $closure;
- public function __construct($closure)
- {
- $this->closure = $closure;
- }
- public function __invoke($params)
- {
- array_unshift($params, $this);
- return call_user_func_array($this->closure, $params);
- }
- }
- $mixin = new Mixin();
- $mixin->blargh = function($self) {
- return 'llamas';
- };
- $cached = Mixin::decorate($mixin);
- $cached->blargh = CachedMethod::build($cached->blargh)->expires('+2 days');
- var_dump($mixin->blargh());
Add Comment
Please, Sign In to add comment