summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Core/Base.php1
-rw-r--r--app/Core/ExternalTask/AccessForbiddenException.php14
-rw-r--r--app/Core/ExternalTask/ExternalTaskManager.php53
-rw-r--r--app/Core/ExternalTask/ExternalTaskProviderInterface.php50
-rw-r--r--app/Core/ExternalTask/NotFoundException.php15
-rw-r--r--app/Core/ExternalTask/ProviderNotFoundException.php15
-rw-r--r--app/ServiceProvider/ExternalTaskProvider.php29
-rw-r--r--app/common.php1
-rw-r--r--tests/units/Core/ExternalTask/ExternalTaskManagerTest.php44
9 files changed, 222 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());
diff --git a/tests/units/Core/ExternalTask/ExternalTaskManagerTest.php b/tests/units/Core/ExternalTask/ExternalTaskManagerTest.php
new file mode 100644
index 00000000..e6f4e069
--- /dev/null
+++ b/tests/units/Core/ExternalTask/ExternalTaskManagerTest.php
@@ -0,0 +1,44 @@
+<?php
+
+use Kanboard\Core\ExternalTask\ExternalTaskManager;
+
+require_once __DIR__.'/../../Base.php';
+
+class ExternalTaskManagerTest extends Base
+{
+ public function testProviderNotFound()
+ {
+ $this->setExpectedException('Kanboard\Core\ExternalTask\ProviderNotFoundException');
+
+ $manager = new ExternalTaskManager();
+ $manager->getProvider('foobar');
+ }
+
+ public function testRegister()
+ {
+ $provider = $this->getMock('Kanboard\Core\ExternalTask\ExternalTaskProviderInterface');
+ $provider->expects($this->any())->method('getName')->willReturn('MyProvider');
+
+ $manager = new ExternalTaskManager();
+ $manager->register($provider);
+
+ $this->assertInstanceOf('Kanboard\Core\ExternalTask\ExternalTaskProviderInterface', $manager->getProvider('MyProvider'));
+ }
+
+ public function testGetList()
+ {
+ $provider1 = $this->getMock('Kanboard\Core\ExternalTask\ExternalTaskProviderInterface');
+ $provider1->expects($this->any())->method('getName')->willReturn('MyProvider1');
+
+ $provider2 = $this->getMock('Kanboard\Core\ExternalTask\ExternalTaskProviderInterface');
+ $provider2->expects($this->any())->method('getName')->willReturn('MyProvider2');
+
+ $manager = new ExternalTaskManager();
+ $manager->register($provider1);
+ $manager->register($provider2);
+ $providers = $manager->getProvidersList();
+
+ $expected = array('MyProvider1' => 'MyProvider1', 'MyProvider2' => 'MyProvider2');
+ $this->assertEquals($expected, $providers);
+ }
+}