CApplicationComponent.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * This file contains the base application component class.
  4. *
  5. * @author Qiang Xue <qiang.xue@gmail.com>
  6. * @link http://www.yiiframework.com/
  7. * @copyright 2008-2013 Yii Software LLC
  8. * @license http://www.yiiframework.com/license/
  9. */
  10. /**
  11. * CApplicationComponent is the base class for application component classes.
  12. *
  13. * CApplicationComponent implements the basic methods required by {@link IApplicationComponent}.
  14. *
  15. * When developing an application component, try to put application component initialization code in
  16. * the {@link init()} method instead of the constructor. This has the advantage that
  17. * the application component can be customized through application configuration.
  18. *
  19. * @property boolean $isInitialized Whether this application component has been initialized (ie, {@link init()} is invoked).
  20. *
  21. * @author Qiang Xue <qiang.xue@gmail.com>
  22. * @package system.base
  23. * @since 1.0
  24. */
  25. abstract class CApplicationComponent extends CComponent implements IApplicationComponent
  26. {
  27. /**
  28. * @var array the behaviors that should be attached to this component.
  29. * The behaviors will be attached to the component when {@link init} is called.
  30. * Please refer to {@link CModel::behaviors} on how to specify the value of this property.
  31. */
  32. public $behaviors=array();
  33. private $_initialized=false;
  34. /**
  35. * Initializes the application component.
  36. * This method is required by {@link IApplicationComponent} and is invoked by application.
  37. * If you override this method, make sure to call the parent implementation
  38. * so that the application component can be marked as initialized.
  39. */
  40. public function init()
  41. {
  42. $this->attachBehaviors($this->behaviors);
  43. $this->_initialized=true;
  44. }
  45. /**
  46. * Checks if this application component has been initialized.
  47. * @return boolean whether this application component has been initialized (ie, {@link init()} is invoked).
  48. */
  49. public function getIsInitialized()
  50. {
  51. return $this->_initialized;
  52. }
  53. }