Skip to content

Commit

Permalink
fix symfony 5 requirement to be specific when fetching either scalar …
Browse files Browse the repository at this point in the history
…or array inputs
  • Loading branch information
nkissebe committed Feb 12, 2025
1 parent 054bad8 commit a9ff466
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions core/libraries/Hubzero/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ public function getVar($key, $default = null, $hash = 'input', $type = 'none', $
switch ($hash)
{
case 'server':
return $this->server($key, $default);
return $this->server($key, $default, $type);
break;

case 'cookie':
return $this->cookie($key, $default);
return $this->cookie($key, $default, $type);
break;

case 'files':
Expand Down Expand Up @@ -164,15 +164,15 @@ public function getVar($key, $default = null, $hash = 'input', $type = 'none', $
break;

case 'post':
return $this->request($key, $default);
return $this->request($key, $default, $type);
break;

case 'get':
return $this->query($key, $default);
return $this->query($key, $default, $type);
break;

default:
return $this->input($key, $default);
return $this->input($key, $default, $type);
break;
}
}
Expand Down Expand Up @@ -283,7 +283,7 @@ public function getCmd($key = null, $default = null, $hash = 'input')
*/
public function getArray($key = null, $default = array(), $hash = 'input')
{
return (array) $this->getVar($key, $default, $hash);
return (array) $this->getVar($key, $default, $hash, 'array');
}

/**
Expand Down Expand Up @@ -537,9 +537,9 @@ protected function getInputSource()
* @param mixed $default
* @return string
*/
public function request($key = null, $default = null)
public function request($key = null, $default = null, $type = null)
{
return $this->retrieveItem('request', $key, $default);
return $this->retrieveItem('request', $key, $default, $type);
}

/**
Expand All @@ -549,9 +549,9 @@ public function request($key = null, $default = null)
* @param mixed $default
* @return string
*/
public function query($key = null, $default = null)
public function query($key = null, $default = null, $type = null)
{
return $this->retrieveItem('query', $key, $default);
return $this->retrieveItem('query', $key, $default, $type);
}

/**
Expand All @@ -561,9 +561,9 @@ public function query($key = null, $default = null)
* @param mixed $default
* @return string
*/
public function cookie($key = null, $default = null)
public function cookie($key = null, $default = null, $type = null)
{
return $this->retrieveItem('cookies', $key, $default);
return $this->retrieveItem('cookies', $key, $default, $type);
}

/**
Expand Down Expand Up @@ -597,9 +597,9 @@ public function file($key = null, $default = null)
* @param mixed $default
* @return string
*/
public function header($key = null, $default = null)
public function header($key = null, $default = null, $type = null)
{
return $this->retrieveItem('headers', $key, $default);
return $this->retrieveItem('headers', $key, $default, $type);
}

/**
Expand All @@ -609,9 +609,9 @@ public function header($key = null, $default = null)
* @param mixed $default
* @return string
*/
public function server($key = null, $default = null)
public function server($key = null, $default = null, $type = null)
{
return $this->retrieveItem('server', $key, $default);
return $this->retrieveItem('server', $key, $default, $type);
}

/**
Expand All @@ -622,14 +622,28 @@ public function server($key = null, $default = null)
* @param mixed $default
* @return string
*/
protected function retrieveItem($source, $key, $default)
protected function retrieveItem($source, $key, $default, $type = null)
{
if (is_null($key))
{
return $this->$source->all();
}

return $this->$source->get($key, $default, true);
if ($type == 'array')
{
try
{
return $this->$source->all($key, $default, true);
}
catch (\Symfony\Component\HttpFoundation\Exception\BadRequestException $e)
{
return $default;
}
}
else
{
return $this->$source->get($key, $default, true);
}
}

/**
Expand Down

0 comments on commit a9ff466

Please sign in to comment.