public function ParameterBag::get in Zircon Profile 8.0
Same name in this branch
- 8.0 vendor/symfony/http-foundation/ParameterBag.php \Symfony\Component\HttpFoundation\ParameterBag::get()
- 8.0 vendor/symfony/dependency-injection/ParameterBag/ParameterBag.php \Symfony\Component\DependencyInjection\ParameterBag\ParameterBag::get()
Same name and namespace in other branches
- 8 vendor/symfony/http-foundation/ParameterBag.php \Symfony\Component\HttpFoundation\ParameterBag::get()
Returns a parameter by name.
Parameters
string $path The key:
mixed $default The default value if the parameter key does not exist:
bool $deep If true, a path like foo[bar] will find deeper items:
Return value
mixed
Throws
\InvalidArgumentException
4 calls to ParameterBag::get()
- ParameterBag::filter in vendor/
symfony/ http-foundation/ ParameterBag.php - Filter key.
- ParameterBag::getAlnum in vendor/
symfony/ http-foundation/ ParameterBag.php - Returns the alphabetic characters and digits of the parameter value.
- ParameterBag::getAlpha in vendor/
symfony/ http-foundation/ ParameterBag.php - Returns the alphabetic characters of the parameter value.
- ParameterBag::getInt in vendor/
symfony/ http-foundation/ ParameterBag.php - Returns the parameter value converted to integer.
File
- vendor/
symfony/ http-foundation/ ParameterBag.php, line 89
Class
- ParameterBag
- ParameterBag is a container for key/value pairs.
Namespace
Symfony\Component\HttpFoundationCode
public function get($path, $default = null, $deep = false) {
if (!$deep || false === ($pos = strpos($path, '['))) {
return array_key_exists($path, $this->parameters) ? $this->parameters[$path] : $default;
}
$root = substr($path, 0, $pos);
if (!array_key_exists($root, $this->parameters)) {
return $default;
}
$value = $this->parameters[$root];
$currentKey = null;
for ($i = $pos, $c = strlen($path); $i < $c; ++$i) {
$char = $path[$i];
if ('[' === $char) {
if (null !== $currentKey) {
throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "[" at position %d.', $i));
}
$currentKey = '';
}
elseif (']' === $char) {
if (null === $currentKey) {
throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "]" at position %d.', $i));
}
if (!is_array($value) || !array_key_exists($currentKey, $value)) {
return $default;
}
$value = $value[$currentKey];
$currentKey = null;
}
else {
if (null === $currentKey) {
throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "%s" at position %d.', $char, $i));
}
$currentKey .= $char;
}
}
if (null !== $currentKey) {
throw new \InvalidArgumentException(sprintf('Malformed path. Path must end with "]".'));
}
return $value;
}