2014-11-04 09:05:21 +00:00
|
|
|
<?php
|
|
|
|
namespace Westdc\Helpers;
|
|
|
|
|
2015-01-09 15:33:25 +00:00
|
|
|
use Zend\Authentication\AuthenticationService;
|
|
|
|
use Zend\Authentication\Storage\Session as SessionStorage;
|
2014-11-04 09:05:21 +00:00
|
|
|
|
|
|
|
class Auth
|
|
|
|
{
|
|
|
|
public $auth;
|
2015-01-18 15:24:31 +00:00
|
|
|
|
2014-11-04 09:05:21 +00:00
|
|
|
function __construct($getAuthService = false)
|
|
|
|
{
|
|
|
|
$config = Config::get();
|
|
|
|
|
|
|
|
$this->auth = new AuthenticationService();
|
|
|
|
$this->auth->setStorage(new SessionStorage($config->session_namespace));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getInstance()
|
|
|
|
{
|
|
|
|
return $this->auth;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function clearIndentity()
|
|
|
|
{
|
|
|
|
return $this->auth->clearIdentity();
|
|
|
|
}
|
|
|
|
|
2015-01-18 15:24:31 +00:00
|
|
|
public function getIdentity($field = "")
|
2014-11-04 09:05:21 +00:00
|
|
|
{
|
2015-01-18 15:24:31 +00:00
|
|
|
if(empty($field))
|
|
|
|
return $this->auth->getIdentity();
|
|
|
|
|
2014-12-23 14:32:23 +00:00
|
|
|
if(isset($this->auth->getIdentity()->$field))
|
|
|
|
return $this->auth->getIdentity()->$field;
|
|
|
|
else
|
|
|
|
return null;
|
2014-11-04 09:05:21 +00:00
|
|
|
}
|
2015-01-18 15:24:31 +00:00
|
|
|
|
|
|
|
public function write($user)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(is_array($user))
|
|
|
|
$user = (object)$user;
|
|
|
|
|
|
|
|
$this->auth->getStorage()->write($user);
|
|
|
|
}
|
2014-11-04 09:05:21 +00:00
|
|
|
}
|