/** * Tests read and write * * @author Kamil Skowron <*****@*****.**> * @since 2015-07-17 */ public function testBagGetAndSet() { $this->specify("Session bag incorrectly handling writing and reading", function () { @session_start(); // Using getters and setters $bag = new Bag('test1'); $bag->set('a', ['b' => 'c']); expect($bag->get('a'))->equals(['b' => 'c']); expect($_SESSION['test1']['a'])->same(['b' => 'c']); // Using direct access $bag = new Bag('test2'); $bag->{'a'} = ['b' => 'c']; expect($bag->{'a'})->equals(['b' => 'c']); expect($_SESSION['test2']['a'])->same(['b' => 'c']); @session_destroy(); }); }
/** * {@inheritdoc} */ public function get($property) { return $this->storage->get($property); }
/** * Get all value filter * * @return array Array value filter when coder use function addFilter */ public function getFilter() { $sessionBagKey = $this->_module . '_' . $this->_controller . '_' . $this->_action . '_filter'; $filterSessionGlobal = new SessionBag('ZCMS_GB_FILTER'); $filterSession = []; if ($filterSessionGlobal->has($sessionBagKey)) { $filterSession = $filterSessionGlobal->get($sessionBagKey); } if (count($this->_filterOptions)) { foreach ($this->_filterOptions as $key => $item) { if ($item['method'] == 'POST') { $this->_filter[$key] = $this->request->getPost($key, $item['type']); if ($this->_filter[$key] == null && $this->_filter[$key] !== $item['value']) { if (array_key_exists($key, $filterSession) && $filterSession[$key] != null) { $this->_filter[$key] = $filterSession[$key]; } else { $this->_filter[$key] = $item['value']; } } } else { $this->_filter[$key] = $this->request->getQuery($key, $item['type']); if ($this->_filter[$key] == null && $this->_filter[$key] !== $item['value']) { if (array_key_exists($key, $filterSession) && $filterSession[$key] != null) { $this->_filter[$key] = $filterSession[$key]; } else { $this->_filter[$key] = $item['value']; } } } } } $filterSessionGlobal->set($sessionBagKey, $this->_filter); return $this->_filter; }