<commit_before><?php
namespace CLMVC\Controllers\Render;

use CLMVC\Controllers\BaseController;
use CLMVC\Controllers\Views;
use CLMVC\Events\Filter;
use CLMVC\Events\View;

class Rendering {

    /**
     * @var bool if should render
     */
    private $render = true;
    /**
     * @var Views
     */
    public $views;
    /**
     * @var BaseController
     */
    private $controller;
    private $controllerName;
    public function __construct($controller) {
        $this->controller = $controller;
        $class = get_class($controller);
        $pos = strrpos($class, '\\');
        $className = substr($class, $pos + 1);
        $this->controllerName = str_replace('Controller', '', $className);
        $this->views = new Views($controller);
    }

    /**
     * @return mixed
     */
    private function getControllerName() {
        return $this->controllerName;
    }

    /**
     * Renders a controller and its action.
     * @param $controller
     * @param $action
     */
    public function Render($controller, $action) {
        $view_path = $this->views->findView($controller, $action, $this->getTemplate());
        if ($view_path) {
            $tags = Filter::run('view-tags', array(array(), $this->controller));
            $engine = RenderingEngines::getEngine($this->getTemplate(), $this->controller->getViewPath());
            $viewcontent = $engine->render($view_path, $this->getBag());
            $layout_path = $this->views->findLayout($this->getTemplate());
            if ($layout_path) {
                $engine = RenderingEngines::getEngine($this->getTemplate(), $view_path);
                $layout_content = $engine->render($layout_path, $this->getBag()+$tags, Filter::run("{$this->controllerName}-{$action}-blocks", array(array('view' => $viewcontent))));
            } else {
                $layout_content = $viewcontent;
            }
            $viewcontent = $layout_content;

        } else
            $viewcontent = 'Could not find view: ' . $view_path;
        $this->render = false;
        RenderedContent::set($viewcontent);
    }


    /**
     * Renders the current Controllers action
     * @param string $action The action to render
     */
    public function RenderToAction($action) {
        $this->Render($this->getControllerName(), $action);
    }

    /**
     * Renders a file.
     * @param string $filePath
     */
    public function RenderFile($filePath) {
        ob_start();
        if (file_exists($filePath)) {
            extract($this->getBag(), EXTR_REFS);
            include($filePath);
            $viewcontent = ob_get_contents();
        } else
            $viewcontent = 'Could not find view: ' . $$filePath;
        $this->render = false;
        ob_end_clean();
        RenderedContent::set($viewcontent);
    }

    /**
     * The text to render to screen.
     * @param string $text
     */
    public function RenderText($text, $end = false) {
        $this->render = false;
        RenderedContent::set($text);
        if ($end) {
            RenderedContent::endIt(true);
        }
    }

    /**
     * Encodes $data as JSON and flushes it and exists request.
     * @param $data
     */
    public function RenderJson($data) {
        header('Content-Type: application/json; charset=UTF-8');
        $this->render = false;
        RenderedContent::set(json_encode($data));
        RenderedContent::endIt(true);
    }

    private function getBag() {
        return $this->controller->getBag()->toArray();
    }

    public function renderedContent() {
        return RenderedContent::get();
    }

    public function canRender($state = null) {
        if (!is_null($state))
            $this->render = $state;
        return $this->render;
    }

    /**
     * @param $layout
     * @param $tag
     * @param $viewcontent
     * @return string
     */
    public function replaceTag($layout, $tag, $viewcontent) {
        $viewPosStart = strpos($layout, $tag);<commit_msg>add JSON_UNESCAPED_UNICODE to renderjson json_encode<commit_after><?php
namespace CLMVC\Controllers\Render;

use CLMVC\Controllers\BaseController;
use CLMVC\Controllers\Views;
use CLMVC\Events\Filter;
use CLMVC\Events\View;

class Rendering {

    /**
     * @var bool if should render
     */
    private $render = true;
    /**
     * @var Views
     */
    public $views;
    /**
     * @var BaseController
     */
    private $controller;
    private $controllerName;
    public function __construct($controller) {
        $this->controller = $controller;
        $class = get_class($controller);
        $pos = strrpos($class, '\\');
        $className = substr($class, $pos + 1);
        $this->controllerName = str_replace('Controller', '', $className);
        $this->views = new Views($controller);
    }

    /**
     * @return mixed
     */
    private function getControllerName() {
        return $this->controllerName;
    }

    /**
     * Renders a controller and its action.
     * @param $controller
     * @param $action
     */
    public function Render($controller, $action) {
        $view_path = $this->views->findView($controller, $action, $this->getTemplate());
        if ($view_path) {
            $tags = Filter::run('view-tags', array(array(), $this->controller));
            $engine = RenderingEngines::getEngine($this->getTemplate(), $this->controller->getViewPath());
            $viewcontent = $engine->render($view_path, $this->getBag());
            $layout_path = $this->views->findLayout($this->getTemplate());
            if ($layout_path) {
                $engine = RenderingEngines::getEngine($this->getTemplate(), $view_path);
                $layout_content = $engine->render($layout_path, $this->getBag()+$tags, Filter::run("{$this->controllerName}-{$action}-blocks", array(array('view' => $viewcontent))));
            } else {
                $layout_content = $viewcontent;
            }
            $viewcontent = $layout_content;

        } else
            $viewcontent = 'Could not find view: ' . $view_path;
        $this->render = false;
        RenderedContent::set($viewcontent);
    }


    /**
     * Renders the current Controllers action
     * @param string $action The action to render
     */
    public function RenderToAction($action) {
        $this->Render($this->getControllerName(), $action);
    }

    /**
     * Renders a file.
     * @param string $filePath
     */
    public function RenderFile($filePath) {
        ob_start();
        if (file_exists($filePath)) {
            extract($this->getBag(), EXTR_REFS);
            include($filePath);
            $viewcontent = ob_get_contents();
        } else
            $viewcontent = 'Could not find view: ' . $$filePath;
        $this->render = false;
        ob_end_clean();
        RenderedContent::set($viewcontent);
    }

    /**
     * The text to render to screen.
     * @param string $text
     * @param bool $end
     */
    public function RenderText($text, $end = false) {
        $this->render = false;
        RenderedContent::set($text);
        if ($end) {
            RenderedContent::endIt(true);
        }
    }

    /**
     * Encodes $data as JSON and flushes it and exists request.
     * @param $data
     */
    public function RenderJson($data) {
        header('Content-Type: application/json; charset=UTF-8');
        $this->render = false;
        RenderedContent::set(json_encode($data, JSON_UNESCAPED_UNICODE));
        RenderedContent::endIt(true);
    }

    private function getBag() {
        return $this->controller->getBag()->toArray();
    }

    public function renderedContent() {
        return RenderedContent::get();
    }

    public function canRender($state = null) {
        if (!is_null($state))
            $this->render = $state;
        return $this->render;
    }

    /**
     * @param $layout
     * @param $tag
     * @param $viewcontent
     * @return string
     */
    public function replaceTag($layout, $tag, $viewcontent) {
        $viewPosStart = strpos($layout, $tag);
{'fraction_non_alphanumeric': 0.14643257377661562, 'fraction_numerical': 0.0004980699788320259, 'mean_word_length': 2.3176373399421726, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 69, 'https://': 0, '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': '5199493', 'n_tokens_mistral': 2338, 'n_tokens_neox': 2291, 'n_words': 483}