Elgg  Version 5.1
Request.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg;
4 
8 
12 class Request {
13 
17  private $http_request;
18 
22  private $dic;
23 
27  private $validation;
28 
35  public function __construct(PublicContainer $dic, HttpRequest $http_request) {
36  $this->http_request = $http_request;
37  $this->dic = $dic;
38  $this->validation = new ValidationResults();
39  }
40 
45  public function validation() {
46  return $this->validation;
47  }
48 
54  public function getRoute() {
55  return $this->getParam('_route');
56  }
57 
65  public function getParams($filter = true) {
66  return $this->http_request->getParams($filter);
67  }
68 
79  public function getParam($key, $default = null, $filter = true) {
80  return $this->http_request->getParam($key, $default, $filter);
81  }
82 
92  public function setParam($key, $value = null) {
93  $this->http_request->setParam($key, $value);
94  }
95 
103  public function getEntityParam(string $key = 'guid'): ?\ElggEntity {
104  $guid = (int) $this->http_request->getParam($key);
105  if (empty($guid)) {
106  return null;
107  }
108 
109  return get_entity($guid);
110  }
111 
119  public function getUserParam(string $key = 'user_guid'): ?\ElggUser {
120  $prop = $this->http_request->getParam($key);
121  if (elgg_is_empty($prop)) {
122  return null;
123  }
124 
125  if ($key === 'username') {
126  return elgg_get_user_by_username((string) $prop);
127  }
128 
129  return get_user((int) $prop);
130  }
131 
137  public function elgg() {
138  return $this->dic;
139  }
140 
145  public function getURL() {
146  return $this->http_request->getCurrentURL();
147  }
148 
153  public function getPath() {
154  return implode('/', $this->http_request->getUrlSegments());
155  }
156 
161  public function isXhr() {
162  return $this->http_request->isXmlHttpRequest();
163  }
164 
169  public function getMethod() {
170  return $this->http_request->getMethod();
171  }
172 
178  public function getHttpRequest() {
179  return $this->http_request;
180  }
181 }
$default
Definition: checkbox.php:30
getHttpRequest()
Get the HttpRequest for this request.
Definition: Request.php:178
getURL()
Get URL of the request.
Definition: Request.php:145
validation()
Access validation results bag.
Definition: Request.php:45
setParam($key, $value=null)
Set request parameter.
Definition: Request.php:92
elgg_get_user_by_username(string $username, bool $try_email=false)
Get a user by username.
Definition: users.php:39
__construct(PublicContainer $dic, HttpRequest $http_request)
Constructor.
Definition: Request.php:35
Represents a set of validated parameters.
getUserParam(string $key= 'user_guid')
Gets the "user" key from the params if it holds an Elgg user.
Definition: Request.php:119
getParams($filter=true)
Get the parameters from the request query and route matches.
Definition: Request.php:65
getParam($key, $default=null, $filter=true)
Get an element of the params array.
Definition: Request.php:79
isXhr()
Is the route access with XmlHttpRequest.
Definition: Request.php:161
$value
Definition: generic.php:51
elgg_is_empty($value)
Check if a value isn&#39;t empty, but allow 0 and &#39;0&#39;.
Definition: input.php:176
getMethod()
Get HTTP method of the request.
Definition: Request.php:169
getEntityParam(string $key= 'guid')
Gets the "entity" key from the params if it holds an Elgg entity.
Definition: Request.php:103
get_entity(int $guid)
Loads and returns an entity object from a guid.
Definition: entities.php:67
elgg()
Get the DI container.
Definition: Request.php:137
get_user(int $guid)
Elgg users Functions to manage multiple or single users in an Elgg install.
Definition: users.php:16
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:44
getRoute()
Get the name of the route.
Definition: Request.php:54
Request container.
Definition: Request.php:12
$filter
Layout body.
Definition: body.php:10
getPath()
Get relative path of the request.
Definition: Request.php:153
$guid
Reset an ElggUpgrade.
Definition: reset.php:6