Archived
1
0
Fork 0

app/models/Data/RequestMeta.php: adding getUriQuery()

This commit is contained in:
Henrik Hautakoski 2018-03-18 12:33:55 +01:00
parent 51a2675366
commit 0aa1107797

View file

@ -25,6 +25,13 @@ class RequestMeta extends Model
*/
protected $uri;
/**
* Cached query parameters from request uri.
*
* @var array|null
*/
protected $_uri_query = null;
/**
*
* @var string
@ -72,6 +79,19 @@ class RequestMeta extends Model
return $this;
}
/**
* @param string $uri
* @return RequestMeta
*/
public function setUri($uri)
{
$this->uri = (string) $uri;
// New uri string, invalidate query.
$this->_uri_query = null;
return $this;
}
/**
* @return string
*/
@ -81,15 +101,28 @@ class RequestMeta extends Model
}
/**
* @param string $uri
* @return RequestMeta
* @return array
*/
public function setUri($uri)
public function getUriQuery()
{
$this->uri = (string) $uri;
return $this;
if ($this->_uri_query === null) {
$query = (string) parse_url($this->getUri(), PHP_URL_QUERY);
$ret = array();
foreach(explode('&', $query) as $v) {
@list($k, $v) = explode('=', $v, 2);
if (strlen($k) > 0) {
$ret[$k] = $v;
}
}
$this->_uri_query = $ret;
}
return $this->_uri_query;
}
/**
* Method to set the value of field Timestamp
*