template = "components.head_actions"; if ($this->app->action['head'] ?? false) { $this->prepareHeadActions(); } $this->setParam('actions', $this->actions); } public function render(){ return view($this->template, $this->params)->render(); } protected function prepareHeadActions(): void { $this->actions = $this->app->action['head']; foreach ($this->actions as $action => $property) { $this->actions[$action]->show = false; if((!$this->app->isReadonly() || !isset($property->readonly) || !$property->readonly) && $this->app->isReadonly()) { continue; } switch ($property?->type) { case self::TYPE_LOGIC: $this->handleLogic($action, $property); break; case self::TYPE_ACTION: default: $this->handleAction($action, $property); break; } } } protected function handleLogic(string $action, $property): void { if (isset($property->{self::ACCESS_HANDLER_KEY})) { $show = $this->handleActionAccess($action, $property->{self::ACCESS_HANDLER_KEY}); } else { $show = Acl::isInRoleArray($property->access ?? []); } $this->actions[$action]->url = $this->app->getPath() . '?logic=' . $action; $this->actions[$action]->show = $show; } public function handleAction(string $action, $property): void { if (isset($property->{self::ACCESS_HANDLER_KEY})) { $show = $this->handleActionAccess($action, $property->{self::ACCESS_HANDLER_KEY}); } else { $show = true; } $this->actions[$action]->url = $this->app->getPath() . '/' . $action; $this->actions[$action]->show = $show; } protected function handleActionAccess(string $action, string $handler): bool { $processorResult = Logic::handle($handler, $this->app, ['action' => $action]); return $processorResult->getStatus(); } }