本文整理汇总了PHP中Zend_Session_Namespace::setExpirationHops方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Session_Namespace::setExpirationHops方法的具体用法?PHP Zend_Session_Namespace::setExpirationHops怎么用?PHP Zend_Session_Namespace::setExpirationHops使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Session_Namespace
的用法示例。
在下文中一共展示了Zend_Session_Namespace::setExpirationHops方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setExpirationHops
/**
* Set redirect expiration hops
*
* @param integer $hops
*/
public function setExpirationHops($hops = 1)
{
// Store setting
$this->_expirationHops[$this->getNamespace()] = $hops;
// Set hops
self::$_session->setExpirationHops((int) $hops, $this->getNamespace());
}
示例2: _initSes
/**
* Initialize session
*/
protected function _initSes()
{
$ses = new \Zend_Session_Namespace(self::SESSION_NAMESPACE, true);
$ses->setExpirationHops(5, null, true);
$ses->setExpirationSeconds(60 * 60 * 24);
$this->_ses = $ses;
}
示例3: getStorage
/**
* Return checkout data storage
*
* @return Zend_Session_Namespace
*/
public function getStorage()
{
if (null === $this->_storage) {
$this->_storage = Axis::session($this->_code . '-Checkout');
$this->_storage->setExpirationSeconds(600);
$this->_storage->setExpirationHops(5);
}
return $this->_storage;
}
示例4: getStorage
/**
* Return checkout data storage
*
* @return Zend_Session_Namespace
*/
public function getStorage()
{
if (null === $this->_storage) {
$this->_storage = new Zend_Session_Namespace($this->_code . '-Checkout');
$this->_storage->setExpirationSeconds(600);
$this->_storage->setExpirationHops(5);
}
return $this->_storage;
}
示例5: getSession
/**
* Get session object
*
* @return Zend_Session_Namespace
*/
public function getSession()
{
if (!isset($this->_session) || null === $this->_session) {
$id = $this->getId();
$this->_session = new $this->_sessionClass('Zend_Form_Captcha_' . $id);
$this->_session->setExpirationHops(1, null, true);
$this->_session->setExpirationSeconds($this->getTimeout());
}
return $this->_session;
}
示例6: addMessage
/**
* addMessage() - Add a message to flash message
*
* @param string $message
* @param string $namespace OPTIONAL
*/
public function addMessage($message, $namespace = null)
{
$namespace = isset($namespace) ? (string) $namespace : $this->_namespace;
if (self::$_messageAdded === false) {
self::$_sessionNamespace->setExpirationHops(1, null, true);
}
if (!is_array(self::$_sessionNamespace->{$namespace})) {
self::$_sessionNamespace->{$namespace} = array();
}
self::$_sessionNamespace->{$namespace}[] = $message;
return;
}
示例7: indexAction
public function indexAction()
{
//$this->_helper->layout ()->disableLayout ();
$auth = Zend_Auth::getInstance();
$authContent = $auth->getStorage()->read();
$authAcl = new Zend_Session_Namespace('authAcl');
$guestID = Authz_Resource_Acl_Guest::GUEST_ID;
if (is_array($authContent) and $authContent['identity'] != $guestID) {
return;
}
$loginForm = new Auth_Form_Auth_Login($_POST);
$authAdapter = null;
if ($this->getRequest()->isPost() and $loginForm->isValid($_POST)) {
$authService = 'DbTable';
switch (strtolower($authService)) {
case 'dbtable':
$db = $this->_getParam('db');
$authAdapter = new Zend_Auth_Adapter_DbTable($db, 'auth_user', 'user_id', 'sec_passwd');
$authAdapter->setIdentity($loginForm->getValue('username'));
$authAdapter->setCredential($loginForm->getValue('password'));
break;
case 'ldap':
/*TODO Implement LDAP auth */
break;
default:
throw new Zend_Exception('Unknown authentication service -> ' . $authService, Zend_Log::ALERT);
}
$result = Zend_Auth::getInstance()->authenticate($authAdapter);
//$this->_helper->logger->debug ( $result );
switch ($result->getCode()) {
case Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND:
case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID:
break;
case Zend_Auth_Result::SUCCESS:
Zend_Session::regenerateId();
preg_match('/[^.]+\\.[^.]+$/', $_SERVER['SERVER_NAME'], $domain);
setcookie(self::AUTH_SID, Zend_Session::getId(), time() + 1200, self::AUTH_PATH, ".{$domain['0']}", null, true);
$last = time();
setcookie('last', $last, null, '/', ".{$domain['0']}", null, true);
$lastLogin = new Zend_Session_Namespace('last');
$lastLogin->lastLogin = $last;
$lastLogin->setExpirationHops(1, null, 1);
$authAcl = new Zend_Session_Namespace('authAcl');
$authAcl->authId = $loginForm->getValue('username');
$this->_helper->redirector('index', 'index');
return;
default:
/** do stuff for other failure **/
break;
}
}
$this->view->form = $loginForm;
}
示例8: getSession
/**
* Get session object
*
* @return Zend_Session_Namespace
*/
public function getSession()
{
if (!isset($this->_session) || null === $this->_session) {
$id = $this->getId();
if (!class_exists($this->_sessionClass)) {
#require_once 'Zend/Loader.php';
Zend_Loader::loadClass($this->_sessionClass);
}
$this->_session = new $this->_sessionClass('Zend_Form_Captcha_' . $id);
$this->_session->setExpirationHops(1, null, true);
$this->_session->setExpirationSeconds($this->getTimeout());
}
return $this->_session;
}
示例9: token
public function token($class = null, $element = null, $salt = null)
{
if (null === $class) {
$class = 'Zend_Form_Element_Hash';
}
if (null === $element) {
$element = 'token';
}
if (null === $salt) {
$salt = 'salt';
}
$session = new Zend_Session_Namespace($class . '_' . $salt . '_' . $element);
$session->setExpirationHops(1, null, true);
$session->setExpirationSeconds(300);
$session->hash = md5(mt_rand(1, 1000000) . $salt . $element . mt_rand(1, 1000000));
return $session->hash;
}
示例10: login
private function login($userName, $password)
{
$authService = 'DbTable';
switch (strtolower($authService)) {
case 'dbtable':
$db = $this->_getParam('db');
$authAdapter = new Zend_Auth_Adapter_DbTable($db, 'auth_user', 'login_id', 'sec_passwd');
$authAdapter->setIdentity($userName);
$authAdapter->setCredential($password);
break;
case 'ldap':
/*TODO Implement LDAP auth */
break;
default:
throw new Zend_Exception('Unknown authentication service -> ' . $authService, Zend_Log::ALERT);
}
$result = Zend_Auth::getInstance()->authenticate($authAdapter);
//$this->_helper->logger->debug ( $result );
switch ($result->getCode()) {
case Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND:
case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID:
echo 'Incorrect User Name or Password.';
break;
case Zend_Auth_Result::SUCCESS:
Zend_Session::regenerateId();
preg_match('/[^.]+\\.[^.]+$/', $_SERVER['SERVER_NAME'], $domain);
setcookie(self::AUTH_SID, Zend_Session::getId(), time() + 1200, self::AUTH_PATH, ".{$domain['0']}", null, true);
$last = time();
setcookie('last', $last, null, '/', ".{$domain['0']}", null, true);
$lastLogin = new Zend_Session_Namespace('last');
$lastLogin->lastLogin = $last;
$lastLogin->setExpirationHops(1, null, 1);
$authAcl = new Zend_Session_Namespace('authAcl');
$authAcl->authId = $userName;
//Zend_Registry::get('logger')->debug($authAcl->authId);
$this->_helper->redirector('markauth', 'index');
return;
default:
/** do stuff for other failure **/
break;
}
}
示例11: testSetExpireSessionVarsByHopsOnUse
/**
* test expiration of namespace variables by hops; expect expiration of specified keys in the proper number of hops
*
* @return void
*/
public function testSetExpireSessionVarsByHopsOnUse()
{
if (strtolower(substr(PHP_OS, 0, 3)) === 'win') {
$this->markTestIncomplete('Fails on Windows, see ZF-2629');
}
$s = new Zend_Session_Namespace('expireGuava');
$expireBeforeHop = 2;
$s->setExpirationHops($expireBeforeHop, 'g', true);
// only count a hop, when namespace is used
$s->g = 'guava';
$s->p = 'peach';
$s->p = 'plum';
$id = session_id();
session_write_close();
// release session so process below can use it
// we are not accessing (using) the "expireGuava" namespace, so these hops should have no effect
for ($i = 1; $i <= $expireBeforeHop + 2; $i++) {
exec("{$this->_script} expireAll {$id} notused", $result);
$result = $this->sortResult($result);
$this->assertTrue($result === '', "iteration over named Zend_Session namespace failed (result='{$result}'; hop #{$i})");
}
for ($i = 1; $i <= $expireBeforeHop + 2; $i++) {
exec("{$this->_script} expireAll {$id} expireGuava", $result);
$result = $this->sortResult($result);
if ($i > $expireBeforeHop) {
$expect = ';p === plum';
$this->assertTrue($result === $expect, "unexpected results iterating over named Zend_Session namespace (result='{$result}'; expected '{$expect}'; hop #{$i})");
} else {
$expect = ';g === guava;p === plum';
$this->assertTrue($result === $expect, "unexpected results iterating over named Zend_Session namespace (result='{$result}'; expected '{$expect}'; hop #{$i})");
}
}
session_start();
// resume artificially suspended session
Zend_Session::destroy();
}
示例12: contentAction
public function contentAction()
{
$this->view->messages = $this->_helper->flashMessenger->getMessages();
$url = $this->_getParam('url');
$proxy = new SxCms_Page_Proxy();
$page = $proxy->getPageByUrl($url, null, $this->_getParam('lng', 'nl'));
if ($page->getId() === false) {
throw new Zend_Controller_Action_Exception('Page not found', 404);
}
$identity = Zend_Auth::getInstance()->getIdentity();
if (!$page->isAllowed($identity)) {
$this->_forward('unauthorized', 'index', null, array('url' => $this->view->url()));
return;
}
if ($page->isExpired()) {
throw new Zend_Controller_Action_Exception('Page expired', 404);
}
if ($page->getInvisible()) {
throw new Zend_Controller_Action_Exception('Page expired', 404);
}
/** Gebruik Nederlandse vertaling indien nodig * */
if ($page->hasContentFallback()) {
$pageFallback = $proxy->getPageById($page->getId(), 'nl');
$page->setContent($pageFallback->getContent());
}
$this->view->page = $page;
$this->_helper->layout->setLayout($page->getLayout());
if ($page->getType() == SxCms_Page::SUMMARY) {
$children = $proxy->getPagesByParentId($page->getId(), null, $this->_getParam('lng', 'nl'), true, true);
$childrenArr = array();
foreach ($children as $child) {
$pageFallback = false;
if ($child->hasSummaryFallback()) {
$pageFallback = $proxy->getPageById($child->getId(), 'nl');
$child->setSummary($pageFallback->getSummary());
}
array_push($childrenArr, $child);
}
$this->view->children = $childrenArr;
$this->renderScript('index/summary.phtml');
return;
}
if ($page->getType() == SxCms_Page::ARTICLE) {
$this->view->comment = new SxCms_Comment();
$captchaSession = new Zend_Session_Namespace('captcha');
$captchaSession->setExpirationHops(3);
if ($captchaSession->token) {
$captcha = $captchaSession->token;
} else {
$captcha = new Zend_Captcha_Image();
$captcha->setName('captcha')->setWordLen(6)->setDotNoiseLevel(20)->setLineNoiseLevel(0)->setFont(APPLICATION_PATH . '/var/fonts/BRLNSR.TTF')->setImgDir(APPLICATION_ROOT . '/public_html/images/captcha');
$captcha->generate();
$captchaSession->token = $captcha;
}
$this->view->captcha = $captcha;
}
if ($page->getPageform()) {
if ($this->getRequest()->isGet()) {
$this->view->captchaId = $this->generateCaptcha();
}
$pageformproxy = new SxModule_Pageform_Proxy();
$subscription = new SxModule_Pageform_Subscription();
$pageform = $pageformproxy->getActiveById($page->getPageform(), $_SESSION['System']['lng']);
$this->view->pageform = $pageform;
if ($this->getRequest()->isPost() && $this->_getParam('comment-submit')) {
$this->view->errors = array();
$validator = new SxCms_Comment_BaseValidator();
$validator->setCaptcha($captcha)->setUserCaptcha($this->_getParam('captcha'));
$comment = new SxCms_Comment();
$comment->setMessage($this->_getParam('message'));
$author = new SxCms_Comment_Author();
$author->setName($this->_getParam('name'))->setEmail($this->_getParam('email'))->setWebsite($this->_getParam('website'));
$comment->setPage($page);
$comment->setCommenter($author);
if (!$validator->validate($comment)) {
$this->view->errors = $validator->getErrors();
$this->view->comment = $comment;
$this->view->userCaptcha = $this->_getParam('captcha');
} else {
$mapper = new SxCms_Comment_DataMapper();
$mapper->save($comment);
$captchaSession->unsetAll();
$this->_helper->flashMessenger->addMessage('Uw bericht werd succcesvol verwerk.
Na goedkeuring door een administrator zal dit op de website verschijnen.');
$this->_helper->redirector->gotoRoute(array('url' => $page->getLink()), 'content');
}
}
if ($this->getRequest()->isPost() && $this->_getParam('pageform-submit')) {
$data = $this->_getParam('pageform');
$subscription->setPageformId($pageform->getId())->setPageformname($pageform->getName())->setIp($this->getRequest()->getServer('REMOTE_ADDR'))->setAgent($this->getRequest()->getServer('HTTP_USER_AGENT'))->setLng($this->_getParam('lng'))->setUrl('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
foreach ($pageform->getField() as $field) {
if (isset($data[$field->getKey()])) {
# Tijd instellen
if ($field->getFieldType() == 'text' && $field->getValidation() == 'time' && is_array($data[$field->getKey()])) {
$data[$field->getKey()] = $data[$field->getKey()]['hh'] . ':' . $data[$field->getKey()]['mm'];
}
# Tijd & datum instellen
if ($field->getFieldType() == 'text' && $field->getValidation() == 'datetime' && is_array($data[$field->getKey()])) {
$data[$field->getKey()] = $data[$field->getKey()]['date'] . ' ' . $data[$field->getKey()]['hh'] . ':' . $data[$field->getKey()]['mm'];
}
//.........这里部分代码省略.........
示例13: _generateCsv
//.........这里部分代码省略.........
} else {
$parameters['headers'] = 'false';
}
$result = $this->_apply_xslt_and_save($filepath, $stylesheet, '', $parameters);
if ($result === NULL) {
$this->_helper->flashMessenger(__('Error when transforming xml file "%s" with the xsl sheet "%s".', $filepath, $stylesheet), 'error');
$this->_helper->redirector->goto('index');
}
$output = $result;
// @todo Use Zend/Omeka api.
$result = $this->_append_file($csvFilePath, $output);
if ($result === FALSE) {
$this->_helper->flashMessenger(__('Error saving data, because the filepath "%s" is not writable.', $filepath), 'error');
$this->_helper->redirector->goto('index');
}
}
// Check final resulted file.
if (filesize($csvFilePath) == 0) {
$this->_helper->flashMessenger(__('The conversion of the xml file "%s" to csv via the xslt style sheet "%s" gives an empty file. Check your options and your files.', basename($filepath), basename($stylesheet)), 'error');
$this->_helper->redirector->goto('index');
}
// Get the view.
$view = $this->view;
// Set up CsvImport validation and column mapping if needed.
$file = XmlImportPlugin::isFullCsvImport() ? new CsvImport_File($csvFilePath, $columnDelimiter, $enclosure) : new CsvImport_File($csvFilePath, $columnDelimiter);
if (!$file->parse()) {
$msg = __('Your CSV file is incorrectly formatted.') . ' ' . $file->getErrorString();
$this->_helper->flashMessenger($msg, 'error');
$this->_helper->redirector->goto('index');
}
// Go directly to the correct view of CsvImport plugin.
$csvImportSession = new Zend_Session_Namespace('CsvImport');
// @see CsvImport_IndexController::indexAction().
$csvImportSession->setExpirationHops(2);
$csvImportSession->originalFilename = $csvFilename;
$csvImportSession->filePath = $csvFilePath;
// Option used with full Csv Import only.
$csvImportSession->format = $format;
$csvImportSession->action = $action;
$csvImportSession->identifierField = $identifierField;
$csvImportSession->itemTypeId = $itemTypeId;
$csvImportSession->collectionId = $collectionId;
if (XmlImportPlugin::isFullCsvImport()) {
$csvImportSession->recordsArePublic = $recordsArePublic;
$csvImportSession->recordsAreFeatured = $recordsAreFeatured;
} else {
$csvImportSession->itemsArePublic = $recordsArePublic;
$csvImportSession->itemsAreFeatured = $recordsAreFeatured;
}
// Options used with full Csv Import only.
$csvImportSession->elementsAreHtml = $elementsAreHtml;
$csvImportSession->createCollections = $createCollections;
$csvImportSession->automapColumns = $automapColumns;
$csvImportSession->containsExtraData = $containsExtraData;
// Options used with Csv Import standard only.
$csvImportSession->automapColumnNamesToElements = $automapColumns;
$csvImportSession->columnDelimiter = $columnDelimiter;
$csvImportSession->enclosure = $enclosure;
$csvImportSession->columnNames = $file->getColumnNames();
$csvImportSession->columnExamples = $file->getColumnExamples();
// A bug appears in CsvImport when examples contain UTF-8 characters
// like 'ГЧ„чŁ'.
foreach ($csvImportSession->columnExamples as &$value) {
$value = iconv('ISO-8859-15', 'UTF-8', @iconv('UTF-8', 'ISO-8859-15' . '//IGNORE', $value));
}
$csvImportSession->elementDelimiter = $elementDelimiter;
示例14: testSetExpireSessionVarsByHopsOnUse
/**
* test expiration of namespace variables by hops; expect expiration of specified keys in the proper number of hops
*
* @runInSeparateProcess
* @return void
*/
public function testSetExpireSessionVarsByHopsOnUse()
{
$s = new Zend_Session_Namespace('expireGuava');
$expireBeforeHop = 2;
$s->setExpirationHops($expireBeforeHop, 'g', true);
// only count a hop, when namespace is used
$s->g = 'guava';
$s->p = 'peach';
$s->p = 'plum';
$id = session_id();
// we are not accessing (using) the "expireGuava" namespace, so these hops should have no effect
for ($i = 1; $i <= $expireBeforeHop + 2; $i++) {
session_write_close();
// release session so process below can use it
exec("{$this->_script} expireAll {$id} notused", $result);
session_start();
// resume artificially suspended session
$result = $this->sortResult($result);
$this->assertTrue($result === '', "iteration over named Zend_Session namespace failed (result='{$result}'; hop #{$i})");
}
for ($i = 1; $i <= $expireBeforeHop + 2; $i++) {
session_write_close();
// release session so process below can use it
exec("{$this->_script} expireAll {$id} expireGuava", $result);
session_start();
// resume artificially suspended session
$result = $this->sortResult($result);
if ($i > $expireBeforeHop) {
$expect = ';p === plum';
$this->assertTrue($result === $expect, "unexpected results iterating over named Zend_Session namespace (result='{$result}'; expected '{$expect}'; hop #{$i})");
} else {
$expect = ';g === guava;p === plum';
$this->assertTrue($result === $expect, "unexpected results iterating over named Zend_Session namespace (result='{$result}'; expected '{$expect}'; hop #{$i})");
}
}
// Do not destroy session since it still may be used by other tests
// Zend_Session::destroy();
}
示例15: addAction
/**
* Add a comment
*
* @return void
*/
public function addAction()
{
/**
* @var $request Zend_Controller_Request_Http
*/
$request = $this->getRequest();
// Retrieve id of commented object
$pid = intval($request->getParam('pid'));
$ns = new Zend_Session_Namespace('Comment_CommentsController');
$ns->setExpirationHops(1);
$form = new Comment_Form_Comment();
if (isset($ns->commentFormData)) {
$form->setDefaults($ns->commentFormData);
foreach ($ns->commentFormErrorsMessages as $elementName => $error) {
$form->getElement($elementName)->addErrors($error);
}
}
$fromRoute = Zend_Controller_Front::getInstance()->getRouter()->getCurrentRouteName();
$toRoute = $this->urlHelper->url();
if ('comment_add' !== $fromRoute) {
$ns->commentFromRoute = $fromRoute;
$toRoute = $toRoute . '/comment';
}
$form->setAction($toRoute);
if ($request->isPost()) {
$parentModel = new $this->_parentModelClass();
$parentObject = $parentModel->find($pid)->current();
if (!$parentObject) {
throw new Zend_Controller_Action_Exception('Unable to find commented object in database', 500);
}
if ($form->isValid($request->getParam('commentForm'))) {
$commentsModel = new Comment_Model_DbTable_Comment();
$data = $form->getValues(true);
$data['pid'] = $pid;
$identity = Zend_Auth::getInstance();
if ($identity->hasIdentity()) {
$data['uid'] = $identity->getIdentity()->uid;
$data['name'] = $identity->getIdentity()->username;
$data['email'] = $identity->getIdentity()->email;
}
$data['created_on'] = time();
$commentsModel->insert($data);
} else {
$ns->commentFormData = $form->getValues();
$ns->commentFormErrorsMessages = $form->getMessages(null, true);
}
$this->_redirect($this->urlHelper->url(array('pid' => $pid), $ns->commentFromRoute));
}
$this->view->assign('form', $form);
}