Hooks.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace Tools;
  3. /**
  4. * Allow user to manage hooks
  5. **/
  6. class Hooks
  7. {
  8. /**
  9. * @var \Tools\Context $context
  10. * /core/tools/Context.php
  11. * Contains website's informations
  12. **/
  13. private $context;
  14. /**
  15. * ctor. Initialize context for having them passed to hook as parameter
  16. **/
  17. public function __construct($context)
  18. {
  19. $this->context = $context;
  20. }
  21. /**
  22. * @param \Tool\AModule $module
  23. * @param string $hookname
  24. * Attach module $module to $hookName
  25. * Can only be called while installing the module.
  26. * When fired, the AModule::doAction($hookName, $context) function will be called.
  27. **/
  28. public function register($module, $hookName)
  29. {
  30. if (!\Tools\ModuleManager::isInstalling())
  31. throw new \Exception("You can only register hooks while installing");
  32. //TODO@2
  33. }
  34. /**
  35. * @param string $hookName
  36. * fire the hook hookName
  37. * call the AModule::doAction($hookName, $context) function for each attached modules
  38. **/
  39. public function trigger($hookName)
  40. {
  41. echo "Triggering hook `{$hookName}'";
  42. //TODO@2
  43. }
  44. /**
  45. * @param array(\Entity\ModuleHook) $module_hookEntities entities to load
  46. * Reload hooks from entities
  47. **/
  48. public function loadHooks($hookEntities)
  49. {
  50. }
  51. }