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 | |
parent | a3ffb3b40e5459a4e671739e8265cc26d7f6b84b (diff) |
Add ExternalTaskManager class
Diffstat (limited to 'app')
-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 | ||||
-rw-r--r-- | app/ServiceProvider/ExternalTaskProvider.php | 29 | ||||
-rw-r--r-- | app/common.php | 1 |
8 files changed, 178 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 +{ +} diff --git a/app/ServiceProvider/ExternalTaskProvider.php b/app/ServiceProvider/ExternalTaskProvider.php new file mode 100644 index 00000000..52484ae6 --- /dev/null +++ b/app/ServiceProvider/ExternalTaskProvider.php @@ -0,0 +1,29 @@ +<?php + +namespace Kanboard\ServiceProvider; + +use Kanboard\Core\ExternalTask\ExternalTaskManager; +use Pimple\Container; +use Pimple\ServiceProviderInterface; + +/** + * Class ExternalTaskProvider + * + * @package Kanboard\ServiceProvider + * @author Frederic Guillot + */ +class ExternalTaskProvider implements ServiceProviderInterface +{ + /** + * Register providers + * + * @access public + * @param \Pimple\Container $container + * @return \Pimple\Container + */ + public function register(Container $container) + { + $container['externalTaskManager'] = new ExternalTaskManager(); + return $container; + } +} diff --git a/app/common.php b/app/common.php index e5490c11..6ebb839e 100644 --- a/app/common.php +++ b/app/common.php @@ -45,6 +45,7 @@ $container->register(new Kanboard\ServiceProvider\GroupProvider()); $container->register(new Kanboard\ServiceProvider\RouteProvider()); $container->register(new Kanboard\ServiceProvider\ActionProvider()); $container->register(new Kanboard\ServiceProvider\ExternalLinkProvider()); +$container->register(new Kanboard\ServiceProvider\ExternalTaskProvider()); $container->register(new Kanboard\ServiceProvider\AvatarProvider()); $container->register(new Kanboard\ServiceProvider\FilterProvider()); $container->register(new Kanboard\ServiceProvider\JobProvider()); |