Elgg  Version 3.0
Request.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg;
4 
9 
13 class Request {
14 
18  private $http_request;
19 
23  private $dic;
24 
28  private $validation;
29 
36  public function __construct(PublicContainer $dic, HttpRequest $http_request) {
37  $this->http_request = $http_request;
38  $this->dic = $dic;
39  $this->validation = new ValidationResults();
40  }
41 
46  public function validation() {
47  return $this->validation;
48  }
49 
55  public function getRoute() {
56  return $this->getParam('_route');
57  }
58 
66  public function getParams($filter = true) {
67  return $this->http_request->getParams($filter);
68  }
69 
80  public function getParam($key, $default = null, $filter = true) {
81  return $this->http_request->getParam($key, $default, $filter);
82  }
83 
93  public function setParam($key, $value = null) {
94  $this->http_request->setParam($key, $value);
95  }
96 
104  public function getEntityParam($key = 'guid') {
105  $guid = $this->http_request->getParam($key);
106  if ($guid) {
108  if ($entity instanceof \ElggEntity) {
109  return $entity;
110  }
111  }
112 
113  return null;
114  }
115 
123  public function getUserParam($key = 'user_guid') {
124  $prop = $this->http_request->getParam($key);
125  if ($key === 'username') {
126  $entity = get_user_by_username($prop);
127 
128  return $entity ? : null;
129  }
130 
131  if ($prop) {
132  $entity = get_entity($prop);
133  if ($entity instanceof \ElggUser) {
134  return $entity;
135  }
136  }
137 
138  return null;
139  }
140 
146  public function elgg() {
147  return $this->dic;
148  }
149 
154  public function getURL() {
155  return $this->http_request->getCurrentURL();
156  }
157 
162  public function getPath() {
163  return implode('/', $this->http_request->getUrlSegments());
164  }
165 
170  public function isXhr() {
171  return $this->http_request->isXmlHttpRequest();
172  }
173 
178  public function getMethod() {
179  return $this->http_request->getMethod();
180  }
181 
182 }
getURL()
Get URL of the request.
Definition: Request.php:154
validation()
Access validation results bag.
Definition: Request.php:46
setParam($key, $value=null)
Set request parameter.
Definition: Request.php:93
__construct(PublicContainer $dic, HttpRequest $http_request)
Constructor.
Definition: Request.php:36
getEntityParam($key= 'guid')
Gets the "entity" key from the params if it holds an Elgg entity.
Definition: Request.php:104
Represents a set of validated parameters.
$guid
Removes an admin notice.
getParams($filter=true)
Get the parameters from the request query and route matches.
Definition: Request.php:66
getParam($key, $default=null, $filter=true)
Get an element of the params array.
Definition: Request.php:80
isXhr()
Is the route access with XmlHttpRequest.
Definition: Request.php:170
get_user_by_username($username)
Get user by username.
Definition: users.php:61
Configuration exception.
getMethod()
Get HTTP method of the request.
Definition: Request.php:178
$entity
Definition: reset.php:8
elgg()
Get the DI container.
Definition: Request.php:146
$default
Definition: checkbox.php:35
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:55
$value
Definition: debugging.php:7
getRoute()
Get the name of the route.
Definition: Request.php:55
Request container.
Definition: Request.php:13
$filter
Layout body.
Definition: body.php:18
getPath()
Get relative path of the request.
Definition: Request.php:162
getUserParam($key= 'user_guid')
Gets the "user" key from the params if it holds an Elgg user.
Definition: Request.php:123
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:87