| | <?php |
| |
|
| | namespace Kanboard\Action; |
| |
|
| | use Kanboard\Event\GenericEvent; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | abstract class Base extends \Kanboard\Core\Base |
| | { |
| | |
| | |
| | |
| | |
| | |
| | |
| | private $compatibleEvents = array(); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | private $callStack = []; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | private $projectId = 0; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | private $params = array(); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | final public function getName() |
| | { |
| | return '\\'.get_called_class(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | abstract public function getDescription(); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | abstract public function doAction(array $data); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | abstract public function getActionRequiredParameters(); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | abstract public function getEventRequiredParameters(); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | abstract public function getCompatibleEvents(); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | abstract public function hasRequiredCondition(array $data); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | public function __toString() |
| | { |
| | $params = array(); |
| |
|
| | foreach ($this->params as $key => $value) { |
| | $params[] = $key.'='.var_export($value, true); |
| | } |
| |
|
| | return $this->getName().'('.implode('|', $params).')'; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public function setProjectId($project_id) |
| | { |
| | $this->projectId = $project_id; |
| | return $this; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | public function getProjectId() |
| | { |
| | return $this->projectId; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public function setParam($name, $value) |
| | { |
| | $this->params[$name] = $value; |
| | return $this; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public function getParam($name, $default = null) |
| | { |
| | return isset($this->params[$name]) ? $this->params[$name] : $default; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public function isExecutable(array $data, $eventName) |
| | { |
| | return $this->hasCompatibleEvent($eventName) && |
| | $this->hasRequiredProject($data) && |
| | $this->hasRequiredParameters($data) && |
| | $this->hasRequiredCondition($data); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public function hasCompatibleEvent($eventName) |
| | { |
| | return in_array($eventName, $this->getEvents()); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public function hasRequiredProject(array $data) |
| | { |
| | return (isset($data['project_id']) && $data['project_id'] == $this->getProjectId()) || |
| | (isset($data['task']['project_id']) && $data['task']['project_id'] == $this->getProjectId()); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public function hasRequiredParameters(array $data, array $parameters = array()) |
| | { |
| | $parameters = $parameters ?: $this->getEventRequiredParameters(); |
| |
|
| | foreach ($parameters as $key => $value) { |
| | if (is_array($value)) { |
| | return isset($data[$key]) && $this->hasRequiredParameters($data[$key], $value); |
| | } else if (! isset($data[$value])) { |
| | return false; |
| | } |
| | } |
| |
|
| | return true; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public function execute(GenericEvent $event, $eventName) |
| | { |
| | $data = $event->getAll(); |
| | $hash = md5(serialize($data).$eventName); |
| |
|
| | |
| | if (isset($this->callStack[$hash])) { |
| | return false; |
| | } else { |
| | $this->callStack[$hash] = true; |
| | } |
| |
|
| | $executable = $this->isExecutable($data, $eventName); |
| | $executed = false; |
| |
|
| | if ($executable) { |
| | $executed = $this->doAction($data); |
| | } |
| |
|
| | $this->logger->debug($this.' ['.$eventName.'] => executable='.var_export($executable, true).' exec_success='.var_export($executed, true)); |
| |
|
| | return $executed; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public function addEvent($event, $description = '') |
| | { |
| | if ($description !== '') { |
| | $this->eventManager->register($event, $description); |
| | } |
| |
|
| | $this->compatibleEvents[] = $event; |
| | return $this; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | public function getEvents() |
| | { |
| | return array_unique(array_merge($this->getCompatibleEvents(), $this->compatibleEvents)); |
| | } |
| | } |
| |
|