2014-05-31 22:43:07 +02:00
< ? php
/**
*
2014-06-01 21:36:53 +02:00
* This file is part of the phpBB Forum Software package .
*
* @ copyright ( c ) phpBB Limited < https :// www . phpbb . com >
* @ license GNU General Public License , version 2 ( GPL - 2.0 )
*
* For full copyright and license information , please see
* the docs / CREDITS . txt file .
2014-05-31 22:43:07 +02:00
*
*/
namespace phpbb\auth ;
use Symfony\Component\DependencyInjection\ContainerInterface ;
/**
* Collection of auth providers to be configured at container compile time .
*/
class provider_collection extends \phpbb\di\service_collection
{
/** @var \phpbb\config\config phpBB Config */
protected $config ;
/**
* Constructor
*
* @ param ContainerInterface $container Container object
* @ param \phpbb\config\config $config phpBB config
*/
2014-06-16 22:55:42 +02:00
public function __construct ( ContainerInterface $container , \phpbb\config\config $config )
2014-05-31 22:43:07 +02:00
{
$this -> container = $container ;
$this -> config = $config ;
}
/**
* Get an auth provider .
*
2014-10-30 14:24:33 +01:00
* @ param string $provider_name The name of the auth provider
2014-05-31 22:43:07 +02:00
* @ return object Default auth provider selected in config if it
* does exist . Otherwise the standard db auth
* provider .
* @ throws \RuntimeException If neither the auth provider that
* is specified by the phpBB config nor the db
* auth provider exist . The db auth provider
* should always exist in a phpBB installation .
*/
2014-10-30 14:24:33 +01:00
public function get_provider ( $provider_name = '' )
2014-05-31 22:43:07 +02:00
{
2014-10-30 16:54:43 +01:00
$provider_name = ( $provider_name !== '' ) ? $provider_name : basename ( trim ( $this -> config [ 'auth_method' ]));
2014-10-30 14:24:33 +01:00
if ( $this -> offsetExists ( 'auth.provider.' . $provider_name ))
2014-05-31 22:43:07 +02:00
{
2014-10-30 14:24:33 +01:00
return $this -> offsetGet ( 'auth.provider.' . $provider_name );
2014-05-31 22:43:07 +02:00
}
// Revert to db auth provider if selected method does not exist
2014-06-15 21:34:02 +02:00
else if ( $this -> offsetExists ( 'auth.provider.db' ))
2014-05-31 22:43:07 +02:00
{
return $this -> offsetGet ( 'auth.provider.db' );
}
else
{
throw new \RuntimeException ( sprintf ( 'The authentication provider for the authentication method "%1$s" does not exist. It was not possible to recover from this by reverting to the database authentication provider.' , $this -> config [ 'auth_method' ]));
}
}
}