AModule.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace Tools;
  3. /**
  4. * Module superclass
  5. * Contains all informations about the module
  6. **/
  7. abstract class AModule
  8. {
  9. /**
  10. * @var \Tools\Context $context
  11. * /core/tools/Context.php
  12. * Website context
  13. * Can be accessed read-only
  14. **/
  15. private $context;
  16. /**
  17. * @var Module database object
  18. **/
  19. private $entity;
  20. /**
  21. * Called on module install
  22. * Should register shortcodes and Hooks
  23. **/
  24. public abstract function install();
  25. /**
  26. * Called on module unsinstall
  27. **/
  28. public function uninstall()
  29. { }
  30. /**
  31. * @param \Tools\HookEvent $event called hook
  32. * /core/tools/HookEvent.php
  33. * Called on hook reception
  34. **/
  35. public abstract function doAction($event);
  36. /**
  37. * @param string $shortCode
  38. * @param array ( key => value ) shortcode's parameters
  39. * Called on shortcode reception
  40. **/
  41. public abstract function doShortCode($shortCode, $params);
  42. /**
  43. * @param \Tools\Context $context
  44. * /core/tools/Context.php
  45. * set the application context
  46. * Will work only one time
  47. **/
  48. public function setContext($context)
  49. {
  50. if ($this->context === null)
  51. $this->context = $context;
  52. }
  53. /**
  54. * @param \Entity\Module $module
  55. * /core/models/Module.php
  56. * set the module database object
  57. * Will work only one time
  58. **/
  59. public function setEntity($entity)
  60. {
  61. if ($this->entity === null)
  62. $this->entity = $entity;
  63. }
  64. /**
  65. * Register hook to be triggered
  66. * Can only be triggered while module setup
  67. **/
  68. public static function registerHook($hookName)
  69. {
  70. $this->context->hooks->register($this, $hookname);
  71. }
  72. /**
  73. * @return string module name
  74. **/
  75. public function getName()
  76. {
  77. return $this->entity->name;
  78. }
  79. /**
  80. * @return string module's description
  81. **/
  82. public function getDescription()
  83. { return ""; }
  84. /**
  85. * Getter
  86. **/
  87. public function __get($key)
  88. {
  89. switch ($key)
  90. {
  91. case "context": return $this->context; break;
  92. case "entity": return $this->entity; break;
  93. }
  94. throw new \Exception("Cannot access attribute {$key}");
  95. }
  96. }