stimulus.class.inc.php 2.2 KB

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