Add ExternalTaskManager class

This commit is contained in:
Frederic Guillot
2016-11-01 22:18:43 -04:00
parent a3ffb3b40e
commit ae5d31e4c2
9 changed files with 222 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
<?php
namespace Kanboard\Core\ExternalTask;
use Exception;
/**
* Class AccessForbiddenException
*
* @package Kanboard\Core\ExternalTask
*/
class AccessForbiddenException extends Exception
{
}

View File

@@ -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);
}
}

View File

@@ -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);
}

View File

@@ -0,0 +1,15 @@
<?php
namespace Kanboard\Core\ExternalTask;
use Exception;
/**
* Class NotFoundException
*
* @package Kanboard\Core\ExternalTask
* @author Frederic Guillot
*/
class NotFoundException extends Exception
{
}

View File

@@ -0,0 +1,15 @@
<?php
namespace Kanboard\Core\ExternalTask;
use Exception;
/**
* Class ProviderNotFoundException
*
* @package Kanboard\Core\ExternalTask
* @author Frederic Guillot
*/
class ProviderNotFoundException extends Exception
{
}