stimulus.class.inc.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * A stimulus is the trigger that makes the lifecycle go ahead (state machine)
  4. *
  5. * @package iTopORM
  6. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  7. * @author Denis Flaven <denisflave@free.fr>
  8. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  9. * @link www.itop.com
  10. * @since 1.0
  11. * @version 1.1.1.1 $
  12. */
  13. class ObjectStimulus
  14. {
  15. private $m_aParams = array();
  16. public function __construct($aParams)
  17. {
  18. $this->m_aParams = $aParams;
  19. $this->ConsistencyCheck();
  20. }
  21. public function Get($sParamName) {return $this->m_aParams[$sParamName];}
  22. // Note: I could factorize this code with the parameter management made for the AttributeDef class
  23. // to be overloaded
  24. static protected function ListExpectedParams()
  25. {
  26. return array("label", "description");
  27. }
  28. private function ConsistencyCheck()
  29. {
  30. // Check that any mandatory param has been specified
  31. //
  32. $aExpectedParams = $this->ListExpectedParams();
  33. foreach($aExpectedParams as $sParamName)
  34. {
  35. if (!array_key_exists($sParamName, $this->m_aParams))
  36. {
  37. $aBacktrace = debug_backtrace();
  38. $sTargetClass = $aBacktrace[2]["class"];
  39. $sCodeInfo = $aBacktrace[1]["file"]." - ".$aBacktrace[1]["line"];
  40. throw new CoreException("missing parameter '$sParamName' in ".get_class($this)." declaration for class $sTargetClass ($sCodeInfo)");
  41. }
  42. }
  43. }
  44. }
  45. class StimulusUserAction extends ObjectStimulus
  46. {
  47. }
  48. ?>