Skip to content

Instantly share code, notes, and snippets.

@weierophinney
Created October 9, 2014 20:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weierophinney/56a040d680d225839658 to your computer and use it in GitHub Desktop.
Save weierophinney/56a040d680d225839658 to your computer and use it in GitHub Desktop.
Example of a custom ZF\OAuth2 PdoAdapter implementation.
<?php
namespace MyLib;
use ZF\OAuth2\Adapter\PdoAdapter;
class OAuth2PdoAdapter extends PdoAdapter
{
protected $mapper;
public function setUsersMapper(Users\MapperInterface $mapper)
{
$this->mapper = $mapper;
}
public function checkUserCredentials($username, $password)
{
return $this->mapper->validate($username, $password);
}
public function getUser($username)
{
$user = $this->mapper->fetch($username, $asArray = true);
if (! $user) {
return false;
}
unset(
$user['activated'],
$user['activated_date'],
$user['activation_key'],
$user['password']
);
return array_merge(array(
'user_id' => $username,
), $user->getArrayCopy());
}
public function setUser($username, $password, $firstName = null, $lastName = null)
{
$user = $this->mapper->create(
$username,
$password,
sprintf('%s %s', $firstName, $lastName),
$asArray = true
);
if (false === $user) {
return false;
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment