/** * Create an instance of HttpAdapter based on the configuration provided * and the registered AuthenticationService. * * @param string $type The base "type" the adapter will provide * @param array $config * @param ContainerInterface $container * @return HttpAdapter */ public static function factory($type, array $config, ContainerInterface $container) { if (!$container->has('authentication')) { throw new ServiceNotCreatedException('Cannot create HTTP authentication adapter; missing AuthenticationService'); } if (!isset($config['options']) || !is_array($config['options'])) { throw new ServiceNotCreatedException('Cannot create HTTP authentication adapter; missing options'); } return new HttpAdapter(HttpAdapterFactory::factory($config['options'], $container), $container->get('authentication'), $type); }
/** * Create an object * * @param ContainerInterface $container * @param string $requestedName * @param null|array $options * @return HttpAuth */ public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { // If no configuration present, nothing to create if (!$container->has('config')) { return false; } $config = $container->get('config'); // If no HTTP adapter configuration present, nothing to create if (!isset($config['zf-mvc-auth']['authentication']['http'])) { return false; } return HttpAdapterFactory::factory($config['zf-mvc-auth']['authentication']['http'], $container); }
/** * @param ServiceLocatorInterface $services * @throws ServiceNotCreatedException * @return false|HttpAuth */ public function createService(ServiceLocatorInterface $services) { // If no configuration present, nothing to create if (!$services->has('config')) { return false; } $config = $services->get('config'); // If no HTTP adapter configuration present, nothing to create if (!isset($config['zf-mvc-auth']['authentication']['http'])) { return false; } return HttpAdapterFactory::factory($config['zf-mvc-auth']['authentication']['http'], $services); }
public function testCanReturnAdapterWithNoResolversAndMissingServiceManagerEntries() { $missingKeyForServiceManager = 'missingKeyForServiceManager'; $serviceManager = $this->getMockBuilder('\\Zend\\ServiceManager\\ServiceLocatorInterface')->getMock(); $serviceManager->expects($this->any())->method('has')->with($missingKeyForServiceManager)->will($this->returnValue(false)); $serviceManager->expects($this->never())->method('get'); $adapter = HttpAdapterFactory::factory(['accept_schemes' => ['basic', 'digest'], 'realm' => 'api', 'digest_domains' => 'https://example.com', 'nonce_timeout' => 3600, 'basic_resolver_factory' => $missingKeyForServiceManager, 'digest_resolver_factory' => $missingKeyForServiceManager], $serviceManager); $this->assertInstanceOf('Zend\\Authentication\\Adapter\\Http', $adapter); $this->assertNull($adapter->getBasicResolver()); $this->assertNull($adapter->getDigestResolver()); }
public function testCanReturnCompoundAdapter() { $adapter = HttpAdapterFactory::factory(array( 'accept_schemes' => array('basic', 'digest'), 'realm' => 'api', 'digest_domains' => 'https://example.com', 'nonce_timeout' => 3600, 'htpasswd' => $this->htpasswd, 'htdigest' => $this->htdigest, )); $this->assertInstanceOf('Zend\Authentication\Adapter\Http', $adapter); $this->assertInstanceOf('Zend\Authentication\Adapter\Http\ApacheResolver', $adapter->getBasicResolver()); $this->assertInstanceOf('Zend\Authentication\Adapter\Http\FileResolver', $adapter->getDigestResolver()); }