public function createResponseFromPage(
        PageInterface $page = null,
        $path = ''
    ) {
        if (
            !($page instanceof PageInterface) ||
            $page->getType() !== ElcodiPageTypes::TYPE_REGULAR
        ) {
            throw new NotFoundHttpException('Page not found');
        }

        $request = $this
            ->requestStack
            ->getCurrentRequest();

        /**
         * Request not found because this controller is not running under
         * Request scope.
         */
        if (!($request instanceof Request)) {
            throw new RuntimeException('Request object not found');
        }

        /**
         * We must check that the product slug is right. Otherwise we must
         * return a Redirection 301 to the right url.
         */
        if (
            $page->getPath() &&
            $path !== $page->getPath()
        ) {
            return new RedirectResponse(
                $this
                    ->urlGenerator
                    ->generate($this->pageRenderRoute, [
                        'id' => $page->getId(),
                        'path' => $page->getPath(),
                    ]),
                301
            );
        }

        $response = $this->createResponseInstance($page);

        if (!$response->isNotModified($request)) {
            $response->setContent($this->renderPage($page));
            $response->headers->set('Content-Type', 'text/html');
        }

        return $response;
    }
public function createResponseFromPage(
        PageInterface $page = null,
        $path = ''
    ) {
        if (
            !($page instanceof PageInterface) ||
            $page->getType() !== ElcodiPageTypes::TYPE_REGULAR
        ) {
            throw new NotFoundHttpException('Page not found');
        }

        $request = $this
            ->requestStack
            ->getCurrentRequest();

        /**
         * Request not found because this controller is not running under
         * Request scope.
         */
        if (!($request instanceof Request)) {
            throw new RuntimeException('Request object not found');
        }

        /**
         * We must check that the product slug is right. Otherwise we must
         * return a Redirection 301 to the right url.
         */
        if (
            $page->getPath() &&
            $path !== $page->getPath()
        ) {
            return new RedirectResponse(
                $this
                    ->urlGenerator
                    ->generate($this->pageRenderRoute, [
                        'id' => $page->getId(),
                        'path' => $page->getPath(),
                    ]),
                301
            );
        }

        $response = $this->createResponseInstance($page);

        if (!$response->isNotModified($request)) {
            $response->setContent($this->renderPage($page));
            $response->headers->set('Content-Type', 'text/html');
        }

        return $response;
    }
public function createResponseFromPage ( PageInterface $ page = null , $ path = '' ) { if ( ! ( $ page instanceof PageInterface ) || $ page -> getType ( ) !== ElcodiPageTypes :: TYPE_REGULAR ) { throw new NotFoundHttpException ( 'Page not found' ) ; } $ request = $ this -> requestStack -> getCurrentRequest ( ) ; /**
         * Request not found because this controller is not running under
         * Request scope.
         */ if ( ! ( $ request instanceof Request ) ) { throw new RuntimeException ( 'Request object not found' ) ; } /**
         * We must check that the product slug is right. Otherwise we must
         * return a Redirection 301 to the right url.
         */ if ( $ page -> getPath ( ) && $ path !== $ page -> getPath ( ) ) { return new RedirectResponse ( $ this -> urlGenerator -> generate ( $ this -> pageRenderRoute , [ 'id' => $ page -> getId ( ) , 'path' => $ page -> getPath ( ) , ] ) , 301 ) ; } $ response = $ this -> createResponseInstance ( $ page ) ; if ( ! $ response -> isNotModified ( $ request ) ) { $ response -> setContent ( $ this -> renderPage ( $ page ) ) ; $ response -> headers -> set ( 'Content-Type' , 'text/html' ) ; } return $ response ; }
Render a page given the found instance.

@param PageInterface|null $page Found page
@param string             $path Page route path

@return Response Page rendered

@throws RuntimeException      Request object not found
@throws NotFoundHttpException Page not found or not valid
Render a page given the found instance .