Elgg  Version 6.1
PageOwnerGatekeeper.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Router\Middleware;
4 
7 
14 
15  protected \ElggEntity $page_owner;
16 
25  public function __invoke(\Elgg\Request $request) {
26 
27  $route = $request->getHttpRequest()->getRoute();
28  if (!$route instanceof Route) {
29  return;
30  }
31 
32  // force detection of page owner for legacy routes
33  $route->setDefault('_detect_page_owner', true);
34 
35  $page_owner = $route->resolvePageOwner();
36  if (!$page_owner instanceof \ElggEntity) {
37  throw new EntityNotFoundException();
38  }
39 
40  $this->page_owner = $page_owner;
41 
42  $this->assert($request, $route);
43  }
44 
53  protected function assert(\Elgg\Request $request, Route $route): void {
54  $this->assertPageOwner();
55  }
56 
63  protected function assertPageOwner(): void {
64  if (!empty($this->getType()) && $this->page_owner->getType() !== $this->getType()) {
65  throw new EntityNotFoundException();
66  }
67 
68  if (!empty($this->getSubtype()) && $this->page_owner->getSubtype() !== $this->getType()) {
69  throw new EntityNotFoundException();
70  }
71 
72  _elgg_services()->gatekeeper->assertAccessibleEntity($this->page_owner);
73  }
74 
80  protected function getType(): string {
81  return '';
82  }
83 
89  protected function getSubtype(): string {
90  return '';
91  }
92 }
getSubtype()
Returns the subtype of the page owner to validate.
$request
Definition: livesearch.php:12
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Definition: LICENSE.txt:215
assert(\Elgg\Request $request, Route $route)
Performs assertions.
Route Wrapper.
Definition: Route.php:8
__invoke(\Elgg\Request $request)
Validate the current request.
getType()
Returns the type of the page owner to validate.
Request container.
Definition: Request.php:12
Aggregate action for saving settings.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353
Check if the current route has a page owner entity.