. */ namespace vierbergenlars\AuthserverOAuthAccountBundle\ResourceOwner; use vierbergenlars\AuthserverExternalAccountBundle\Entity\ExternalUser; class ResourceOwnerMap implements \ArrayAccess, \IteratorAggregate { private $config; public function __construct(array $config) { $this->config = $config; } /** * * @param ExternalUser $externalUser * @throws \InvalidArgumentException * @return ResourceOwnerConfig */ public function getOwnerFromExternalUser(ExternalUser $externalUser) { $provider = $externalUser->getProvider(); if (strpos($provider, 'oauth_') !== 0) throw new \InvalidArgumentException(sprintf('External user provider should start with "oauth_", got "%s"', $provider)); $name = substr($provider, strlen('oauth_')); return $this->offsetGet($name); } public function offsetExists($offset) { return isset($this->config[$offset]); } public function offsetGet($offset) { if (!$this->offsetExists($offset)) throw new \OutOfBoundsException(sprintf('Resource owner "%s" does not exist.', $offset)); if (!$this->config[$offset] instanceof ResourceOwnerConfig) $this->config[$offset] = new ResourceOwnerConfig($this->config[$offset]); return $this->config[$offset]; } public function offsetSet($offset, $value) { throw new \LogicException(sprintf('%s is frozen.', self::class)); } public function offsetUnset($offset) { throw new \LogicException(sprintf('%s is frozen.', self::class)); } public function getIterator() { return new ResourceOwnerMapIterator($this, array_keys($this->config)); } }