diff options
author | Frédéric Guillot <fguillot@users.noreply.github.com> | 2014-03-10 21:49:24 -0400 |
---|---|---|
committer | Frédéric Guillot <fguillot@users.noreply.github.com> | 2014-03-10 21:49:24 -0400 |
commit | 1cda8059b577d4025efa96377def082bf8f35f94 (patch) | |
tree | 0a24ff313a60da340b8d4b85b63f76bb6bf883cb /actions/base.php | |
parent | fca61f7eb0ca1c3cc9f2f4ce02578bd80f8a2be0 (diff) |
Lowercase file
Diffstat (limited to 'actions/base.php')
-rw-r--r-- | actions/base.php | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/actions/base.php b/actions/base.php new file mode 100644 index 00000000..bb9b8bc1 --- /dev/null +++ b/actions/base.php @@ -0,0 +1,55 @@ +<?php + +namespace Action; + +abstract class Base implements \Core\Listener +{ + private $project_id = 0; + private $params = array(); + + abstract public function doAction(array $data); + abstract public function getActionRequiredParameters(); + abstract public function getEventRequiredParameters(); + + public function __construct($project_id) + { + $this->project_id = $project_id; + } + + public function setParam($name, $value) + { + $this->params[$name] = $value; + } + + public function getParam($name, $default_value = null) + { + return isset($this->params[$name]) ? $this->params[$name] : $default_value; + } + + public function isExecutable(array $data) + { + if (isset($data['project_id']) && $data['project_id'] == $this->project_id && $this->hasRequiredParameters($data)) { + return true; + } + + return false; + } + + public function hasRequiredParameters(array $data) + { + foreach ($this->getEventRequiredParameters() as $parameter) { + if (! isset($data[$parameter])) return false; + } + + return true; + } + + public function execute(array $data) + { + if ($this->isExecutable($data)) { + return $this->doAction($data); + } + + return false; + } +} |