*/ class ChainUserProvider implements UserProviderInterface { private $providers; public function __construct(array $providers) { $this->providers = $providers; } /** * {@inheritDoc} */ public function loadUserByUsername($username) { foreach ($this->providers as $provider) { try { return $provider->loadUserByUsername($username); } catch (UsernameNotFoundException $notFound) { // try next one } } throw new UsernameNotFoundException(sprintf('There is no user with name "%s".', $username)); } /** * {@inheritDoc} */ public function loadUser(UserInterface $user) { foreach ($this->providers as $provider) { try { return $provider->loadUser($user); } catch (UnsupportedUserException $unsupported) { // try next one } } throw new UnsupportedUserException(sprintf('The account "%s" is not supported.', get_class($user))); } /** * {@inheritDoc} */ public function supportsClass($class) { foreach ($this->providers as $provider) { if ($provider->supportsClass($class)) { return true; } } return false; } }