00001 <?php 00029 class Zend_Auth 00030 { 00036 protected static $_instance = null; 00037 00043 protected $_storage = null; 00044 00050 protected function __construct() 00051 {} 00052 00058 protected function __clone() 00059 {} 00060 00068 public static function getInstance() 00069 { 00070 if (null === self::$_instance) { 00071 self::$_instance = new self(); 00072 } 00073 00074 return self::$_instance; 00075 } 00076 00084 public function getStorage() 00085 { 00086 if (null === $this->_storage) { 00090 require_once 'Zend/Auth/Storage/Session.php'; 00091 $this->setStorage(new Zend_Auth_Storage_Session()); 00092 } 00093 00094 return $this->_storage; 00095 } 00096 00103 public function setStorage(Zend_Auth_Storage_Interface $storage) 00104 { 00105 $this->_storage = $storage; 00106 return $this; 00107 } 00108 00115 public function authenticate(Zend_Auth_Adapter_Interface $adapter) 00116 { 00117 $result = $adapter->authenticate(); 00118 00123 if ($this->hasIdentity()) { 00124 $this->clearIdentity(); 00125 } 00126 00127 if ($result->isValid()) { 00128 $this->getStorage()->write($result->getIdentity()); 00129 } 00130 00131 return $result; 00132 } 00133 00139 public function hasIdentity() 00140 { 00141 return !$this->getStorage()->isEmpty(); 00142 } 00143 00149 public function getIdentity() 00150 { 00151 $storage = $this->getStorage(); 00152 00153 if ($storage->isEmpty()) { 00154 return null; 00155 } 00156 00157 return $storage->read(); 00158 } 00159 00165 public function clearIdentity() 00166 { 00167 $this->getStorage()->clear(); 00168 } 00169 }