diff options
author | Frederic Guillot <fred@kanboard.net> | 2017-11-09 15:09:54 -0800 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2017-11-09 15:09:54 -0800 |
commit | 44aa24bab16bdc2545b08594386adb24ead3aa9e (patch) | |
tree | 4ca2c4632d9657f8babfb7781b5aadc0d3e30238 /app/Core | |
parent | 95b2a36886a763242e11b4b27998a0d5c51ca7f4 (diff) |
Add user backend provider system
Diffstat (limited to 'app/Core')
-rw-r--r-- | app/Core/Base.php | 3 | ||||
-rw-r--r-- | app/Core/Group/GroupBackendProviderInterface.php | 2 | ||||
-rw-r--r-- | app/Core/Group/GroupManager.php | 10 | ||||
-rw-r--r-- | app/Core/Group/GroupProviderInterface.php | 2 | ||||
-rw-r--r-- | app/Core/User/UserBackendProviderInterface.php | 21 | ||||
-rw-r--r-- | app/Core/User/UserManager.php | 71 |
6 files changed, 101 insertions, 8 deletions
diff --git a/app/Core/Base.php b/app/Core/Base.php index 4e553746..3807f385 100644 --- a/app/Core/Base.php +++ b/app/Core/Base.php @@ -7,7 +7,7 @@ use Pimple\Container; /** * Base Class * - * @package core + * @package Kanboard\Core * @author Frederic Guillot * * @property \Kanboard\Analytic\TaskDistributionAnalytic $taskDistributionAnalytic @@ -22,6 +22,7 @@ use Pimple\Container; * @property \Kanboard\Core\Cache\BaseCache $cacheDriver * @property \Kanboard\Core\Event\EventManager $eventManager * @property \Kanboard\Core\Group\GroupManager $groupManager + * @property \Kanboard\Core\User\UserManager $userManager * @property \Kanboard\Core\Http\Client $httpClient * @property \Kanboard\Core\Http\OAuth2 $oauth * @property \Kanboard\Core\Http\RememberMeCookie $rememberMeCookie diff --git a/app/Core/Group/GroupBackendProviderInterface.php b/app/Core/Group/GroupBackendProviderInterface.php index 74c5cb03..0b6e2985 100644 --- a/app/Core/Group/GroupBackendProviderInterface.php +++ b/app/Core/Group/GroupBackendProviderInterface.php @@ -5,7 +5,7 @@ namespace Kanboard\Core\Group; /** * Group Backend Provider Interface * - * @package group + * @package Kanboard\Core\Group * @author Frederic Guillot */ interface GroupBackendProviderInterface diff --git a/app/Core/Group/GroupManager.php b/app/Core/Group/GroupManager.php index 48b6c4f8..a0559139 100644 --- a/app/Core/Group/GroupManager.php +++ b/app/Core/Group/GroupManager.php @@ -5,7 +5,7 @@ namespace Kanboard\Core\Group; /** * Group Manager * - * @package group + * @package Kanboard\Core\Group * @author Frederic Guillot */ class GroupManager @@ -13,10 +13,10 @@ class GroupManager /** * List of backend providers * - * @access private + * @access protected * @var array */ - private $providers = array(); + protected $providers = array(); /** * Register a new group backend provider @@ -52,11 +52,11 @@ class GroupManager /** * Remove duplicated groups * - * @access private + * @access protected * @param array $groups * @return GroupProviderInterface[] */ - private function removeDuplicates(array $groups) + protected function removeDuplicates(array $groups) { $result = array(); diff --git a/app/Core/Group/GroupProviderInterface.php b/app/Core/Group/GroupProviderInterface.php index 4c7c16ec..f312f89b 100644 --- a/app/Core/Group/GroupProviderInterface.php +++ b/app/Core/Group/GroupProviderInterface.php @@ -5,7 +5,7 @@ namespace Kanboard\Core\Group; /** * Group Provider Interface * - * @package group + * @package Kanboard\Core\Group * @author Frederic Guillot */ interface GroupProviderInterface diff --git a/app/Core/User/UserBackendProviderInterface.php b/app/Core/User/UserBackendProviderInterface.php new file mode 100644 index 00000000..5f8cab47 --- /dev/null +++ b/app/Core/User/UserBackendProviderInterface.php @@ -0,0 +1,21 @@ +<?php + +namespace Kanboard\Core\User; + +/** + * User Backend Provider Interface + * + * @package Kanboard\Core\User + * @author Frederic Guillot + */ +interface UserBackendProviderInterface +{ + /** + * Find a user from a search query + * + * @access public + * @param string $input + * @return UserProviderInterface[] + */ + public function find($input); +} diff --git a/app/Core/User/UserManager.php b/app/Core/User/UserManager.php new file mode 100644 index 00000000..e1692480 --- /dev/null +++ b/app/Core/User/UserManager.php @@ -0,0 +1,71 @@ +<?php + +namespace Kanboard\Core\User; + +/** + * User Manager + * + * @package Kanboard\Core\User + * @author Frederic Guillot + */ +class UserManager +{ + /** + * List of backend providers + * + * @access protected + * @var array + */ + protected $providers = array(); + + /** + * Register a new group backend provider + * + * @access public + * @param UserBackendProviderInterface $provider + * @return $this + */ + public function register(UserBackendProviderInterface $provider) + { + $this->providers[] = $provider; + return $this; + } + + /** + * Find a group from a search query + * + * @access public + * @param string $input + * @return UserProviderInterface[] + */ + public function find($input) + { + $groups = array(); + + foreach ($this->providers as $provider) { + $groups = array_merge($groups, $provider->find($input)); + } + + return $this->removeDuplicates($groups); + } + + /** + * Remove duplicated users + * + * @access protected + * @param array $users + * @return UserProviderInterface[] + */ + protected function removeDuplicates(array $users) + { + $result = array(); + + foreach ($users as $user) { + if (! isset($result[$user->getUsername()])) { + $result[$user->getUsername()] = $user; + } + } + + return array_values($result); + } +} |