| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace Tools;
- /**
- * Module superclass
- * Contains all informations about the module
- **/
- abstract class AModule
- {
- /**
- * @var \Tools\Context $context
- * /core/tools/Context.php
- * Website context
- * Can be accessed read-only
- **/
- private $context;
- /**
- * @var Module database object
- **/
- private $entity;
- /**
- * Called on module install
- * Should register shortcodes and Hooks
- **/
- public abstract function install();
- /**
- * Called on module unsinstall
- **/
- public function uninstall()
- { }
- /**
- * @param \Tools\HookEvent $event called hook
- * /core/tools/HookEvent.php
- * Called on hook reception
- **/
- public abstract function doAction($event);
- /**
- * @param string $shortCode
- * @param array ( key => value ) shortcode's parameters
- * Called on shortcode reception
- **/
- public abstract function doShortCode($shortCode, $params);
- /**
- * @param \Tools\Context $context
- * /core/tools/Context.php
- * set the application context
- * Will work only one time
- **/
- public function setContext($context)
- {
- if ($this->context === null)
- $this->context = $context;
- }
- /**
- * @param \Entity\Module $module
- * /core/models/Module.php
- * set the module database object
- * Will work only one time
- **/
- public function setEntity($entity)
- {
- if ($this->entity === null)
- $this->entity = $entity;
- }
- /**
- * Register hook to be triggered
- * Can only be triggered while module setup
- **/
- public function registerHook($hookName)
- {
- $this->context->hookManager->register($this, $hookName);
- }
- /**
- * @return string module name
- **/
- public function getName()
- {
- return $this->entity->name;
- }
- /**
- * @return string module's description
- **/
- public function getDescription()
- { return ""; }
- /**
- * Getter
- **/
- public function __get($key)
- {
- switch ($key)
- {
- case "context": return $this->context; break;
- case "entity": return $this->entity; break;
- }
- throw new \Exception("Cannot access attribute {$key}");
- }
- }
|