aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/auth/provider_collection.php
diff options
context:
space:
mode:
authorMarc Alexander <admin@m-a-styles.de>2014-05-31 22:43:07 +0200
committerMarc Alexander <admin@m-a-styles.de>2014-06-01 21:31:06 +0200
commit6f5f0d6d8d5d3afcabccaa9da7c64108af5d4ab7 (patch)
tree3cd8ff3ae639535b97f99f203bc77b8c074ba115 /phpBB/phpbb/auth/provider_collection.php
parent306beab4cba155a933391c40c75f5dd9c57fd69e (diff)
downloadforums-6f5f0d6d8d5d3afcabccaa9da7c64108af5d4ab7.tar
forums-6f5f0d6d8d5d3afcabccaa9da7c64108af5d4ab7.tar.gz
forums-6f5f0d6d8d5d3afcabccaa9da7c64108af5d4ab7.tar.bz2
forums-6f5f0d6d8d5d3afcabccaa9da7c64108af5d4ab7.tar.xz
forums-6f5f0d6d8d5d3afcabccaa9da7c64108af5d4ab7.zip
[ticket/12352] Use custom provider collection for auth providers
Using this custom provider collection, we can properly check whether the configured auth provider does exist. The method get_provider() has been added for returning the default auth provider or the standard db auth provider if the specified one does not exist. Additionally, the method get_provider() will throw an RuntimeException if none of the above exist. PHPBB3-12352
Diffstat (limited to 'phpBB/phpbb/auth/provider_collection.php')
-rw-r--r--phpBB/phpbb/auth/provider_collection.php63
1 files changed, 63 insertions, 0 deletions
diff --git a/phpBB/phpbb/auth/provider_collection.php b/phpBB/phpbb/auth/provider_collection.php
new file mode 100644
index 0000000000..bef1dd2c50
--- /dev/null
+++ b/phpBB/phpbb/auth/provider_collection.php
@@ -0,0 +1,63 @@
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2014 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+namespace phpbb\auth;
+
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/**
+* Collection of auth providers to be configured at container compile time.
+*
+* @package phpBB3
+*/
+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
+ */
+ public function __construct($container, \phpbb\config\config $config)
+ {
+ $this->container = $container;
+ $this->config = $config;
+ }
+
+ /**
+ * Get an auth provider.
+ *
+ * @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.
+ */
+ public function get_provider()
+ {
+ if ($this->offsetExists('auth.provider.' . basename(trim($this->config['auth_method']))))
+ {
+ return $this->offsetGet('auth.provider.' . basename(trim($this->config['auth_method'])));
+ }
+ // Revert to db auth provider if selected method does not exist
+ elseif ($this->offsetExists('auth.provider.db'))
+ {
+ 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']));
+ }
+ }
+}