$t->is($ph->getAll(), $parameters, '->getAll() returns all parameters'); // ->has() $t->diag('->has()'); $ph = new sfParameterHolder(); $ph->set('foo', 'bar'); $t->is($ph->has('foo'), true, '->has() returns true if the key exists'); $t->is($ph->has('bar'), false, '->has() returns false if the key does not exist'); $ph->set('bar', null); $t->is($ph->has('bar'), true, '->has() returns true if the key exist, even if the value is null'); // ->remove() $t->diag('->remove()'); $ph = new sfParameterHolder(); $ph->set('foo', 'bar'); $ph->set('myfoo', 'bar'); $ph->remove('foo'); $t->is($ph->has('foo'), false, '->remove() removes the key from parameters'); $ph->remove('myfoo'); $t->is($ph->has('myfoo'), false, '->remove() removes the key from parameters'); $t->is($ph->remove('nonexistant', 'foobar'), 'foobar', '->remove() takes a default value as its second argument'); $t->is($ph->getAll(), null, '->remove() removes the key from parameters'); // ->set() $t->diag('->set()'); $foo = 'bar'; $ph = new sfParameterHolder(); $ph->set('foo', $foo); $t->is($ph->get('foo'), $foo, '->set() sets the value for a key'); $foo = 'foo'; $t->is($ph->get('foo'), 'bar', '->set() sets the value for a key, not a reference'); // ->setByRef() $t->diag('->setByRef()'); $foo = 'bar';
// ->add() $t->diag('->add()'); $foo = 'bar'; $parameters = array('foo' => $foo, 'bar' => 'bar'); $myparameters = array('myfoo' => 'bar', 'mybar' => 'bar'); $ph = new sfParameterHolder(); $ph->add($parameters); $t->is($ph->getAll(), $parameters, '->add() adds an array of parameters'); $foo = 'mybar'; $t->is($ph->getAll(), $parameters, '->add() adds an array of parameters, not a reference'); // ->addByRef() $t->diag('->addByRef()'); $foo = 'bar'; $parameters = array('foo' => &$foo, 'bar' => 'bar'); $myparameters = array('myfoo' => 'bar', 'mybar' => 'bar'); $ph = new sfParameterHolder(); $ph->addByRef($parameters); $t->is($parameters, $ph->getAll(), '->add() adds an array of parameters'); $foo = 'mybar'; $t->is($parameters, $ph->getAll(), '->add() adds a reference of an array of parameters'); // ->serialize() ->unserialize() $t->diag('->serialize() ->unserialize()'); $t->ok($ph == unserialize(serialize($ph)), 'sfParameterHolder implements the Serializable interface'); // Array path as a key $t->diag('Array path as a key'); $ph = new sfParameterHolder(); $ph->add(array('foo' => array('bar' => 'foo'))); $t->is($ph->has('foo[bar]'), true, '->has() can takes a multi-array key'); $t->is($ph->get('foo[bar]'), 'foo', '->has() can takes a multi-array key'); $t->is($ph->remove('foo[bar]'), 'foo', '->remove() can takes a multi-array key'); $t->is($ph->getAll(), array('foo' => array()), '->remove() can takes a multi-array key');
/** * Returns true if a request parameter exists. * * This is a proxy method equivalent to: * * <code>$this->getRequest()->getParameterHolder()->has($name)</code> * * @param string $name The parameter name * @return boolean true if the request parameter exists, false otherwise */ public function hasRequestParameter($name) { return $this->requestParameterHolder->has($name); }
public function has($name) { return parent::has($name) || $this->proxy_has($name); }
$ph->remove('foo'); $t->is($ph->has('foo'), false, '->remove() removes the key from parameters'); $ph->remove('myfoo'); $t->is($ph->has('myfoo'), false, '->remove() removes the key from parameters'); $t->is($ph->has('myfoo', 'symfony/mynamespace'), true, '->remove() removes the key from parameters for a given namespace'); $ph->remove('myfoo', 'symfony/mynamespace'); $t->is($ph->has('myfoo', 'symfony/mynamespace'), false, '->remove() takes a namespace as its second argument'); $t->is($ph->getAll(), null, '->remove() removes the key from parameters'); // ->removeNamespace() $t->diag('->removeNamespace()'); $ph = new sfParameterHolder(); $ph->set('foo', 'bar'); $ph->set('myfoo', 'bar'); $ph->set('myfoo', 'bar', 'symfony/mynamespace'); $ph->removeNamespace($ph->getDefaultNamespace()); $t->is($ph->has('foo'), false, '->removeNamespace() removes all keys and values from a namespace'); $t->is($ph->has('myfoo'), false, '->removeNamespace() removes all keys and values from a namespace'); $t->is($ph->has('myfoo', 'symfony/mynamespace'), true, '->removeNamespace() does not remove keys in other namepaces'); $ph->set('foo', 'bar'); $ph->set('myfoo', 'bar'); $ph->set('myfoo', 'bar', 'symfony/mynamespace'); $ph->removeNamespace(); $t->is($ph->has('foo'), false, '->removeNamespace() removes all keys and values from the default namespace by default'); $t->is($ph->has('myfoo'), false, '->removeNamespace() removes all keys and values from the default namespace by default'); $t->is($ph->has('myfoo', 'symfony/mynamespace'), true, '->removeNamespace() does not remove keys in other namepaces'); $ph->removeNamespace('symfony/mynamespace'); $t->is($ph->has('myfoo', 'symfony/mynamespace'), false, '->removeNamespace() takes a namespace as its first parameter'); $t->is(null, $ph->getAll(), '->removeNamespace() removes all the keys from parameters'); // ->set() $t->diag('->set()'); $foo = 'bar';