stimulus.class.inc.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. // #@# Really dirty !!!
  14. // #@# TO BE CLEANED -> ALIGN WITH OTHER METAMODEL DECLARATIONS
  15. class ObjectStimulus
  16. {
  17. private $m_aParams = array();
  18. private $m_sHostClass = null;
  19. private $m_sCode = null;
  20. public function __construct($sCode, $aParams)
  21. {
  22. $this->m_sCode = $sCode;
  23. $this->m_aParams = $aParams;
  24. $this->ConsistencyCheck();
  25. }
  26. public function SetHostClass($sHostClass)
  27. {
  28. $this->m_sHostClass = $sHostClass;
  29. }
  30. public function GetHostClass()
  31. {
  32. return $this->m_sHostClass;
  33. }
  34. public function GetCode()
  35. {
  36. return $this->m_sCode;
  37. }
  38. public function GetLabel()
  39. {
  40. return Dict::S('Class:'.$this->m_sHostClass.'/Stimulus:'.$this->m_sCode, $this->m_sCode);
  41. }
  42. public function GetDescription()
  43. {
  44. return Dict::S('Class:'.$this->m_sHostClass.'/Stimulus:'.$this->m_sCode.'+', '');
  45. }
  46. // obsolete- public function Get($sParamName) {return $this->m_aParams[$sParamName];}
  47. // Note: I could factorize this code with the parameter management made for the AttributeDef class
  48. // to be overloaded
  49. static protected function ListExpectedParams()
  50. {
  51. return array();
  52. }
  53. private function ConsistencyCheck()
  54. {
  55. // Check that any mandatory param has been specified
  56. //
  57. $aExpectedParams = $this->ListExpectedParams();
  58. foreach($aExpectedParams as $sParamName)
  59. {
  60. if (!array_key_exists($sParamName, $this->m_aParams))
  61. {
  62. $aBacktrace = debug_backtrace();
  63. $sTargetClass = $aBacktrace[2]["class"];
  64. $sCodeInfo = $aBacktrace[1]["file"]." - ".$aBacktrace[1]["line"];
  65. throw new CoreException("missing parameter '$sParamName' in ".get_class($this)." declaration for class $sTargetClass ($sCodeInfo)");
  66. }
  67. }
  68. }
  69. }
  70. class StimulusUserAction extends ObjectStimulus
  71. {
  72. }
  73. ?>