summaryrefslogtreecommitdiff
path: root/app/Core/ExternalTask/ExternalTaskManager.php
blob: 87a46b71b1d56d6f4c1fc2c5bf8f1e2566d40d93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?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);

        if (count($providers)) {
            return array_combine($providers, $providers);
        }

        return array();
    }

    /**
     * Get all providers
     *
     * @return ExternalTaskProviderInterface[]
     */
    public function getProviders()
    {
        return $this->providers;
    }
}