summaryrefslogtreecommitdiff
path: root/app/Event/Base.php
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-10-12 21:38:56 -0400
committerFrédéric Guillot <fred@kanboard.net>2014-10-12 21:38:56 -0400
commit074056352de98fc567b4d13184c72887c75625d0 (patch)
tree7d262c3a5d5f779648f51aa0eb7d9f279c05d89d /app/Event/Base.php
parent4061927d215c846ff8eb196301bf61532018042b (diff)
Project activity refactoring and listeners improvements
Diffstat (limited to 'app/Event/Base.php')
-rw-r--r--app/Event/Base.php79
1 files changed, 79 insertions, 0 deletions
diff --git a/app/Event/Base.php b/app/Event/Base.php
new file mode 100644
index 00000000..745871a5
--- /dev/null
+++ b/app/Event/Base.php
@@ -0,0 +1,79 @@
+<?php
+
+namespace Event;
+
+use Core\Listener;
+use Core\Registry;
+use Core\Tool;
+
+/**
+ * Base Listener
+ *
+ * @package event
+ * @author Frederic Guillot
+ *
+ * @property \Model\Comment $comment
+ * @property \Model\Project $project
+ * @property \Model\ProjectActivity $projectActivity
+ * @property \Model\SubTask $subTask
+ * @property \Model\Task $task
+ * @property \Model\TaskFinder $taskFinder
+ */
+abstract class Base implements Listener
+{
+ /**
+ * Registry instance
+ *
+ * @access protected
+ * @var \Core\Registry
+ */
+ protected $registry;
+
+ /**
+ * Constructor
+ *
+ * @access public
+ * @param \Core\Registry $registry Regsitry instance
+ */
+ public function __construct(Registry $registry)
+ {
+ $this->registry = $registry;
+ }
+
+ /**
+ * Return class information
+ *
+ * @access public
+ * @return string
+ */
+ public function __toString()
+ {
+ return get_called_class();
+ }
+
+ /**
+ * Load automatically models
+ *
+ * @access public
+ * @param string $name Model name
+ * @return mixed
+ */
+ public function __get($name)
+ {
+ return Tool::loadModel($this->registry, $name);
+ }
+
+ /**
+ * Get event namespace
+ *
+ * Event = task.close | Namespace = task
+ *
+ * @access public
+ * @return string
+ */
+ public function getEventNamespace()
+ {
+ $event_name = $this->registry->event->getLastTriggeredEvent();
+ return substr($event_name, 0, strpos($event_name, '.'));
+ }
+}