22 protected const ACCESS_LEVELS = [
'public',
'logged_in',
'logged_out',
'admin'];
27 protected const UNPROTECTED_ACTIONS = [
'logout'];
53 if (!in_array($access, self::ACCESS_LEVELS)) {
54 throw new DomainException(
"Unrecognized value '{$access}' for \$access in " . __METHOD__);
59 $action =
trim($action,
'/');
61 if (empty($handler)) {
62 $handler = Paths::sanitize(
Paths::elgg() .
"actions/{$action}.php",
false);
65 if (str_ends_with($handler,
'.php')) {
75 if (!in_array($action, self::UNPROTECTED_ACTIONS)) {
76 $middleware[] = CsrfFirewall::class;
79 if ($access ===
'admin') {
80 $middleware[] = AdminGatekeeper::class;
81 }
elseif ($access ===
'logged_in') {
82 $middleware[] = MiddlewareGateKeeper::class;
83 }
elseif ($access ===
'logged_out') {
84 $middleware[] = LoggedOutGatekeeper::class;
87 $middleware[] = ActionMiddleware::class;
89 $additional_middleware = (array)
elgg_extract(
'middleware', $params);
90 $middleware = array_merge($middleware, $additional_middleware);
92 $this->routes->register(
"action:{$action}", [
93 'path' =>
"/action/{$action}",
95 'controller' => $controller,
96 'middleware' => $middleware,
111 $action =
trim($action,
'/');
113 $this->routes->unregister(
"action:{$action}");
125 public function exists(
string $action): bool {
126 $action =
trim($action,
'/');
127 $route = $this->routes->get(
"action:$action");
132 $file = $route->getDefault(
'_file');
133 $controller = $route->getDefault(
'_controller');
135 if (!$file && !$controller) {
139 if ($file && !file_exists($file)) {
143 if ($controller && !$this->handlers->isCallable($controller)) {
157 $routes = $this->routes->all();
158 foreach ($routes as
$name => $route) {
159 if (!str_starts_with(
$name,
'action:')) {
166 $middleware = (array) $route->getDefault(
'_middleware');
167 if (in_array(MiddlewareGateKeeper::class, $middleware)) {
168 $access =
'logged_in';
169 }
elseif (in_array(LoggedOutGatekeeper::class, $middleware)) {
170 $access =
'logged_out';
171 }
elseif (in_array(AdminGatekeeper::class, $middleware)) {
176 'file' => $route->getDefault(
'_file'),
177 'controller' => $route->getDefault(
'_controller'),
$params
Saves global plugin settings.
Helpers for providing callable-based APIs.
if(!$user||!$user->canDelete()) $name
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
Exception thrown if a value does not adhere to a defined valid data domain.
exists(string $action)
Check if an action is registered and its script exists.
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
getAllActions()
Get all actions.
Protects a route from non-authenticated users.
if(!$menu instanceof\Elgg\Menu\PreparedMenu) $actions
__construct(protected RouteRegistrationService $routes, protected HandlersService $handlers)
Constructor.
unregister(string $action)
Unregisters an action.
Route registration service.