Guest User

Untitled

a guest
Jan 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. <?php
  2.  
  3. class Mixin
  4. {
  5. private $__map=array();
  6.  
  7. public function __call($method, $params)
  8. {
  9. if(!isset($this->__map[$method]))
  10. throw new BadMethodCallException("$method not defined");
  11.  
  12. return $this->__map[$method]->__invoke($params);
  13. }
  14.  
  15. public function __set($param, $value)
  16. {
  17. if(!is_a($value, 'MixinMethod'))
  18. $value = new MixinMethod($value);
  19.  
  20. $this->__map[$param] = $value;
  21. }
  22.  
  23. public static function decorate($object)
  24. {
  25.  
  26. }
  27. }
  28.  
  29. class MixinMethod
  30. {
  31. private $closure;
  32.  
  33. public function __construct($closure)
  34. {
  35. $this->closure = $closure;
  36. }
  37.  
  38. public function __invoke($params)
  39. {
  40. array_unshift($params, $this);
  41. return call_user_func_array($this->closure, $params);
  42. }
  43. }
  44.  
  45. $mixin = new Mixin();
  46. $mixin->blargh = function($self) {
  47. return 'llamas';
  48. };
  49.  
  50. $cached = Mixin::decorate($mixin);
  51. $cached->blargh = CachedMethod::build($cached->blargh)->expires('+2 days');
  52.  
  53. var_dump($mixin->blargh());
Add Comment
Please, Sign In to add comment