diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/src/Connection/ConnectionProviderRef.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/src/Connection/ConnectionProviderRef.php | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/src/Connection/ConnectionProviderRef.php b/www/wiki/extensions/SemanticMediaWiki/src/Connection/ConnectionProviderRef.php new file mode 100644 index 00000000..471f3a35 --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/src/Connection/ConnectionProviderRef.php @@ -0,0 +1,66 @@ +<?php + +namespace SMW\Connection; + +use RuntimeException; + +/** + * @license GNU GPL v2+ + * @since 3.0 + * + * @author mwjames + */ +class ConnectionProviderRef { + + /** + * @var array + */ + private $connectionProviders = []; + + /** + * @since 3.0 + * + * @param array $connectionProviders + */ + public function __construct( array $connectionProviders ) { + $this->connectionProviders = $connectionProviders; + } + + /** + * @since 3.0 + * + * @param string $key + * + * @return boolean + */ + public function hasConnection( $key ) { + return isset( $this->connectionProviders[$key] ); + } + + /** + * @since 3.0 + * + * @param string $key + * + * @return ConnectionProvider + * @throws RuntimeException + */ + public function getConnection( $key ) { + + if ( isset( $this->connectionProviders[$key] ) && $this->connectionProviders[$key] instanceof ConnectionProvider ) { + return $this->connectionProviders[$key]->getConnection(); + } + + throw new RuntimeException( "$key is unknown" ); + } + + /** + * @since 3.0 + */ + public function releaseConnection() { + foreach ( $this->connectionProviders as $connectionProvider ) { + $connectionProvider->releaseConnection(); + } + } + +} |