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))); }
<?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; });