C_Component

Pope is a component-based framework.

Defined (1)

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

/pope/lib/class.component.php  
  1. class C_Component extends ExtensibleObject 
  2. /** 
  3. * @var string 
  4. */ 
  5. var $context; 
  6. var $adapted = FALSE; 
  7.  
  8. /** 
  9. * Many components will execute parent::define() 
  10. */ 
  11. function define($context=FALSE) 
  12. $this->context = is_null($context) ? FALSE : $context; 
  13. $this->implement('I_Component'); 
  14.  
  15. // Initializes the state of the object 
  16. function initialize() 
  17. $this->get_registry()->apply_adapters($this); 
  18. $this->adapted = TRUE; 
  19. register_shutdown_function(array(&$this, 'update_cache')); 
  20. $this->_method_map_cache = (array)C_Pope_Cache::get( 
  21. array($this->context, $this->_mixin_priorities, $this->_disabled_map),  
  22. $this->_method_map_cache 
  23. ); 
  24.  
  25. // Updates the cache for this component 
  26. function update_cache() 
  27. C_Pope_Cache::set(array($this->context, $this->_mixin_priorities, $this->_disabled_map), $this->_method_map_cache); 
  28.  
  29. /** 
  30. * Determines if the component has one or more particular contexts assigned 
  31. * @param string|array $context 
  32. * @return boolean 
  33. */ 
  34. function has_context($context) 
  35. $retval = TRUE; 
  36. $current_context = is_array($this->context) ? $this->context : array($this->context); 
  37. if (!is_array($context)) $context = array($context); 
  38. foreach ($context as $c) { 
  39. if (!in_array($c, $current_context)) { 
  40. $retval = FALSE; 
  41. break; 
  42. return $retval; 
  43.  
  44. /** 
  45. * Assigns a particular context to the component 
  46. * @param type $context 
  47. */ 
  48. function add_context($context) 
  49. if (!is_array($context)) $context = array($context); 
  50. if (!is_array($this->context)) $this->context = array($this->context); 
  51. foreach ($context as $c) { 
  52. if (in_array($c, $this->context)) continue; 
  53. else $context[] = $c; 
  54.  
  55. /** 
  56. * Assigns one or more contexts to the component 
  57. * @param type $context 
  58. */ 
  59. function assign_context($context) 
  60. $this->add_context($context); 
  61.  
  62. /** 
  63. * Un-assigns one or more contexts from the component 
  64. * @param type $context 
  65. */ 
  66. function remove_context($context) 
  67. if (!is_array($context)) $context = array($context); 
  68. if (!is_array($this->context)) $this->context = array($this->context); 
  69. foreach ($context as $c) { 
  70. if (($index = array_search($c, $this->context)) !== FALSE) { 
  71. unset($this->context[$index]); 
  72.  
  73. /** 
  74. * Assigns one or more contexts to the component 
  75. * @param type $context 
  76. */ 
  77. function unassign_context($context) 
  78. $this->remove_context($context); 
  79.  
  80. /** 
  81. * Gets the component registry 
  82. * @return C_Component_Registry 
  83. */ 
  84. function get_registry() 
  85. return C_Component_Registry::get_instance(); 
  86.  
  87. /** 
  88. * Gets the component registry -- backward compatibility 
  89. * @return C_Component_Registry 
  90. */ 
  91. function _get_registry() 
  92. return C_Component_Registry::get_instance();