<commit_before><?php namespace Drivers\Templates;

/**
 *This class handles rendering of view files
 *
 *@author <NAME> <<EMAIL>>
 *@copyright Copyright (c) 2015 - 2020 <NAME>
 *@link http://libraries.gliver.io
 *@category Core
 *@package Core\Helpers\View
 */

use Drivers\Registry;
use Helpers\Path\Path;
use Drivers\Templates\BaseTemplateClass;
use Drivers\Templates\TemplateException;

class View {

    /**
    *@var \Object The template parser class instance
    */
    private static $BaseTemplateObject = null;

    /**
    *@var array The variables to be injected into the view files
    */
    private static $variables = array();
     
    /**
     *This is the constructor class. We make this private to avoid creating instances of
     *this object
     *
     *@param null
     *@return void
     */
    private function __construct() {}

    /**
     *This method stops creation of a copy of this object by making it private
     *
     *@param null
     *@return void
     *
     */
    private function __clone(){}

    /**
    *This method returns the template parser object
    *
    *@param null
    *@return 
    */
    public static function getBaseTemplateObject()
    {
        //check if the BaseTemplateClass has been defined, if not create instance and return
        if( is_null(self::$BaseTemplateObject))
        {
            self::$BaseTemplateObject = new BaseTemplateClass();

            return self::$BaseTemplateObject;
        }

        else return self::$BaseTemplateObject;

    }

    /**
    *This method gets the header content for importing classes
    *
    *@param null
    *@return string The content of the header section
    */
    private static function getHeaderContent()
    {
        //get the content of the aliases array
        $class_aliases_namespaces = Registry::getConfig()['aliases'];

        //define array to contain numeric class_alias_namesplace
        $class_alias_array = array();

        //convert associative array to indexed array
        foreach($class_aliases_namespaces as $namespace => $alias)
        {
            //add elements to the class_alias_array array
            $class_alias_array[] = "use $namespace as $alias;";

        }

        //convert aliases array to string
        $class_alias_string = implode('', $class_alias_array);

        return sprintf('<?php %s function request_exec_time(){return microtime(true) - Registry::$gliver_app_start;}?>', $class_alias_string);

    } 

    /**
     * This method sets the view file variables to be injected in view file.
     * @param string $key The key with which to store the data
     * @param mixed $data The data in any format to inject into the view file
     * @return static class
     */
    public  static function with($key, $data)
    {
        //set the value of the $variables property
        self::$variables[$key] = $data;

        //return the static class
        return new static;

    }
 
    /**<commit_msg>SEtting the with() method of the View class to accept key value pairs for arguments<commit_after><?php namespace Drivers\Templates;

/**
 *This class handles rendering of view files
 *
 *@author <NAME> <<EMAIL>>
 *@copyright Copyright (c) 2015 - 2020 <NAME>
 *@link http://libraries.gliver.io
 *@category Core
 *@package Core\Helpers\View
 */

use Drivers\Registry;
use Helpers\Path\Path;
use Drivers\Templates\BaseTemplateClass;
use Drivers\Templates\TemplateException;

class View {

    /**
    *@var \Object The template parser class instance
    */
    private static $BaseTemplateObject = null;

    /**
    *@var array The variables to be injected into the view files
    */
    private static $variables = array();
     
    /**
     *This is the constructor class. We make this private to avoid creating instances of
     *this object
     *
     *@param null
     *@return void
     */
    private function __construct() {}

    /**
     *This method stops creation of a copy of this object by making it private
     *
     *@param null
     *@return void
     *
     */
    private function __clone(){}

    /**
    *This method returns the template parser object
    *
    *@param null
    *@return 
    */
    public static function getBaseTemplateObject()
    {
        //check if the BaseTemplateClass has been defined, if not create instance and return
        if( is_null(self::$BaseTemplateObject))
        {
            self::$BaseTemplateObject = new BaseTemplateClass();

            return self::$BaseTemplateObject;
        }

        else return self::$BaseTemplateObject;

    }

    /**
    *This method gets the header content for importing classes
    *
    *@param null
    *@return string The content of the header section
    */
    private static function getHeaderContent()
    {
        //get the content of the aliases array
        $class_aliases_namespaces = Registry::getConfig()['aliases'];

        //define array to contain numeric class_alias_namesplace
        $class_alias_array = array();

        //convert associative array to indexed array
        foreach($class_aliases_namespaces as $namespace => $alias)
        {
            //add elements to the class_alias_array array
            $class_alias_array[] = "use $namespace as $alias;";

        }

        //convert aliases array to string
        $class_alias_string = implode('', $class_alias_array);

        return sprintf('<?php %s function request_exec_time(){return microtime(true) - Registry::$gliver_app_start;}?>', $class_alias_string);

    } 

    /**
     * This method sets the view file variables to be injected in view file.
     * @param string $key The key with which to store the data
     * @param mixed $data The data in any format to inject into the view file
     * @return static class
     */
    public  static function with($key, $data)
    {
        //set the value of the $variables property
        self::$variables[] = array($key => $data);

        //return the static class
        return new static;

    }
 
    /**
{'fraction_non_alphanumeric': 0.09533300116259757, 'fraction_numerical': 0.0026573658860654377, 'mean_word_length': 2.491014492753623, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, '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': '3083861', 'n_tokens_mistral': 1654, 'n_tokens_neox': 1587, 'n_words': 577}