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/User/UserManager.php | |
parent | 95b2a36886a763242e11b4b27998a0d5c51ca7f4 (diff) |
Add user backend provider system
Diffstat (limited to 'app/Core/User/UserManager.php')
-rw-r--r-- | app/Core/User/UserManager.php | 71 |
1 files changed, 71 insertions, 0 deletions
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); + } +} |