Returns the page from the event.

@param ResourceEventInterface $event

@return PageInterface
765328
private function getPageFromEvent(ResourceEventInterface $event)
    {
        $resource = $event->getResource();

        if (!$resource instanceof PageInterface) {
            throw new InvalidArgumentException("Expected instance of PageInterface");
        }

        return $resource;
    }
60603
public function onPreUpdate(ResourceEventInterface $event)
    {
        $page = $this->getPageFromEvent($event);

        // Don't disable if static
        if (!$page->isEnabled() && $page->isStatic()) {
            $page->setEnabled(true);
        }

        // Don't enable if at least one ancestor is disabled.
        if ($page->isEnabled()) {
            $parentPage = $page;
            while (null !== $parentPage = $parentPage->getParent()) {
                if (!$parentPage->isEnabled()) {
                    $page->setEnabled(false);
                    $event->addMessage(new ResourceMessage(
                        'ekyna_cms.page.alert.parent_disabled',
                        ResourceMessage::TYPE_WARNING
                    ));
                    break;
                }
            }
        }

        // Bubble disable
        if ($this->disablePageChildren($page)) {
            $event->addMessage(new ResourceMessage(
                'ekyna_cms.page.alert.children_disabled',
                ResourceMessage::TYPE_WARNING
            ));
        }
        if ($this->disablePageRelativeMenus($page)) {
            $event->addMessage(new ResourceMessage(
                'ekyna_cms.page.alert.menus_disabled',
                ResourceMessage::TYPE_WARNING
            ));
            $this->tm->addTags(call_user_func($this->menuClass . '::getEntityTagPrefix'));
        }
    }
547222
public function getPage($name)
    {
        if (null === $this->pageObjectFactory) {
            throw new \RuntimeException('To create pages you need to pass a factory with setPageObjectFactory()');
        }

        return $this->pageObjectFactory->createPage($name);
    }
264390
public function dispatchEvent(object $event): object
    {
        if (isset($this->i__dispatcher)) {
            $this->i__dispatcher->dispatch($event);
        }

        return $event;
    }
818493
protected function persistResource(ResourceEvent $event)
    {
        $resource = $event->getResource();

        // TODO Validation ?

        try {
            $this->manager->persist($resource);
            $this->manager->flush();
        } catch(DBALException $e) {
            if ($this->debug) {
                throw $e;
            }
            $event->addMessage(new ResourceMessage(
                'ekyna_admin.resource.message.persist.failure',
                ResourceMessage::TYPE_ERROR
            ));
            return $event;
        }

        return $event->addMessage(new ResourceMessage(
            'ekyna_admin.resource.message.persist.success',
            ResourceMessage::TYPE_SUCCESS
        ));
    }
688826
public function load(\Zend_EventManager_EventDescription $event)
    {
        if(false !== ($content = $this->cache->load($this->_getIdentifier($event)))) {
            $event->stopPropagation(true);
            return $content;
        }
    }
213393
public function findByRequest(Request $request): ?PageInterface
    {
        if (null !== $route = $request->attributes->get('_route', null)) {
            return $this->findByRoute($route);
        }

        return null;
    }
64100
public function getCurrent(): ?PageInterface
    {
        if (false === $this->currentPage) {
            if (null === $this->request) {
                throw new \RuntimeException('The page helper must be initialized first.');
            }
            $this->currentPage = $this->findByRequest($this->request);
        }

        return $this->currentPage;
    }
921020
public function onKernelRequest(ConfigureMenuEvent $event)
    {
        $menu = $event->getMenu();
        $menu->addChild(
            'LDAP',
            [
                'route' => 'claro_admin_ldap',
            ]
        )->setExtra('name', 'LDAP');

        return $menu;
    }
1152461
protected function createResourceEvent($resource)
    {
        if (null !== $eventClass = $this->config->getEventClass()) {
            $event = new $eventClass($resource);
        } else {
            $event = new ResourceEvent();
            $event->setResource($resource);
        }
        return $event;
    }
577153
public static function getEventDispatcher(): EventDispatcherInterface
    {
        if (isset(self::$dispatchers[static::class])) {
            return self::$dispatchers[static::class];
        }

        return self::$dispatchers[static::class] = new EventDispatcher();
    }
1001830
public function getPath(Event $event) {
		$pathBuilder = $this->pathBuilder();
		$method = $event->getData('method');
		if (!method_exists($pathBuilder, $event->getData('method'))) {
			throw new BadMethodCallException(sprintf('`%s` does not implement the `%s` method!', get_class($pathBuilder), $method));
		};

		$event = $this->dispatchEvent('FileStorage.beforeGetPath', [
			'entity' => $event->getData('entity'),
			'storageAdapter' => $this->getStorageAdapter($event->getData('entity')->get('adapter')),
			'pathBuilder' => $pathBuilder
		]);

		if ($event->isStopped()) {
			return $event->result;
		}

		if ($event->getSubject() instanceof EntityInterface) {
			$event->getData('entity');
		}

		if (empty($event->getData('entity'))) {
			throw new RuntimeException('No entity present!');
		}

		$path = $pathBuilder->{$method}($event->getData('entity'), $event->getData());

		$entity = $event->getData('entity');
		$event = $this->dispatchEvent('FileStorage.afterGetPath', [
			'entity' => $entity,
			'storageAdapter' => $this->getStorageAdapter($entity->get('adapter')),
			'pathBuilder' => $pathBuilder,
			'path' => $path
		]);

		if ($event->isStopped()) {
			return $event->getResult();
		}

		return $path;
	}
1140639
public function onPreUpdate(ResourceEventInterface $event)
    {
        $menu = $this->getMenuFromEvent($event);

        // Don't disable if locked
        if (!$menu->isEnabled() && $menu->isLocked()) {
            $menu->setEnabled(true);
        }

        // Don't enable if disabled relative page
        if ($menu->isEnabled() && !$menu->isLocked() && 0 < strlen($menu->getRoute())) {
            /** @noinspection SqlDialectInspection */
            $disabledPageId = $this->em
                ->createQuery("SELECT p.id FROM {$this->pageClass} p WHERE p.route = :route AND p.enabled = 0")
                ->setParameter('route', $menu->getRoute())
                ->getOneOrNullResult(Query::HYDRATE_SCALAR)
            ;
            if (null !== $disabledPageId) {
                $event->addMessage(new ResourceMessage(
                    'ekyna_cms.menu.alert.cant_enable_as_disabled_page',
                    ResourceMessage::TYPE_ERROR
                ));
                return;
            }
        }

        // Disable menu children
        if (!$menu->isEnabled()) {
            $this->em->createQuery(sprintf(
                'UPDATE %s m SET m.enabled = 0 WHERE m.root = :root AND m.left > :left AND m.right < :right',
                $this->menuClass
            ))->execute(array(
                'root'  => $menu->getRoot(),
                'left'  => $menu->getLeft(),
                'right' => $menu->getRight(),
            ));
        }
    }
901792
public function dispatch(EventInterface $event)
    {
        if (array_key_exists($event->getName(), $this->listeners)) {
            foreach ($this->listeners[$event->getName()] as $listener) {
                $listener($event);
            }
        }

        return $event;
    }
146452
public function get(EventInterface $event) {
        $response = $event->getResponse();
        $database = $event->getDatabase();
        $storage = $event->getStorage();

        $databaseStatus = $database->getStatus();
        $storageStatus = $storage->getStatus();

        if (!$databaseStatus || !$storageStatus) {
            if (!$databaseStatus && !$storageStatus) {
                $message = 'Database and storage error';
            } else if (!$storageStatus) {
                $message = 'Storage error';
            } else {
                $message = 'Database error';
            }

            $response->setStatusCode(503, $message);
        }

        $response->setMaxAge(0)
                 ->setPrivate();
        $response->headers->addCacheControlDirective('no-store');

        $statusModel = new Model\Status();
        $statusModel->setDate(new DateTime('now', new DateTimeZone('UTC')))
                    ->setDatabaseStatus($databaseStatus)
                    ->setStorageStatus($storageStatus);

        $response->setModel($statusModel);
    }
1326573
public function handleGetPageDetails(GetPageDetailsEvent $event)
    {
        /** @var PageModel $pageModelAdapter */
        $pageModelAdapter = $this->framework->getAdapter(PageModel::class);

        $page = $pageModelAdapter->findWithDetails($event->getPageId());

        if ($page) {
            $event->setPageDetails($page->row());
        }
    }
282875
public function loadGroups(EventInterface $event) {
        $query = new GroupQuery();
        $params = $event->getRequest()->query;

        if ($params->has('page')) {
            $query->page($params->get('page'));
        }

        if ($params->has('limit')) {
            $query->limit($params->get('limit'));
        }

        $response = $event->getResponse();
        $aclAdapter = $event->getAccessControl();

        // Create the model and set some pagination values
        $model = new GroupsModel();
        $model->setLimit($query->limit())
              ->setPage($query->page());

        $groups = $aclAdapter->getGroups($query, $model);
        $modelGroups = [];

        foreach ($groups as $groupName => $resources) {
            $modelGroups[] = [
                'name' => $groupName,
                'resources' => $resources,
            ];
        }

        $model->setGroups($modelGroups);
        $response->setModel($model);
    }