Created
July 17, 2012 19:30
-
-
Save bakura10/3131459 to your computer and use it in GitHub Desktop.
Common\Authentication\Storage\Db
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 | |
namespace Common\Authentication\Storage; | |
use Doctrine\Common\Persistence\ObjectRepository; | |
use Zend\Authentication\Storage\StorageInterface; | |
/** | |
* This class implements StorageInterface and allow to save the result of an authentication against a database | |
*/ | |
class Db implements StorageInterface | |
{ | |
/** | |
* @var ObjectRepository | |
*/ | |
protected $objectRepository; | |
/** | |
* @var StorageInterface | |
*/ | |
protected $storage; | |
/** | |
* @param ObjectRepository $objectRepository | |
* @param StorageInterface $storage | |
*/ | |
public function __construct(ObjectRepository $objectRepository, StorageInterface $storage) | |
{ | |
$this->objectRepository = $objectRepository; | |
$this->storage = $storage; | |
} | |
/** | |
* @return bool | |
*/ | |
public function isEmpty() | |
{ | |
return $this->storage->isEmpty(); | |
} | |
/** | |
* @return mixed|null|object | |
*/ | |
public function read() | |
{ | |
$identity = $this->storage->read(); | |
if (is_scalar($identity)) { | |
return $this->objectRepository->find($identity); | |
} else { | |
return null; | |
} | |
} | |
/** | |
* @param $contents | |
* @return void | |
*/ | |
public function write($contents) | |
{ | |
$this->storage->write($contents); | |
} | |
/** | |
* @return void | |
*/ | |
public function clear() | |
{ | |
$this->storage->clear(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment