Skip to content

Instantly share code, notes, and snippets.

@weierophinney
Created August 5, 2014 20:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save weierophinney/edb762a09d7a800b2ead to your computer and use it in GitHub Desktop.
Example of pulling a PDO connection from an existing ZF2 DB adapter in order to seed a ZF\OAuth2\Adapter\PdoAdapter instance.
<?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