Example of pulling a PDO connection from an existing ZF2 DB adapter in order to seed a ZF\OAuth2\Adapter\PdoAdapter instance.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use ZF\OAuth2\Adapter\PdoAdapter; | |
class OAuth2PdoAdapterFactory | |
{ | |
public function __invoke($services) | |
{ | |
$db = $services->get('DB\MyDbName'); | |
if (! $db instanceof Adapter) { | |
throw new DomainException('DB\MyDbname is not a Zend\\Db adapter; cannot be used with OAuth2'); | |
} | |
$pdo = $db->getDriver()->getConnection()->getResource(); | |
if (! $pdo instanceof Pdo) { | |
throw new DomainException('DB\MyDbname is not a PDO-based adapter; cannot be used with OAuth2'); | |
} | |
$config = $services->get('Config'); | |
$oauth2ServerConfig = array(); | |
if (isset($config['zf-oauth2']['storage_settings']) && is_array($config['zf-oauth2']['storage_settings'])) { | |
$oauth2ServerConfig = $config['zf-oauth2']['storage_settings']; | |
} | |
return new OAuth2PdoAdapter($pdo, $oauth2ServerConfig); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment