Elgg  Version 3.0
Invoker.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg;
4 
5 use Closure;
7 use ElggSession;
8 
12 class Invoker {
13 
17  protected $session;
18 
22  protected $dic;
23 
30  public function __construct(ElggSession $session, PublicContainer $dic) {
31  $this->session = $session;
32  $this->dic = $dic;
33  }
34 
49  public function call(int $flags, Closure $closure) {
50 
51  $ia = $this->session->getIgnoreAccess();
52  if ($flags & ELGG_IGNORE_ACCESS) {
53  $this->session->setIgnoreAccess(true);
54  } else if ($flags & ELGG_ENFORCE_ACCESS) {
55  $this->session->setIgnoreAccess(false);
56  }
57 
58  $ha = $this->session->getDisabledEntityVisibility();
59  if ($flags & ELGG_SHOW_DISABLED_ENTITIES) {
60  $this->session->setDisabledEntityVisibility(true);
61  } else if ($flags & ELGG_HIDE_DISABLED_ENTITIES) {
62  $this->session->setDisabledEntityVisibility(false);
63  }
64 
65  $restore = function () use ($ia, $ha) {
66  $this->session->setIgnoreAccess($ia);
67  $this->session->setDisabledEntityVisibility($ha);
68  };
69 
70  try {
71  $result = $this->dic->call($closure);
72  } catch (\Exception $e) {
73  $restore();
74  throw $e;
75  }
76 
77  $restore();
78 
79  return $result;
80  }
81 }
const ELGG_ENFORCE_ACCESS
Definition: constants.php:157
const ELGG_HIDE_DISABLED_ENTITIES
Definition: constants.php:159
const ELGG_IGNORE_ACCESS
elgg_call() flags
Definition: constants.php:156
Configuration exception.
const ELGG_SHOW_DISABLED_ENTITIES
Definition: constants.php:158
call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags...
Definition: Invoker.php:49
__construct(ElggSession $session, PublicContainer $dic)
Constructor.
Definition: Invoker.php:30
Invocation service.
Definition: Invoker.php:12