Elgg  Version master
PageOwnerService.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Page;
4 
9 use Elgg\Invoker;
11 
20 
24  protected $request;
25 
29  protected $entity_table;
30 
34  protected $events;
35 
39  protected $invoker;
40 
44  protected $page_owner_guid = 0;
45 
54  public function __construct(
59  ) {
60  $this->request = $request;
61  $this->entity_table = $entity_table;
62  $this->events = $events;
63  $this->invoker = $invoker;
64 
65  $this->page_owner_guid = $this->detectPageOwnerFromRoute();
66  }
67 
73  protected function detectPageOwnerFromRoute(): int {
74  $route = $this->request->getRoute();
75  if (!$route instanceof Route) {
76  return 0;
77  }
78 
79  $page_owner = $route->resolvePageOwner();
80  if (!$page_owner instanceof \ElggEntity) {
81  return 0;
82  }
83 
84  return $page_owner->guid;
85  }
86 
95  public function setPageOwnerGuid(int $guid = 0) {
96  if ($guid < 0) {
97  throw new RangeException(__METHOD__ . ' requires a positive integer.');
98  }
99 
100  $this->page_owner_guid = $guid;
101  }
102 
108  public function getPageOwnerGuid() {
109  return $this->page_owner_guid;
110  }
111 
117  public function getPageOwnerEntity(): ?\ElggEntity {
118  return $this->entity_table->get($this->getPageOwnerGuid());
119  }
120 }
getPageOwnerEntity()
Returns the page owner entity.
Exception thrown to indicate range errors during program execution.
Elgg HTTP request.
Definition: Request.php:17
Events service.
getPageOwnerGuid()
Return the current page owner guid.
detectPageOwnerFromRoute()
Detects page owner from route.
setPageOwnerGuid(int $guid=0)
Sets a new page owner guid.
Route Wrapper.
Definition: Route.php:8
$page_owner
Definition: add.php:16
Holds page owner related functions.
__construct(Request $request, EntityTable $entity_table, EventsService $events, Invoker $invoker)
Constructor.
Entity table database service.
Definition: EntityTable.php:24
$guid
Reset an ElggUpgrade.
Definition: reset.php:6
Invocation service.
Definition: Invoker.php:10