<commit_before><?php
/**
 * DfView is a view class
 *
 * DfView provide functions for templates and views
 *
 * @author <NAME> <<EMAIL>>
 * @package system.base
 * @since 0.2.1
 */
class DfView
{
    /**
     * Application views path
     * @var string
     */
    public $viewsPath;
    /**
     * Application views template path
     * @var string
     */
    public $templatePath;
    /**
     * View include path
     * @var string
     */
    public $includePath;
    /**
     * Template view
     * @var string
     */
    public $templateView = 'index';
    /**
     * View Data Array
     * @var array
     */
    public $viewData = [];

    public function __construct()
    {
        $this->viewsPath = DfApp::app()->getRuntimePath(true) . '/app/views/';
        $this->templatePath = $this->viewsPath . 'templates/';
    }

    public function render($view, $data = [])
    {
        $this->renderPage($view, $this->templateView, $data);
    }

    private function renderPage($viewName, $template, $data = [])
    {
        $this->viewData = $data;

        $this->includePath = $this->getViewPath($viewName);
        $templatePath = $this->templatePath . $template . '.php';

        if (isset($templatePath)) {
            include($templatePath);
        }
    }

    /**
     * Get View Path
     * @param string $name
     * @return bool
     */
    private function getViewPath($name)
    {
        $locations = ['/'];
        !isset(DfApp::app()->router->controller) ? : $locations[] = DfApp::app()->router->controller;
        !isset(DfApp::app()->router->action) ? : $locations[] = DfApp::app()->router->action;

        return $this->findView($locations, $name);
    }

    /**
     * Find View
     * @param array $locations
     * @param string $name
     * @return bool
     */
    private function findView($locations = [], $name)
    {
        $viewPath = $this->viewsPath;

        foreach ($locations as $id => $location) {
            $viewPath .= ($id == 0 ? '' : '/') . $location;
            $checkPath = $viewPath . '/' . $name . '.php';
            if (file_exists($checkPath)) {
                return $checkPath;
            }
        }

        return false;
    }

    /**
     * Render Include
     */
    private function renderInclude()
    {
        if (!empty($this->includePath)) {
            include($this->includePath);
        } else {
            throw new DfNotFoundException("View path is not defined");
        }
    }
}<commit_msg>Fixes #32: Change include algorithm. Now from actions to root<commit_after><?php
/**
 * DfView is a view class
 *
 * DfView provide functions for templates and views
 *
 * @author <NAME> <<EMAIL>>
 * @package system.base
 * @since 0.2.1
 */
class DfView
{
    /**
     * Application views path
     * @var string
     */
    public $viewsPath;
    /**
     * Application views template path
     * @var string
     */
    public $templatePath;
    /**
     * View include path
     * @var string
     */
    public $includePath;
    /**
     * Template view
     * @var string
     */
    public $templateView = 'index';
    /**
     * View Data Array
     * @var array
     */
    public $viewData = [];

    public function __construct()
    {
        $this->viewsPath = DfApp::app()->getRuntimePath(true) . 'app/views/';
        $this->templatePath = $this->viewsPath . 'templates/';
    }

    public function render($view, $data = [])
    {
        $this->renderPage($view, $this->templateView, $data);
    }

    private function renderPage($viewName, $template, $data = [])
    {
        $this->viewData = $data;

        $this->includePath = $this->getViewPath($viewName);
        $templatePath = $this->templatePath . $template . '.php';

        if (isset($templatePath)) {
            include($templatePath);
        }
    }

    /**
     * Get View Path
     * @param string $name
     * @return bool
     */
    private function getViewPath($name)
    {
        $locations = [''];
        !isset(DfApp::app()->router->controller) ? : $locations[] = DfApp::app()->router->controller;
        !isset(DfApp::app()->router->action) ? : $locations[] = DfApp::app()->router->action;

        return $this->findView($locations, $name);
    }

    /**
     * Find View
     * @param array $locations
     * @param string $name
     * @return bool
     */
    private function findView($locations = [], $name)
    {
        $viewPath = $this->viewsPath;
        $checks = [];

        foreach ($locations as $id => $location) {
            $viewPath .= (intval($id) <= 1 ? '' : '/') . $location;
            $checkPath = $viewPath . (intval($id) == 0 ? '' : '/') . $name . '.php';
            $checks[] = $checkPath;
        }

        foreach (array_reverse($checks, true) as $path) {
            if (file_exists($path)) {
                return $path;
            }
        }

        return false;
    }

    /**
     * Render Include
     */
    private function renderInclude()
    {
        if (!empty($this->includePath)) {
            include($this->includePath);
        } else {
            throw new DfNotFoundException("View path is not defined");
        }
    }
}
{'fraction_non_alphanumeric': 0.15992255566311714, 'fraction_numerical': 0.0021297192642787998, 'mean_word_length': 1.9137055837563453, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 55, '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': '5292406', 'n_tokens_mistral': 1568, 'n_tokens_neox': 1521, 'n_words': 343}