diff options
Diffstat (limited to 'app/Core/ExternalTask')
-rw-r--r-- | app/Core/ExternalTask/AccessForbiddenException.php | 14 | ||||
-rw-r--r-- | app/Core/ExternalTask/ExternalTaskManager.php | 53 | ||||
-rw-r--r-- | app/Core/ExternalTask/ExternalTaskProviderInterface.php | 50 | ||||
-rw-r--r-- | app/Core/ExternalTask/NotFoundException.php | 15 | ||||
-rw-r--r-- | app/Core/ExternalTask/ProviderNotFoundException.php | 15 |
5 files changed, 147 insertions, 0 deletions
diff --git a/app/Core/ExternalTask/AccessForbiddenException.php b/app/Core/ExternalTask/AccessForbiddenException.php new file mode 100644 index 00000000..a379d812 --- /dev/null +++ b/app/Core/ExternalTask/AccessForbiddenException.php @@ -0,0 +1,14 @@ +<?php + +namespace Kanboard\Core\ExternalTask; + +use Exception; + +/** + * Class AccessForbiddenException + * + * @package Kanboard\Core\ExternalTask + */ +class AccessForbiddenException extends Exception +{ +} diff --git a/app/Core/ExternalTask/ExternalTaskManager.php b/app/Core/ExternalTask/ExternalTaskManager.php new file mode 100644 index 00000000..2ce6f106 --- /dev/null +++ b/app/Core/ExternalTask/ExternalTaskManager.php @@ -0,0 +1,53 @@ +<?php + +namespace Kanboard\Core\ExternalTask; + +/** + * Class ExternalTaskManager + * + * @package Kanboard\Core\ExternalTask + * @author Frederic Guillot + */ +class ExternalTaskManager +{ + protected $providers = array(); + + /** + * Register a new task provider + * + * @param ExternalTaskProviderInterface $externalTaskProvider + * @return $this + */ + public function register(ExternalTaskProviderInterface $externalTaskProvider) + { + $this->providers[$externalTaskProvider->getName()] = $externalTaskProvider; + return $this; + } + + /** + * Get task provider + * + * @param string $name + * @return ExternalTaskProviderInterface|null + * @throws ProviderNotFoundException + */ + public function getProvider($name) + { + if (isset($this->providers[$name])) { + return $this->providers[$name]; + } + + throw new ProviderNotFoundException('Unable to load this provider: '.$name); + } + + /** + * Get list of task providers + * + * @return array + */ + public function getProvidersList() + { + $providers = array_keys($this->providers); + return array_combine($providers, $providers); + } +} diff --git a/app/Core/ExternalTask/ExternalTaskProviderInterface.php b/app/Core/ExternalTask/ExternalTaskProviderInterface.php new file mode 100644 index 00000000..9e672780 --- /dev/null +++ b/app/Core/ExternalTask/ExternalTaskProviderInterface.php @@ -0,0 +1,50 @@ +<?php + +namespace Kanboard\Core\ExternalTask; + +/** + * Interface ExternalTaskProviderInterface + * + * @package Kanboard\Core\ExternalTask + * @author Frederic Guillot + */ +interface ExternalTaskProviderInterface +{ + /** + * Get templates + * + * @return string + */ + public function getCreationFormTemplate(); + public function getModificationFormTemplate(); + public function getTaskViewTemplate(); + + /** + * Get provider name (visible in the user interface) + * + * @access public + * @return string + */ + public function getName(); + + /** + * Retrieve task from external system or cache + * + * @access public + * @throws \Kanboard\Core\ExternalTask\AccessForbiddenException + * @throws \Kanboard\Core\ExternalTask\NotFoundException + * @param string $uri + * @return array Dict that will populate the form + */ + public function retrieve($uri); + + /** + * Save the task to the external system and/or update the cache + * + * @access public + * @param string $uri + * @param array $data + * @return bool + */ + public function persist($uri, array $data); +} diff --git a/app/Core/ExternalTask/NotFoundException.php b/app/Core/ExternalTask/NotFoundException.php new file mode 100644 index 00000000..c7ed13ef --- /dev/null +++ b/app/Core/ExternalTask/NotFoundException.php @@ -0,0 +1,15 @@ +<?php + +namespace Kanboard\Core\ExternalTask; + +use Exception; + +/** + * Class NotFoundException + * + * @package Kanboard\Core\ExternalTask + * @author Frederic Guillot + */ +class NotFoundException extends Exception +{ +} diff --git a/app/Core/ExternalTask/ProviderNotFoundException.php b/app/Core/ExternalTask/ProviderNotFoundException.php new file mode 100644 index 00000000..2deddda8 --- /dev/null +++ b/app/Core/ExternalTask/ProviderNotFoundException.php @@ -0,0 +1,15 @@ +<?php + +namespace Kanboard\Core\ExternalTask; + +use Exception; + +/** + * Class ProviderNotFoundException + * + * @package Kanboard\Core\ExternalTask + * @author Frederic Guillot + */ +class ProviderNotFoundException extends Exception +{ +} |