Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
62.50% covered (warning)
62.50%
5 / 8
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
provider_collection
62.50% covered (warning)
62.50%
5 / 8
50.00% covered (danger)
50.00%
1 / 2
6.32
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 get_provider
50.00% covered (danger)
50.00%
3 / 6
0.00% covered (danger)
0.00%
0 / 1
6.00
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14namespace phpbb\auth;
15
16use Symfony\Component\DependencyInjection\ContainerInterface;
17
18/**
19* Collection of auth providers to be configured at container compile time.
20*/
21class provider_collection extends \phpbb\di\service_collection
22{
23    /** @var \phpbb\config\config phpBB Config */
24    protected $config;
25
26    /**
27    * Constructor
28    *
29    * @param ContainerInterface $container Container object
30    * @param \phpbb\config\config $config phpBB config
31    */
32    public function __construct(ContainerInterface $container, \phpbb\config\config $config)
33    {
34        $this->container = $container;
35        $this->config = $config;
36    }
37
38    /**
39    * Get an auth provider.
40    *
41    * @param string $provider_name The name of the auth provider
42    * @return object    Default auth provider selected in config if it
43    *            does exist. Otherwise the standard db auth
44    *            provider.
45    * @throws \RuntimeException If neither the auth provider that
46    *            is specified by the phpBB config nor the db
47    *            auth provider exist. The db auth provider
48    *            should always exist in a phpBB installation.
49    */
50    public function get_provider($provider_name = '')
51    {
52        $provider_name = ($provider_name !== '') ? $provider_name : basename(trim($this->config['auth_method']));
53        if ($this->offsetExists('auth.provider.' . $provider_name))
54        {
55            return $this->offsetGet('auth.provider.' . $provider_name);
56        }
57        // Revert to db auth provider if selected method does not exist
58        else if ($this->offsetExists('auth.provider.db'))
59        {
60            return $this->offsetGet('auth.provider.db');
61        }
62        else
63        {
64            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']));
65        }
66    }
67}