/** * Returns a key's value from this bag's data * * @param string $key * @param mixed $default * * @return mixed */ public function get($key, $default = null) { // check if we have this key if (parent::has($this->prefixKey($key))) { // do we have expiry information? if (!isset($this->data[static::EXPIRE_DATA_KEY][$key])) { // nope, simply return the data return parent::get($this->prefixKey($key), $default); } // return the data if we don't have expiry information or if the data is valid if ($this->data[static::EXPIRE_DATA_KEY][$key][1] !== static::EXPIRE_STATE_EXPIRED) { // check the expiry strategy if ($this->data[static::EXPIRE_DATA_KEY][$key][0] === EXPIRE_ON_GET) { // expire on get, so expire it $this->data[static::EXPIRE_DATA_KEY][$key][1] = static::EXPIRE_STATE_EXPIRED; } // return the data return parent::get($this->prefixKey($key), $default); } } // no dice, return the default return $default; }
/** * Checks if a key was set upon this bag's data * * @param string $key * * @return boolean */ public function has($key) { return parent::has($this->prefixKey($key)); }
/** * @group Common */ public function testIteratorAggregate() { $c = new DataContainer(array('some' => 'value', 'is' => 'this')); foreach ($c as $key => $value) { $this->assertTrue($c->has($key)); $this->assertEquals($value, $c[$key]); } }