Creates a base response for given page.

@param PageInterface $page

@return Response
178866
protected function createResponse(PageInterface $page)
    {
        if ($page->getTarget()) {
            $page->addHeader('Location', $this->router->generate($page->getTarget()));
            $response = new Response('', 302, $page->getHeaders() ?: []);
        } else {
            $response = new Response('', 200, $page->getHeaders() ?: []);
        }

        return $response;
    }
507058
public static function description(PageInterface $page = null)
    {
        $page = $page ?: Router::getActivePage();
        $description = $page->getDescription() ?:
            ChunkFacade::get('text', 'standfirst', $page)->text();

        return strip_tags($description);
    }
1336761
public function deleteAction(Page $page)
    {
        if ($page->isDeleted()) {
            $this->hardDelete($page);
        } else {
            $this->softDelete($page);
        }

        $this->getEntityManager()->flush();

        return $this->createJsonResponse(null, 204);
    }
683689
private function disablePageChildren(PageInterface $page)
    {
        $childrenDisabled = false;
        if (!$page->isEnabled()) {
            if (0 < $page->getChildren()->count()) {
                foreach ($page->getChildren() as $child) {
                    if ($child->isEnabled()) {
                        $child->setEnabled(false);
                        $childrenDisabled = true;

                        $this->em->persist($child);

                        $this->deletePageCache($page);

                        $this->tm->addTags($page->getEntityTag());
                    }

                    $this->disablePageRelativeMenus($child);

                    $childrenDisabled |= $this->disablePageChildren($child);
                }
            }
        }
        return $childrenDisabled;
    }
1367250
public function page($page)
  {
    if (false === is_numeric($page) || $page <= 0)
    {
      throw new InvalidArgumentException(sprintf(
        '%s is an invalid page value. It has to be numeric and positive',
        $page
      ));
    }

    $this->responseConfig['optionalParameters'] = array_merge(
      $this->responseConfig['optionalParameters'],
      array("ItemPage" => $page)
    );

    return $this;
  }
1359356
public function postUpdate(PageInterface $page, LifecycleEventArgs $event)
    {
        /** @var \Doctrine\ORM\EntityManagerInterface $em */
        $em = $event->getObjectManager();
        $uow = $em->getUnitOfWork();

        $changeSet = $uow->getEntityChangeSet($page);
        if (array_key_exists('enabled', $changeSet)) {
            if ($page->isEnabled()) {
                $this->discardPageRedirections($page);
            } else {
                $this->buildPageRedirections($page);
            }
        }
    }
1233897
private function saveIfEmpty(Page $page)
    {
        $metadata = $this->container
                ->get('nestednode.metadata.resolver')
                ->resolve($page);

            $page->setMetaData($metadata);
            if ($this->container->get('em')->contains($page)) {
                $this->container->get('em')->flush($page);
            }

            return $page;
    }
439866
public function makePageCopy(PageInterface $page)
    {
        $pageClass = $this->pageManager->getClassName();
        /** @var PageInterface $pageCopy */
        $pageCopy = new $pageClass();

        $now = new \DateTime();

        $postfix = sprintf(' copy %s', $now->format('d.m.Y H:i:s'));

        $pageCopy->setPageName($page->getPageName().$postfix);
        $pageCopy->setMetaTitle($page->getMetaTitle());
        $pageCopy->setUrl($page->getUrl().$postfix);
        $pageCopy->setMetaKeyword($page->getMetaKeyword());
        $pageCopy->setMetaDescription($page->getMetaDescription());
        $pageCopy->setActiveFrom($page->getActiveFrom());
        $pageCopy->setIsHome(false);
        $pageCopy->setTemplateName($page->getTemplateName());
        $pageCopy->setLocale($page->getLocale());

        $layoutBlocks = $page->getLayoutBlock();

        $om = $this->registry->getManager();

        foreach ($layoutBlocks as $layoutBlock) {

            /** @var $newLayoutBlock \Networking\InitCmsBundle\Model\LayoutBlockInterface */
            $newLayoutBlock = clone $layoutBlock;


            $content = $om->getRepository($newLayoutBlock->getClassType())->find(
                $newLayoutBlock->getObjectId()
            );
            $newContent = clone $content;

            $om->persist($newContent);
            $om->flush();

            $newLayoutBlock->setObjectId($newContent->getId());
            $newLayoutBlock->setPage($pageCopy);

            $om->persist($newLayoutBlock);
        }

        $om->persist($pageCopy);

        $om->flush();

        return $pageCopy;
    }
45349
public function update(Page $page)
    {
        $attributes = request()->validate(Page::$rules, Page::$messages);

        $attributes['is_header'] = boolval(input('is_header'));
        $attributes['is_hidden'] = boolval(input('is_hidden'));
        $attributes['is_footer'] = boolval(input('is_footer'));
        $attributes['is_featured'] = boolval(input('is_featured'));

        $page = $this->updateEntry($page, $attributes);
        $page->updateUrl()->save();
        $page->banners()->sync(input('banners'));

        return redirect_to_resource();
    }
969183
public function handle(ServerRequestInterface $request): ResponseInterface{
        if($this->runningQueue === null){
            $this->runningQueue = clone $this->queue;
        }

        $this->runningLevel++;

        if($this->runningQueue->isEmpty()){
            $response   = $this->factory->createResponse();
        }else{
            $response   = $this->runningQueue->dequeue()->process($request, $this);
        }

        $this->runningLevel--;

        if($this->runningLevel === 0){
            $this->runningQueue = null;
        }

        return $response;
    }
253648
public function handle(ServerRequestInterface $request):ResponseInterface {
		$path = $request->getUri()->getPath();
// TODO: Abstract response type needed.
		$response = new PageResponse();

		try {
			$templateDirectory = implode(DIRECTORY_SEPARATOR, [
				$this->router->getBaseViewLogicPath(),
				"_component",
			]);
			$viewAssembly = $this->router->getViewAssembly($path);
			$view = $this->getView(
				$response->getBody(),
				(string)$viewAssembly,
				$templateDirectory,
				$path,
				$request->getHeaderLine("accept")
			);
		}
		catch(BasenameNotFoundException $exception) {
// TODO: Handle view not found.
			die("The requested view is not found!!!");
		}

		LogicFactory::setView($view);
		$baseLogicDirectory = $this->router->getBaseViewLogicPath();

		$logicAssembly = $this->router->getLogicAssembly($path);

		$logicObjects = $this->createLogicObjects(
			$logicAssembly,
			$baseLogicDirectory,
			$request->getUri()
		);

		$this->dispatchLogicObjects($logicObjects);
		$this->injectCsrf($view);
		$view->stream();

		return $response;
	}
771509
public function verifyPage(): ResponseInterface
    {
        $this->checkRegistrationAllowed();

        $title = I18N::translate('User verification');

        return $this->viewResponse('register-page', [
            'title' => $title,
        ]);
    }
500208
public function requestApproval(Page $page)
    {
        $this->authorize('edit', $page);

        $page->markUpdatesAsPendingApproval();

        Event::fire(new Events\PageApprovalRequested($page, auth()->user()));

        return $page->getCurrentVersion()->getStatus();
    }
526961
private function loadBlocks(PageInterface $page)
    {
        $blocks = $this->blockInteractor->loadPageBlocks($page);

        // save a local cache
        foreach ($blocks as $block) {
            $this->blocks[$block->getId()] = $block;
        }
    }
1068080
private function createMenus(PageInterface $page, array $menus)
    {
        if (!empty($menus)) {
            foreach ($menus as $parentName => $config) {
                if (null === $parent = $this->menuRepository->findOneByName($parentName)) {
                    $this->output->writeln(sprintf(
                        '<error>Parent menu "%s" not found for route "%s".</error>',
                        $parentName,
                        $page->getRoute()
                    ));

                    return false;
                }

                $name = $page->getRoute();
                if (null === $this->menuRepository->findOneBy(['name' => $name, 'parent' => $parent])) {
                    /** @var \Ekyna\Bundle\CmsBundle\Model\MenuInterface $menu */
                    $menu = $this->menuRepository->createNew();
                    $menu
                        ->setParent($parent)
                        ->setName($name)
                        ->setRoute($name);

                    if (isset($config['options'])) {
                        $menu->setOptions((array)$config['options']);
                    }
                    if (isset($config['attributes'])) {
                        $menu->setAttributes((array)$config['attributes']);
                    }

                    foreach ($this->locales as $locale) {
                        $menuTranslation = $menu->translate($locale, true);
                        $menuTranslation
                            ->setTitle($page->translate($locale)->getTitle());
                    }

                    if (!$this->validate($menu)) {
                        return false;
                    }

                    $this->menuOperator->persist($menu);
                }
            }
        }

        return true;
    }
684599
public function makePageSnapshot(PageInterface $page)
    {
        foreach ($page->getLayoutBlock() as $layoutBlock) {
            $layoutBlockContent = $this->registry->getManagerForClass($layoutBlock->getClassType())->getRepository($layoutBlock->getClassType())->find(
                $layoutBlock->getObjectId()
            );
            $layoutBlock->takeSnapshot($this->serializer->serialize($layoutBlockContent, 'json'));
        }

        $pageSnapshotClass = $this->pageSnapshotManager->getClassName();

        /** @var \Networking\InitCmsBundle\Model\PageSnapshotInterface $pageSnapshot */
        $pageSnapshot = new $pageSnapshotClass($page);
        $pageSnapshot->setVersionedData($this->serializer->serialize($page, 'json'))
            ->setPage($page);

        if ($oldPageSnapshot = $page->getSnapshot()) {
            $snapshotContentRoute = $oldPageSnapshot->getContentRoute();
        } else {
            $contentRouteClass = $this->contentRouteManager->getClassName();
            /** @var \Networking\InitCmsBundle\Model\ContentRouteInterface $snapshotContentRoute */
            $snapshotContentRoute = new $contentRouteClass();
        }

        $pageSnapshot->setContentRoute($snapshotContentRoute);
        $pageSnapshot->setPath(self::getPageRoutePath($page->getPath()));

        $om = $this->registry->getManagerForClass($pageSnapshotClass);
        $om->persist($pageSnapshot);
        $om->flush();

        $snapshotContentRoute->setPath(self::getPageRoutePath($page->getPath()));
        $snapshotContentRoute->setObjectId($pageSnapshot->getId());

        if ($oldPageSnapshot && ($oldPageSnapshot->getPath() != self::getPageRoutePath($page->getPath()))) {
            $this->phpCache->clean();
        }

        $om = $this->registry->getManagerForClass(get_class($snapshotContentRoute));
        $om->persist($snapshotContentRoute);
        $om->flush();
    }
130303
protected function createLaravelResponse(ResponseInterface $response)
    {
        return new Response(
            (string) $response->getBody(),
            $response->getStatusCode(),
            $response->getHeaders()
        );
    }