/**
  * Indicates whether or not a parameter exists.
  *
  * @param  string $name  A parameter name
  *
  * @return bool true, if the parameter exists, otherwise false
  */
 public function has($name)
 {
     if (array_key_exists($name, $this->parameters)) {
         return true;
     } else {
         return sfToolkit::hasArrayValueForPath($this->parameters, $name);
     }
     return false;
 }
 /**
  * Indicates whether or not a parameter exists.
  *
  * @param  string $name  A parameter name
  *
  * @return bool true, if the parameter exists, otherwise false
  */
 public function has($name)
 {
     if (isset($this->parameters[$name])) {
         return true;
     } else {
         return sfToolkit::hasArrayValueForPath($this->parameters, $name);
     }
     return false;
 }
 public function has($name, $ns = null)
 {
     if (!$ns) {
         $ns = $this->default_namespace;
     }
     if (isset($this->parameters[$ns][$name])) {
         return true;
     } else {
         if (isset($this->parameters[$ns])) {
             return sfToolkit::hasArrayValueForPath($this->parameters[$ns], $name);
         }
     }
     return false;
 }
Example #4
0
$t->diag('::hasArrayValueForPath()');

$t->is(sfToolkit::hasArrayValueForPath($arr, 'foobar'), true, '::hasArrayValueForPath() returns true if the path exists');
$t->is(sfToolkit::hasArrayValueForPath($arr, 'barfoo'), false, '::hasArrayValueForPath() returns false if the path does not exist');

$t->is(sfToolkit::hasArrayValueForPath($arr, 'foo[bar][baz]'), true, '::hasArrayValueForPath() works with deep paths');
$t->is(sfToolkit::hasArrayValueForPath($arr, 'foo[bar][bar]'), false, '::hasArrayValueForPath() works with deep paths');

$t->is(sfToolkit::hasArrayValueForPath($arr, 'foo[]'), true, '::hasArrayValueForPath() accepts a [] at the end to check for an array');
$t->is(sfToolkit::hasArrayValueForPath($arr, 'foobar[]'), false, '::hasArrayValueForPath() accepts a [] at the end to check for an array');
$t->is(sfToolkit::hasArrayValueForPath($arr, 'barfoo[]'), false, '::hasArrayValueForPath() accepts a [] at the end to check for an array');

$t->is(sfToolkit::hasArrayValueForPath($arr, 'bar[1]'), true, '::hasArrayValueForPath() can take an array indexed by integer');
$t->is(sfToolkit::hasArrayValueForPath($arr, 'bar[2]'), false, '::hasArrayValueForPath() can take an array indexed by integer');

$t->is(sfToolkit::hasArrayValueForPath($arr, 'foo[bar][baz][booze]'), false, '::hasArrayValueForPath() is not fooled by php mistaking strings and array');

// ::getArrayValueForPath()
$t->diag('::getArrayValueForPath()');

$t->is(sfToolkit::getArrayValueForPath($arr, 'foobar'), 'foo', '::getArrayValueForPath() returns the value of the path if it exists');
$t->is(sfToolkit::getArrayValueForPath($arr, 'barfoo'), null, '::getArrayValueForPath() returns null if the path does not exist');
$t->is(sfToolkit::getArrayValueForPath($arr, 'barfoo', 'bar'), 'bar', '::getArrayValueForPath() takes a default value as its third argument');

$t->is(sfToolkit::getArrayValueForPath($arr, 'foo[bar][baz]'), 'foo bar', '::getArrayValueForPath() works with deep paths');
$t->is(sfToolkit::getArrayValueForPath($arr, 'foo[bar][bar]'), false, '::getArrayValueForPath() works with deep paths');
$t->is(sfToolkit::getArrayValueForPath($arr, 'foo[bar][bar]', 'bar'), 'bar', '::getArrayValueForPath() works with deep paths');

$t->is(sfToolkit::getArrayValueForPath($arr, 'foo[]'), array('bar' => array('baz' => 'foo bar')), '::getArrayValueForPath() accepts a [] at the end to check for an array');
$t->is(sfToolkit::getArrayValueForPath($arr, 'foobar[]'), null, '::getArrayValueForPath() accepts a [] at the end to check for an array');
$t->is(sfToolkit::getArrayValueForPath($arr, 'barfoo[]'), null, '::getArrayValueForPath() accepts a [] at the end to check for an array');
 protected function hasValue($values, $name)
 {
     if (array_key_exists($name, $values)) {
         return true;
     }
     return sfToolkit::hasArrayValueForPath($values, $name);
 }