Elgg  Version 3.0
Route.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Router;
4 
8 class Route extends \Symfony\Component\Routing\Route {
9 
13  protected $parameters = [];
14 
23  public function setMatchedParameters(array $parameters) {
24  $this->parameters = $parameters;
25 
26  return $this;
27  }
28 
34  public function getMatchedParameters() {
35  return $this->parameters;
36  }
37 
42  public function getName() {
43  return elgg_extract('_route', $this->parameters);
44  }
45 
52  public function resolvePageOwner() {
53 
54  $params = $this->getMatchedParameters();
55  $route_name = $this->getName();
56 
57  $route_parts = explode(':', $route_name);
58 
59  $from_guid = function ($guid) {
61  if ($entity instanceof \ElggUser || $entity instanceof \ElggGroup) {
62  return $entity;
63  } else if ($entity instanceof \ElggObject) {
64  return $entity->getContainerEntity();
65  }
66  };
67 
68  switch ($route_parts[0]) {
69  case 'view' :
70  case 'edit' :
71  $username = elgg_extract('username', $params);
72  if ($username) {
73  return get_user_by_username($username) ?: null;
74  }
75 
76  $guid = elgg_extract('guid', $params);
77  if ($guid) {
78  return $from_guid($guid);
79  }
80  break;
81 
82  case 'add' :
83  case 'collection' :
84  $username = elgg_extract('username', $params);
85  if ($username) {
86  return get_user_by_username($username) ?: null;
87  }
88 
89  $guid = elgg_extract('guid', $params);
90  if ($guid) {
91  return $from_guid($guid);
92  }
93 
94  $container_guid = elgg_extract('container_guid', $params);
95  if ($container_guid) {
96  return $from_guid($container_guid);
97  }
98  break;
99  }
100 
101  }
102 }
$username
Definition: delete.php:23
$params
Saves global plugin settings.
Definition: save.php:13
$guid
Removes an admin notice.
get_user_by_username($username)
Get user by username.
Definition: users.php:61
resolvePageOwner()
Attemps to resolve page owner from route parameters.
Definition: Route.php:52
Route Wrapper.
Definition: Route.php:8
$entity
Definition: reset.php:8
getName()
Get matched route name.
Definition: Route.php:42
setMatchedParameters(array $parameters)
Set matched parameters.
Definition: Route.php:23
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1131
$container_guid
getMatchedParameters()
Get matched parameters.
Definition: Route.php:34
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:87