diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-11-01 22:18:43 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-11-01 22:18:43 -0400 |
commit | ae5d31e4c285e0ce672de780fdacff953fe71bba (patch) | |
tree | 5a0f3995633da429417cdc0cfbad920c3e9b4bc9 /app/Core | |
parent | a3ffb3b40e5459a4e671739e8265cc26d7f6b84b (diff) |
Add ExternalTaskManager class
Diffstat (limited to 'app/Core')
-rw-r--r-- | app/Core/Base.php | 1 | ||||
-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 |
6 files changed, 148 insertions, 0 deletions
diff --git a/app/Core/Base.php b/app/Core/Base.php index 44dfaa39..3dbf47f9 100644 --- a/app/Core/Base.php +++ b/app/Core/Base.php @@ -17,6 +17,7 @@ use Pimple\Container; * @property \Kanboard\Analytic\AverageTimeSpentColumnAnalytic $averageTimeSpentColumnAnalytic * @property \Kanboard\Core\Action\ActionManager $actionManager * @property \Kanboard\Core\ExternalLink\ExternalLinkManager $externalLinkManager + * @property \Kanboard\Core\ExternalTask\ExternalTaskManager $externalTaskManager * @property \Kanboard\Core\Cache\MemoryCache $memoryCache * @property \Kanboard\Core\Cache\BaseCache $cacheDriver * @property \Kanboard\Core\Event\EventManager $eventManager 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 +{ +} |