28 private static $access_levels = [
'public',
'logged_in',
'logged_out',
'admin'];
34 private static $bypass_csrf = [
55 $this->routes = $routes;
56 $this->handlers = $handlers;
72 if (!in_array($access, self::$access_levels)) {
73 throw new DomainException(
"Unrecognized value '{$access}' for \$access in " . __METHOD__);
78 $action =
trim($action,
'/');
80 if (empty($handler)) {
82 $handler = Paths::sanitize(
"{$path}/{$action}.php",
false);
88 if (str_ends_with($handler,
'.php')) {
96 if (!in_array($action, self::$bypass_csrf)) {
97 $middleware[] = CsrfFirewall::class;
100 if ($access ==
'admin') {
101 $middleware[] = AdminGatekeeper::class;
102 }
elseif ($access ==
'logged_in') {
103 $middleware[] = MiddlewareGateKeeper::class;
104 }
elseif ($access ==
'logged_out') {
105 $middleware[] = LoggedOutGatekeeper::class;
108 $middleware[] = ActionMiddleware::class;
110 $this->routes->register(
"action:{$action}", [
111 'path' =>
"/action/{$action}",
113 'controller' => $controller,
114 'middleware' => $middleware,
129 $action =
trim($action,
'/');
131 $route = $this->routes->get(
"action:{$action}");
136 $this->routes->unregister(
"action:{$action}");
148 public function exists(
string $action): bool {
149 $action =
trim($action,
'/');
150 $route = $this->routes->get(
"action:$action");
155 $file = $route->getDefault(
'_file');
156 $controller = $route->getDefault(
'_controller');
158 if (!$file && !$controller) {
162 if ($file && !file_exists($file)) {
166 if ($controller && !$this->handlers->isCallable($controller)) {
180 $routes = $this->routes->all();
181 foreach ($routes as
$name => $route) {
182 if (!str_starts_with(
$name,
'action:')) {
189 $middleware = (array) $route->getDefault(
'_middleware');
190 if (in_array(MiddlewareGateKeeper::class, $middleware)) {
191 $access =
'logged_in';
192 }
elseif (in_array(LoggedOutGatekeeper::class, $middleware)) {
193 $access =
'logged_out';
194 }
elseif (in_array(AdminGatekeeper::class, $middleware)) {
199 'file' => $route->getDefault(
'_file'),
200 'controller' => $route->getDefault(
'_controller'),
Helpers for providing callable-based APIs.
if(!$user||!$user->canDelete()) $name
__construct(RouteRegistrationService $routes, HandlersService $handlers)
Constructor.
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']))
getAllActions()
Get all actions.
trait Loggable
Enables adding a logger.
Protects a route from non-authenticated users.
if(!$menu instanceof\Elgg\Menu\PreparedMenu) $actions
unregister(string $action)
Unregisters an action.
Route registration service.