<commit_before><?php

namespace Rcm\Page\Renderer;

use Rcm\Entity\Page;
use Rcm\Entity\Site;
use Rcm\Http\Response;
use Rcm\Page\PageData\PageDataBc;
use Rcm\Page\PageData\PageDataService;
use Rcm\Page\PageStatus\PageStatus;
use Rcm\Page\PageTypes\PageTypes;
use Rcm\Service\LayoutManager;
use Zend\Expressive\ZendView\ZendViewRenderer;
use Zend\View\Model\ModelInterface;
use Zend\View\Model\ViewModel;
use Zend\View\Renderer\PhpRenderer;

/**
 * Class PageRenderer
 *
 * @author    <NAME>
 * @license   License.txt
 * @link      https://github.com/jerv13
 */
class PageRendererBc
{
    /**
     * @var LayoutManager
     */
    protected $layoutManager;

    /**
     * @var PageStatus
     */
    protected $pageStatus;

    protected $viewRenderer;

    /**
     * Constructor.
     *
     * @param LayoutManager $layoutManager
     * @param PageDataService $pageDataService
     * @param PageStatus $pageStatus
     */
    public function __construct(
        LayoutManager $layoutManager,
        PageDataService $pageDataService,
        PageStatus $pageStatus,
        PhpRenderer $viewRenderer
    ) {
        $this->layoutManager = $layoutManager;
        $this->pageDataService = $pageDataService;
        $this->pageStatus = $pageStatus;
        $this->viewRenderer = $viewRenderer;
    }

    /**
     * getLayoutManager
     *
     * @return LayoutManager
     */
    protected function getLayoutManager()
    {
        return $this->layoutManager;
    }

    /**
     * renderZf2
     *
     * @param Response $response
     * @param ModelInterface $layoutView
     * @param ViewModel $viewModel
     * @param PageDataBc $pageData
     *
     * @return Response|ViewModel
     */
    public function renderZf2(
        Response $response,
        ModelInterface $layoutView,
        ViewModel $viewModel,
        PageDataBc $pageData
    ) {
        if (empty($pageData->getPage())) {
            $response->setStatusCode($this->pageStatus->getNotFoundStatus());

            return $response;
        }

        $httpStatus = $pageData->getHttpStatus();

        if ($httpStatus == $this->pageStatus->getNotAuthorizedStatus()) {
            $response->setStatusCode($this->pageStatus->getNotAuthorizedStatus());

            return $response;
        }

        $response->setStatusCode(
            $httpStatus
        );

        $site = $pageData->getSite();
        $page = $pageData->getPage();
        $requestedPageData = $pageData->getRequestedPage();

        $layoutView = $this->prepareLayoutView(
            $layoutView,
            $site,
            $page
        );

        $layoutView->setVariable(
            'page',
            $page
        );

        $layoutView->setVariable(
            'site',
            $site
        );

        $layoutView->setVariable(
            'httpStatus',
            $httpStatus
        );

        $layoutView->setVariable(
            'requestedPageData',
            $requestedPageData
        );

        $viewModel->setVariable(
            'page',
            $page
        );
        $viewModel->setVariable(
            'httpStatus',
            $httpStatus
        );
        $viewModel->setVariable(
            'useInstanceConfig',
            true
        );

        $viewModel->setTemplate(
            'pages/'
            . $this->getLayoutManager()->getSitePageTemplate(
                $site,
                $page->getPageLayout()
            )
        );

        return $viewModel;

        $layoutView->addChild($viewModel);

        $renderedHtml = $this->viewRenderer->render($layoutView);

        $response = new Response();
        $response->setStatusCode($httpStatus);
        $response->setContent($renderedHtml);

        return $response;<commit_msg>Make "not found" page return 404 instead of 200<commit_after><?php

namespace Rcm\Page\Renderer;

use Rcm\Entity\Page;
use Rcm\Entity\Site;
use Rcm\Http\Response;
use Rcm\Page\PageData\PageDataBc;
use Rcm\Page\PageData\PageDataService;
use Rcm\Page\PageStatus\PageStatus;
use Rcm\Page\PageTypes\PageTypes;
use Rcm\Service\LayoutManager;
use Zend\Expressive\ZendView\ZendViewRenderer;
use Zend\View\Model\ModelInterface;
use Zend\View\Model\ViewModel;
use Zend\View\Renderer\PhpRenderer;

/**
 * Class PageRenderer
 *
 * @author    <NAME>
 * @license   License.txt
 * @link      https://github.com/jerv13
 */
class PageRendererBc
{
    /**
     * @var LayoutManager
     */
    protected $layoutManager;

    /**
     * @var PageStatus
     */
    protected $pageStatus;

    protected $viewRenderer;

    /**
     * Constructor.
     *
     * @param LayoutManager $layoutManager
     * @param PageDataService $pageDataService
     * @param PageStatus $pageStatus
     */
    public function __construct(
        LayoutManager $layoutManager,
        PageDataService $pageDataService,
        PageStatus $pageStatus,
        PhpRenderer $viewRenderer
    ) {
        $this->layoutManager = $layoutManager;
        $this->pageDataService = $pageDataService;
        $this->pageStatus = $pageStatus;
        $this->viewRenderer = $viewRenderer;
    }

    /**
     * getLayoutManager
     *
     * @return LayoutManager
     */
    protected function getLayoutManager()
    {
        return $this->layoutManager;
    }

    /**
     * renderZf2
     *
     * @param Response $response
     * @param ModelInterface $layoutView
     * @param ViewModel $viewModel
     * @param PageDataBc $pageData
     *
     * @return Response|ViewModel
     */
    public function renderZf2(
        Response $response,
        ModelInterface $layoutView,
        ViewModel $viewModel,
        PageDataBc $pageData
    ) {
        if (empty($pageData->getPage())) {
            $response->setStatusCode($this->pageStatus->getNotFoundStatus());

            return $response;
        }

        $httpStatus = $pageData->getHttpStatus();

        if ($httpStatus == $this->pageStatus->getNotAuthorizedStatus()) {
            $response->setStatusCode($this->pageStatus->getNotAuthorizedStatus());

            return $response;
        }

        $response->setStatusCode(
            $httpStatus
        );

        $site = $pageData->getSite();
        $page = $pageData->getPage();
        $requestedPageData = $pageData->getRequestedPage();

        $layoutView = $this->prepareLayoutView(
            $layoutView,
            $site,
            $page
        );

        $layoutView->setVariable(
            'page',
            $page
        );

        $layoutView->setVariable(
            'site',
            $site
        );

        $layoutView->setVariable(
            'httpStatus',
            $httpStatus
        );

        $layoutView->setVariable(
            'requestedPageData',
            $requestedPageData
        );

        $viewModel->setVariable(
            'page',
            $page
        );
        $viewModel->setVariable(
            'httpStatus',
            $httpStatus
        );
        $viewModel->setVariable(
            'useInstanceConfig',
            true
        );

        $viewModel->setTemplate(
            'pages/'
            . $this->getLayoutManager()->getSitePageTemplate(
                $site,
                $page->getPageLayout()
            )
        );

        $layoutView->addChild($viewModel);

        $renderedHtml = $this->viewRenderer->render($layoutView);

        $response = new Response();
        $response->setStatusCode($httpStatus);
        $response->setContent($renderedHtml);

        return $response;
{'fraction_non_alphanumeric': 0.11681745609366684, 'fraction_numerical': 0.0018626929217668972, 'mean_word_length': 1.9594488188976378, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 77, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1201961', 'n_tokens_mistral': 2131, 'n_tokens_neox': 2064, 'n_words': 353}