本文整理汇总了PHP中lithium\storage\Session::applyFilter方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::applyFilter方法的具体用法?PHP Session::applyFilter怎么用?PHP Session::applyFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lithium\storage\Session
的用法示例。
在下文中一共展示了Session::applyFilter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testReadFilter
public function testReadFilter()
{
Session::config(array('primary' => array('adapter' => new Memory(), 'filters' => array()), 'secondary' => array('adapter' => new Memory(), 'filters' => array())));
Session::applyFilter('read', function ($self, $params, $chain) {
$result = $chain->next($self, $params, $chain);
if (isset($params['options']['increment'])) {
$result += $params['options']['increment'];
}
return $result;
});
Session::write('foo', 'bar');
$this->assertEqual('bar', Session::read('foo'));
Session::write('bar', 1);
$this->assertEqual(2, Session::read('bar', array('increment' => 1)));
}
示例2: function
<?php
// Define used classes.
use lithium\util\collection\Filters;
use lithium\storage\Session;
// Get to the `Session` instance by filtering the `Dispatcher`
Filters::apply('\\lithium\\action\\Dispatcher', '_callable', function ($self, $params, $chain) {
$controller = $chain->next($self, $params, $chain);
Session::applyFilter('read', function ($self, $params, $chain) {
$profiler = \Profiler::start('storage\\Session::read');
$result = $chain->next($self, $params, $chain);
$profiler->end();
return $result;
});
Session::applyFilter('write', function ($self, $params, $chain) {
$profiler = \Profiler::start('storage\\Session::write');
$result = $chain->next($self, $params, $chain);
$profiler->end();
return $result;
});
// Return the controller object.
return $controller;
});