mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-27 07:44:04 +02:00
lib: Add Request::getIsApiRequest()
If the Accept header is set to application/json it's an API request. refs #9660
This commit is contained in:
parent
3aae37aff3
commit
c23c7a5fa9
@ -7,24 +7,46 @@ use Zend_Controller_Request_Http;
|
|||||||
use Icinga\User;
|
use Icinga\User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request to handle special attributes
|
* A request
|
||||||
*/
|
*/
|
||||||
class Request extends Zend_Controller_Request_Http
|
class Request extends Zend_Controller_Request_Http
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* User object
|
* User if authenticated
|
||||||
*
|
*
|
||||||
* @var User
|
* @var User|null
|
||||||
*/
|
*/
|
||||||
private $user;
|
protected $user;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Unique identifier
|
||||||
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $uniqueId;
|
protected $uniqueId;
|
||||||
|
|
||||||
private $url;
|
/**
|
||||||
|
* Request URL
|
||||||
|
*
|
||||||
|
* @var Url
|
||||||
|
*/
|
||||||
|
protected $url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get whether the request seems to be an API request
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getIsApiRequest()
|
||||||
|
{
|
||||||
|
return $this->getHeader('Accept') === 'application/json';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the request URL
|
||||||
|
*
|
||||||
|
* @return Url
|
||||||
|
*/
|
||||||
public function getUrl()
|
public function getUrl()
|
||||||
{
|
{
|
||||||
if ($this->url === null) {
|
if ($this->url === null) {
|
||||||
@ -34,31 +56,38 @@ class Request extends Zend_Controller_Request_Http
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setter for user
|
* Get the user if authenticated
|
||||||
*
|
*
|
||||||
* @param User $user
|
* @return User|null
|
||||||
*/
|
|
||||||
public function setUser(User $user)
|
|
||||||
{
|
|
||||||
$this->user = $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Getter for user
|
|
||||||
*
|
|
||||||
* @return User
|
|
||||||
*/
|
*/
|
||||||
public function getUser()
|
public function getUser()
|
||||||
{
|
{
|
||||||
return $this->user;
|
return $this->user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the authenticated user
|
||||||
|
*
|
||||||
|
* @param User $user
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setUser(User $user)
|
||||||
|
{
|
||||||
|
$this->user = $user;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes an ID unique to this request, to prevent id collisions in different containers
|
* Makes an ID unique to this request, to prevent id collisions in different containers
|
||||||
*
|
*
|
||||||
* Call this whenever an ID might show up multiple times in different containers. This function is useful
|
* Call this whenever an ID might show up multiple times in different containers. This function is useful
|
||||||
* for ensuring unique ids on sites, even if we combine the HTML of different requests into one site,
|
* for ensuring unique ids on sites, even if we combine the HTML of different requests into one site,
|
||||||
* while still being able to reference elements uniquely in the same request.
|
* while still being able to reference elements uniquely in the same request.
|
||||||
|
*
|
||||||
|
* @param string $id
|
||||||
|
*
|
||||||
|
* @return string The id suffixed w/ an identifier unique to this request
|
||||||
*/
|
*/
|
||||||
public function protectId($id)
|
public function protectId($id)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user