From 44aa24bab16bdc2545b08594386adb24ead3aa9e Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Thu, 9 Nov 2017 15:09:54 -0800 Subject: Add user backend provider system --- app/Core/User/UserManager.php | 71 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 app/Core/User/UserManager.php (limited to 'app/Core/User/UserManager.php') 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 @@ +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); + } +} -- cgit v1.2.3