本文整理匯總了PHP中Zend\Session\SessionManager::isValid方法的典型用法代碼示例。如果您正苦於以下問題:PHP SessionManager::isValid方法的具體用法?PHP SessionManager::isValid怎麽用?PHP SessionManager::isValid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\Session\SessionManager
的用法示例。
在下文中一共展示了SessionManager::isValid方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: isValid
/**
* Is this session valid?
*
* Notifies the Validator Chain until either all validators have returned
* true or one has failed.
*
* @return bool
*/
public function isValid()
{
if (null === $this->isValid) {
$this->isValid = parent::isValid();
}
return $this->isValid;
}
示例2: _init
public function _init(Dispatcher $dispatcher)
{
// 引入Composer,Yaf擴展的配置項yaf.use_spl_autoload務必設置為1
if (file_exists(ROOT_PATH . '/vendor/autoload.php')) {
$loader = (include ROOT_PATH . '/vendor/autoload.php');
//$loader->add("",ROOT_PATH.'/library');
//$loader->addPsr4("Zend\\",ROOT_PATH.'/library/Zend');
Registry::set('loader', $loader);
}
// 禁止自動渲染
$dispatcher->autoRender(FALSE);
// 保存配置
$this->_config = Application::app()->getConfig();
Registry::set('config', $this->_config);
// 報錯設置
if ($this->_config->global->showError) {
error_reporting(-1);
ini_set('display_errors', 'On');
}
// 加解密
if (!empty($this->_config->global->key)) {
Registry::set('enc', function () {
$blockCipher = BlockCipher::factory('mcrypt', array('algo' => 'aes'));
$blockCipher->setKey($this->_config->global->key);
return $blockCipher;
});
}
// 命令行方式,跳過SESSION
if (!defined("RUN_IN_CLI")) {
// 保存路徑
$sessionConfig = $this->_config->session->toArray();
if (isset($sessionConfig['save_path'])) {
@mkdir($sessionConfig['save_path'], 0777, true);
}
// 配置
$config = new SessionConfig();
$config->setOptions($sessionConfig);
// 會話管理器
$manager = new SessionManager($config);
// 開啟會話
$manager->start();
// 驗證會話
$manager->getValidatorChain()->attach('session.validate', array(new HttpUserAgent(), 'isValid'));
if (!$manager->isValid()) {
$manager->destroy();
throw new \Exception("會話驗證失敗");
}
// 會話Token
$default = new Zend\Session\Container();
if (empty($default->offsetGet('securityToken'))) {
$default->offsetSet('securityToken', md5(uniqid(rand(), true)));
}
// 保存實例
Registry::set('session', $default);
Registry::set('sm', $manager);
}
// 數據庫
Registry::set('db', function () {
$mysqlMasterConfig = $this->_config->mysql->master->toArray();
$adapter = new Adapter($mysqlMasterConfig);
$connect = $adapter->getDriver()->getConnection();
for ($i = 0; $i < 5; $i++) {
if ($connect->isConnected()) {
break;
}
$connect->connect();
}
return $adapter;
});
// 郵件
Registry::set('mail', function () {
$options = new SmtpOptions($this->_config->smtp->toArray());
$mail = new SmtpTransport();
$mail->setOptions($options);
return $mail;
});
// 日誌
Registry::set('logger', function () {
$logger = new Zend\Log\Logger();
$writer = new Zend\Log\Writer\Stream($this->_config->log->path . '/' . date("Ymd") . ".log");
$logger->addWriter($writer);
return $logger;
});
}