Elgg  Version master
Request.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg;
4 
8 
12 class Request {
13 
17  protected $validation;
18 
25  public function __construct(protected PublicContainer $dic, protected HttpRequest $http_request) {
26  $this->validation = new ValidationResults();
27  }
28 
33  public function validation() {
34  return $this->validation;
35  }
36 
42  public function getRoute() {
43  return $this->getParam('_route');
44  }
45 
53  public function getParams($filter = true) {
54  return $this->http_request->getParams($filter);
55  }
56 
67  public function getParam($key, $default = null, $filter = true) {
68  return $this->http_request->getParam($key, $default, $filter);
69  }
70 
80  public function setParam($key, $value = null) {
81  $this->http_request->setParam($key, $value);
82  }
83 
91  public function getEntityParam(string $key = 'guid'): ?\ElggEntity {
92  $guid = (int) $this->http_request->getParam($key);
93  if (empty($guid)) {
94  return null;
95  }
96 
97  return get_entity($guid);
98  }
99 
107  public function getUserParam(string $key = 'user_guid'): ?\ElggUser {
108  $prop = $this->http_request->getParam($key);
109  if (elgg_is_empty($prop)) {
110  return null;
111  }
112 
113  if ($key === 'username') {
114  return elgg_get_user_by_username((string) $prop);
115  }
116 
117  return get_user((int) $prop);
118  }
119 
125  public function elgg() {
126  return $this->dic;
127  }
128 
133  public function getURL() {
134  return $this->http_request->getCurrentURL();
135  }
136 
141  public function getPath() {
142  return implode('/', $this->http_request->getUrlSegments());
143  }
144 
149  public function isXhr() {
150  return $this->http_request->isXmlHttpRequest();
151  }
152 
157  public function getMethod() {
158  return $this->http_request->getMethod();
159  }
160 
166  public function getHttpRequest() {
167  return $this->http_request;
168  }
169 }
$default
Definition: checkbox.php:30
getHttpRequest()
Get the HttpRequest for this request.
Definition: Request.php:166
getURL()
Get URL of the request.
Definition: Request.php:133
validation()
Access validation results bag.
Definition: Request.php:33
setParam($key, $value=null)
Set request parameter.
Definition: Request.php:80
elgg_get_user_by_username(string $username, bool $try_email=false)
Get a user by username.
Definition: users.php:39
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:107
getParams($filter=true)
Get the parameters from the request query and route matches.
Definition: Request.php:53
getParam($key, $default=null, $filter=true)
Get an element of the params array.
Definition: Request.php:67
isXhr()
Is the route access with XmlHttpRequest.
Definition: Request.php:149
$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:157
getEntityParam(string $key= 'guid')
Gets the "entity" key from the params if it holds an Elgg entity.
Definition: Request.php:91
get_entity(int $guid)
Loads and returns an entity object from a guid.
Definition: entities.php:70
$filter
Layout content filter.
Definition: filter.php:18
elgg()
Get the DI container.
Definition: Request.php:125
__construct(protected PublicContainer $dic, protected HttpRequest $http_request)
Constructor.
Definition: Request.php:25
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:42
Request container.
Definition: Request.php:12
getPath()
Get relative path of the request.
Definition: Request.php:141
$guid
Reset an ElggUpgrade.
Definition: reset.php:6