Elgg  Version 4.x
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($key = 'guid') {
104  $guid = $this->http_request->getParam($key);
105  if ($guid) {
107  if ($entity instanceof \ElggEntity) {
108  return $entity;
109  }
110  }
111 
112  return null;
113  }
114 
122  public function getUserParam($key = 'user_guid') {
123  $prop = $this->http_request->getParam($key);
124  if ($key === 'username') {
125  $entity = get_user_by_username($prop);
126 
127  return $entity ? : null;
128  }
129 
130  if ($prop) {
131  $entity = get_entity($prop);
132  if ($entity instanceof \ElggUser) {
133  return $entity;
134  }
135  }
136 
137  return null;
138  }
139 
145  public function elgg() {
146  return $this->dic;
147  }
148 
153  public function getURL() {
154  return $this->http_request->getCurrentURL();
155  }
156 
161  public function getPath() {
162  return implode('/', $this->http_request->getUrlSegments());
163  }
164 
169  public function isXhr() {
170  return $this->http_request->isXmlHttpRequest();
171  }
172 
177  public function getMethod() {
178  return $this->http_request->getMethod();
179  }
180 
186  public function getHttpRequest() {
187  return $this->http_request;
188  }
189 }
$default
Definition: checkbox.php:31
getHttpRequest()
Get the HttpRequest for this request.
Definition: Request.php:186
getURL()
Get URL of the request.
Definition: Request.php:153
validation()
Access validation results bag.
Definition: Request.php:45
setParam($key, $value=null)
Set request parameter.
Definition: Request.php:92
__construct(PublicContainer $dic, HttpRequest $http_request)
Constructor.
Definition: Request.php:35
getEntityParam($key= 'guid')
Gets the "entity" key from the params if it holds an Elgg entity.
Definition: Request.php:103
Represents a set of validated parameters.
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:169
$value
Definition: generic.php:51
get_user_by_username($username)
Get user by username.
Definition: users.php:41
getMethod()
Get HTTP method of the request.
Definition: Request.php:177
$entity
Definition: reset.php:8
elgg()
Get the DI container.
Definition: Request.php:145
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:18
getPath()
Get relative path of the request.
Definition: Request.php:161
getUserParam($key= 'user_guid')
Gets the "user" key from the params if it holds an Elgg user.
Definition: Request.php:122
$guid
Reset an ElggUpgrade.
Definition: reset.php:6
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:69