|
@@ -73,24 +73,14 @@ class ParameterBag
|
|
|
/**
|
|
|
* Returns a parameter by name.
|
|
|
*
|
|
|
- * @param string $key The key
|
|
|
- * @param mixed $default The default value
|
|
|
+ * @param string $path The key
|
|
|
+ * @param mixed $default The default value
|
|
|
+ * @param boolean $deep
|
|
|
*/
|
|
|
- public function get($key, $default = null)
|
|
|
+ public function get($path, $default = null, $deep = false)
|
|
|
{
|
|
|
- return array_key_exists($key, $this->parameters) ? $this->parameters[$key] : $default;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Returns a parameter by name allowing to specify a path with arbitrary depth.
|
|
|
- *
|
|
|
- * @param string $path The path, e.g. foo[bar]
|
|
|
- * @param mixed $default The default value
|
|
|
- */
|
|
|
- public function getDeep($path, $default = null)
|
|
|
- {
|
|
|
- if (false === $pos = strpos($path, '[')) {
|
|
|
- return $this->get($path, $default);
|
|
|
+ if (!$deep || false === $pos = strpos($path, '[')) {
|
|
|
+ return array_key_exists($path, $this->parameters) ? $this->parameters[$path] : $default;
|
|
|
}
|
|
|
|
|
|
$root = substr($path, 0, $pos);
|
|
@@ -172,52 +162,56 @@ class ParameterBag
|
|
|
/**
|
|
|
* Returns the alphabetic characters of the parameter value.
|
|
|
*
|
|
|
- * @param string $key The parameter key
|
|
|
- * @param mixed $default The default value
|
|
|
+ * @param string $key The parameter key
|
|
|
+ * @param mixed $default The default value
|
|
|
+ * @param boolean $deep
|
|
|
*
|
|
|
* @return string The filtered value
|
|
|
*/
|
|
|
- public function getAlpha($key, $default = '')
|
|
|
+ public function getAlpha($key, $default = '', $deep = false)
|
|
|
{
|
|
|
- return preg_replace('/[^[:alpha:]]/', '', $this->get($key, $default));
|
|
|
+ return preg_replace('/[^[:alpha:]]/', '', $this->get($key, $default, $deep));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Returns the alphabetic characters and digits of the parameter value.
|
|
|
*
|
|
|
- * @param string $key The parameter key
|
|
|
- * @param mixed $default The default value
|
|
|
+ * @param string $key The parameter key
|
|
|
+ * @param mixed $default The default value
|
|
|
+ * @param boolean $deep
|
|
|
*
|
|
|
* @return string The filtered value
|
|
|
*/
|
|
|
- public function getAlnum($key, $default = '')
|
|
|
+ public function getAlnum($key, $default = '', $deep = false)
|
|
|
{
|
|
|
- return preg_replace('/[^[:alnum:]]/', '', $this->get($key, $default));
|
|
|
+ return preg_replace('/[^[:alnum:]]/', '', $this->get($key, $default, $deep));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Returns the digits of the parameter value.
|
|
|
*
|
|
|
- * @param string $key The parameter key
|
|
|
- * @param mixed $default The default value
|
|
|
+ * @param string $key The parameter key
|
|
|
+ * @param mixed $default The default value
|
|
|
+ * @param boolean $deep
|
|
|
*
|
|
|
* @return string The filtered value
|
|
|
*/
|
|
|
- public function getDigits($key, $default = '')
|
|
|
+ public function getDigits($key, $default = '', $deep = false)
|
|
|
{
|
|
|
- return preg_replace('/[^[:digit:]]/', '', $this->get($key, $default));
|
|
|
+ return preg_replace('/[^[:digit:]]/', '', $this->get($key, $default, $deep));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Returns the parameter value converted to integer.
|
|
|
*
|
|
|
- * @param string $key The parameter key
|
|
|
- * @param mixed $default The default value
|
|
|
+ * @param string $key The parameter key
|
|
|
+ * @param mixed $default The default value
|
|
|
+ * @param boolean $deep
|
|
|
*
|
|
|
* @return string The filtered value
|
|
|
*/
|
|
|
- public function getInt($key, $default = 0)
|
|
|
+ public function getInt($key, $default = 0, $deep = false)
|
|
|
{
|
|
|
- return (int) $this->get($key, $default);
|
|
|
+ return (int) $this->get($key, $default, $deep);
|
|
|
}
|
|
|
}
|