<commit_before><?php
namespace Colibri\Controller;

use Colibri\View\Layout;
use Colibri\View\PhpTemplate;
use Colibri\Config\Config;

/**
 * Views Controller abstract class.
 * Extends from this class & place code for actions methods.
 *
 * @author        <NAME> aka alek13 <<EMAIL>>
 *
 * @property bool $showProfilerInfoOnDebug ...
 * @property bool $showAppDevToolsOnDebug  ...
 *
 */
abstract
class ViewsController extends Base
{
    /**
     * @var PhpTemplate
     */
    protected $template = null;
    /**
     * @var    bool tells to core to use template or not
     */
    protected $useTemplate = true;
    /**
     * @var    bool
     */
    protected $useBackbone = true;
    /**
     * @var bool
     */
    protected $_showProfilerInfoOnDebug = true;
    /**
     * @var bool
     */
    protected $_showAppDevToolsOnDebug = true;

    private $divPath = null;
    private $divPrefix = null;
    private $divPostfix = null;



    protected function init()
    {
        parent::init();
        $this->divPath    = $this->_module . '/' . Config::divisions($this->_division);
        $this->divPrefix  = ($this->_division === '' ? '' : $this->_division . '_');
        $this->divPostfix = ($this->_division === '' ? '' : '.' . $this->_division);
    }


    public function setUp()
    {
        $this->template = new PhpTemplate();
    }

    /**
     */
    public function    tearDown()
    {
        if (!$this->useTemplate) {
            return;
        }

        if ($this->template->getFilename() === null) {
            $tplPath = sprintf(MODULE_TEMPLATES, $this->divPath);
            $tplName = $tplPath . $this->_method . '.php';
            if (file_exists($tplName)) {
                $this->template->load($tplName);
            }
        }


        if (!$this->useBackbone) {
            if ($this->template->getFilename() === null) {
                throw new \Exception('template not loaded.');
            }
            $this->_response = $this->template->compile();
            return;
        }

        $this->setUpLayout();

        $this->_response = Layout::compile(
            $this->template->getFilename() !== null
                ? $this->template->compile()
                : (DEBUG ? 'DEBUG Info: template not autoloaded.<br/> no such file: ' . str_replace(ROOT, '', $tplName) : '')
        );
    }

    private function setUpLayout()
    {
        if (Layout::filename()) {
            return;
        }

        Layout::filename('backbone' . $this->divPostfix . '.php');

        // TODO: bring out into application config ??
        Layout::addJsText(
	        'var VND=\'' . VND . '\';' . "\n" .
            'var MOD=\'' . MOD . '\';' . "\n" .
            'var IMG=\'' . RES_IMG . '\';' . "\n" .
            'var JS =\'' . RES_JS . '\';' . "\n" .
            'var CSS=\'' . RES_CSS . '\';' . "\n" .
            'var SWF=\'' . RES_SWF . '\';' . "\n" .
            'var PTO=\'' . RES_IMG_PTO . '\';'
        );
        Layout::addJsMgr('backbone' . ($this->_division === '' ? '' : '_' . $this->_division));
        Layout::addCss('backbone' . $this->divPostfix . '.css');

        $fileBaseName = $this->_module . '_' . $this->_method;
        // add default js manager
        $jsPath   = $this->divPath . '/js/managers/';
        $jsName   = $this->divPrefix . $fileBaseName;
        $fileName = MODULES . $jsPath . $jsName . '_mgr.js';
        if (file_exists($fileName)) {
            Layout::addJsMgr($jsName, MOD . $jsPath);
        }

        // add default css
        $cssPath  = $this->divPath . '/css/';
        $cssName  = $this->divPrefix . $fileBaseName . '.css';
        $fileName = MODULES . $cssPath . $cssName;
        if (file_exists($fileName)) {
            Layout::addCss($cssName, MOD . $cssPath);
        }
    }
}
<commit_msg>add short template vars setter<commit_after><?php
namespace Colibri\Controller;

use Colibri\View\Layout;
use Colibri\View\PhpTemplate;
use Colibri\Config\Config;

/**
 * Views Controller abstract class.
 * Extends from this class & place code for actions methods.
 *
 * @author        <NAME> aka alek13 <<EMAIL>>
 *
 * @property bool $showProfilerInfoOnDebug ...
 * @property bool $showAppDevToolsOnDebug  ...
 *
 */
abstract
class ViewsController extends Base
{
    /**
     * @var PhpTemplate
     */
    protected $template = null;
    /**
     * @var    bool tells to core to use template or not
     */
    protected $useTemplate = true;
    /**
     * @var    bool
     */
    protected $useBackbone = true;
    /**
     * @var bool
     */
    protected $_showProfilerInfoOnDebug = true;
    /**
     * @var bool
     */
    protected $_showAppDevToolsOnDebug = true;

    private $divPath = null;
    private $divPrefix = null;
    private $divPostfix = null;



    protected function init()
    {
        parent::init();
        $this->divPath    = $this->_module . '/' . Config::divisions($this->_division);
        $this->divPrefix  = ($this->_division === '' ? '' : $this->_division . '_');
        $this->divPostfix = ($this->_division === '' ? '' : '.' . $this->_division);
    }


    public function setUp()
    {
        $this->template = new PhpTemplate();
    }

    /**
     * @param array $variables
     */
    public function view(array $variables)
    {
        $this->template->setVars($variables);
    }

    /**
     */
    public function    tearDown()
    {
        if (!$this->useTemplate) {
            return;
        }

        if ($this->template->getFilename() === null) {
            $tplPath = sprintf(MODULE_TEMPLATES, $this->divPath);
            $tplName = $tplPath . $this->_method . '.php';
            if (file_exists($tplName)) {
                $this->template->load($tplName);
            }
        }


        if (!$this->useBackbone) {
            if ($this->template->getFilename() === null) {
                throw new \Exception('template not loaded.');
            }
            $this->_response = $this->template->compile();
            return;
        }

        $this->setUpLayout();

        $this->_response = Layout::compile(
            $this->template->getFilename() !== null
                ? $this->template->compile()
                : (DEBUG ? 'DEBUG Info: template not autoloaded.<br/> no such file: ' . str_replace(ROOT, '', $tplName) : '')
        );
    }

    private function setUpLayout()
    {
        if (Layout::filename()) {
            return;
        }

        Layout::filename('backbone' . $this->divPostfix . '.php');

        // TODO: bring out into application config ??
        Layout::addJsText(
            'var VND=\'' . VND . '\';' . "\n" .
            'var MOD=\'' . MOD . '\';' . "\n" .
            'var IMG=\'' . RES_IMG . '\';' . "\n" .
            'var JS =\'' . RES_JS . '\';' . "\n" .
            'var CSS=\'' . RES_CSS . '\';' . "\n" .
            'var SWF=\'' . RES_SWF . '\';' . "\n" .
            'var PTO=\'' . RES_IMG_PTO . '\';'
        );
        Layout::addJsMgr('backbone' . ($this->_division === '' ? '' : '_' . $this->_division));
        Layout::addCss('backbone' . $this->divPostfix . '.css');

        $fileBaseName = $this->_module . '_' . $this->_method;
        // add default js manager
        $jsPath   = $this->divPath . '/js/managers/';
        $jsName   = $this->divPrefix . $fileBaseName;
        $fileName = MODULES . $jsPath . $jsName . '_mgr.js';
        if (file_exists($fileName)) {
            Layout::addJsMgr($jsName, MOD . $jsPath);
        }

        // add default css
        $cssPath  = $this->divPath . '/css/';
        $cssName  = $this->divPrefix . $fileBaseName . '.css';
        $fileName = MODULES . $cssPath . $cssName;
        if (file_exists($fileName)) {
            Layout::addCss($cssName, MOD . $cssPath);
        }
    }
}

{'fraction_non_alphanumeric': 0.17599382477807796, 'fraction_numerical': 0.0005146018268364853, 'mean_word_length': 1.7704918032786885, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 91, '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': '1856356', 'n_tokens_mistral': 2412, 'n_tokens_neox': 2406, 'n_words': 490}