Mixin

An mixin provides methods for an ExtensibleObject to use.

Defined (1)

The class is defined in the following location(s).

/pope/lib/class.extensibleobject.php  
  1. class Mixin extends PopeHelpers 
  2. /** 
  3. * The ExtensibleObject which called the extension's method 
  4. * @var ExtensibleObject 
  5. */ 
  6. var $object; 
  7.  
  8. /** 
  9. * The name of the method called on the ExtensibleObject 
  10. * @var type 
  11. */ 
  12. var $method_called; 
  13.  
  14. /** 
  15. * There really isn't any concept of 'parent' method. An ExtensibleObject 
  16. * instance contains an ordered array of extension classes, which provides 
  17. * the method implementations for the instance to use. Suppose that an 
  18. * ExtensibleObject has two extension, and both have the same methods.The 
  19. * last extension appears to 'override' the first extension. So, instead of calling 
  20. * a 'parent' method, we're actually just calling an extension that was added sooner than 
  21. * the one that is providing the current method implementation. 
  22. */ 
  23. function call_parent($method) 
  24. $retval = NULL; 
  25.  
  26. // To simulate a 'parent' call, we remove the current mixin providing the 
  27. // implementation. 
  28. $klass = $this->object->get_mixin_providing($method); 
  29.  
  30. // Perform the routine described above... 
  31. $this->object->disable_mixin_for($method, $klass); 
  32.  
  33. // Get the method map cache 
  34. $orig_method_map = $this->object->_method_map_cache; 
  35. $this->object->_method_map_cache = (array)C_Pope_Cache::get( 
  36. array($this->object->context, $this->object->_mixin_priorities, $this->object->_disabled_map),  
  37. $this->object->_method_map_cache 
  38. ); 
  39.  
  40. // Call anchor 
  41. $args = func_get_args(); 
  42.  
  43. // Remove $method parameter 
  44. array_shift($args); 
  45.  
  46. // Execute the method 
  47. $retval = $this->object->call_method($method, $args); 
  48.  
  49. // Cache the method map for this configuration of mixins 
  50. C_Pope_Cache::set( 
  51. array($this->object->context, $this->object->_mixin_priorities, $this->object->_disabled_map),  
  52. $this->object->_method_map_cache 
  53. ); 
  54.  
  55. // Re-enable mixins; 
  56. // $this->object->add_mixin($klass); 
  57. $this->object->enable_mixin_for($method, $klass); 
  58.  
  59. // Restore the original method map 
  60. $this->object->_method_map_cache = $orig_method_map; 
  61.  
  62. return $retval; 
  63.  
  64. /** 
  65. * Although is is preferrable to call $this->object->method(), sometimes 
  66. * it's nice to use $this->method() instead. 
  67. * @param string $method 
  68. * @param array $args 
  69. * @return mixed 
  70. */ 
  71. function __call($method, $args) 
  72. if ($this->object->has_method($method)) { 
  73. return call_user_func_array(array(&$this->object, $method), $args); 
  74.  
  75. /** 
  76. * Although extensions can have state, it's probably more desirable to maintain 
  77. * the state in the parent object to keep a sane environment 
  78. * @param string $property 
  79. * @return mixed 
  80. */ 
  81. function __get($property) 
  82. return $this->object->$property;