populate Source Object with meta data from Resource

@param  Smarty_Template_Source   $source    source object
@param  Smarty_Internal_Template $_template template object

@return void
15504
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
    {
        $uid = '';
        $sources = array();
        $exists = true;
        foreach ($_template->smarty->getTemplateDir() as $key => $directory) {
            try {
                $s = Smarty_Resource::source(null, $source->smarty, '[' . $key . ']' . $source->name);
                if (!$s->exists) {
                    continue;
                }
                $sources[$s->uid] = $s;
                $uid .= $s->filepath;
            }
            catch (SmartyException $e) {
            }
        }

        if (!$sources) {
            $source->exists = false;
            $source->template = $_template;

            return;
        }

        $sources = array_reverse($sources, true);
        reset($sources);
        $s = current($sources);

        $source->components = $sources;
        $source->filepath = $s->filepath;
        $source->uid = sha1($uid);
        $source->exists = $exists;
        if ($_template && $_template->smarty->compile_check) {
            $source->timestamp = $s->timestamp;
        }
        // need the template at getContent()
        $source->template = $_template;
    }
573487
public function compileSource($source)
    {
        $result = false;

        $compiler = $this->getCompiler();
        if(is_callable($compiler)) {
            $result = call_user_func($compiler, $source);
        }

        if(!is_string($result)) {
            throw new \RuntimeException(sprintf('The template content cannot be compiled.'));
        }

        return $result;
    }
1347740
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null)
    {
        /** @var Smarty_Internal_Template $_smarty_tpl
         * used in included file
         */
        $_smarty_tpl = $_template;

        return @include $_template->cached->filepath;
    }
1183238
static function fetch($template, $data = array(), $smarty = NULL)
	{
//		if($template[0] == '/')
//			$template = 'xfile:'.$template;

//		PhpConsole\Handler::getInstance()->debug($template, 'tpl');
//		PhpConsole\Handler::getInstance()->debug($data, 'tpldata');

		if(!$smarty)
			$smarty = self::factory();

		$data = array_merge(bors_template::page_data(), $data);
		$smarty->auto_literal = popval($data, 'smarty_auto_literal', $smarty->auto_literal);
		$smarty->assign($data);
		$trace = debug_backtrace();

		$caller_path = NULL;
		$wo_xfile_prefix = str_replace('xfile:', '', $template);

		for($i=1, $stop=count($trace); $i<$stop; $i++)
		{
			if(!empty($trace[$i]['file']))
				$php_file_dir = dirname(@$trace[$i]['file']).'/';
			else
				$php_file_dir = '/unknown/';

			if(file_exists($php_file_dir.$wo_xfile_prefix))
			{
				$caller_path = $php_file_dir;
				break;
			}
		}

		$dirname = dirname($wo_xfile_prefix);
		if($dirname == '.' && ($object = @$data['this']))
			$dirname = dirname($object->real_class_file());

		if(!preg_match("!^\w+:!", $dirname))
			$dirname = "xfile:$dirname";
		if(!($dir_names = $smarty->getTemplateVars('template_dirnames')))
			$dir_names = array();
		array_unshift($dir_names, $dirname);
		array_unshift($dir_names, $caller_path);

		$smarty->assign("template_dirnames", $dir_names);

		$smarty->assign('me', bors()->user());
		$smarty->assign("main_uri", empty($GLOBALS['main_uri']) ? NULL : $GLOBALS['main_uri']);

		// Снести в пользу render_page(), наверное.
		if(!$smarty->templateExists($template))
			$template = self::find_template($template, @$data['this']);

		if(config('debug.execute_trace'))
			bors_debug::execute_trace("smarty3->fetch()");

		$smarty->error_reporting = E_ALL & ~E_NOTICE;
		$result = $smarty->fetch($template);
		$dir_names = $smarty->getTemplateVars('template_dirnames');
		array_shift($dir_names);
		array_shift($dir_names);

		$smarty->assign("template_dirnames", $dir_names);
		return $result;
	}
241296
public function setSource($source): void
    {
        if (!\is_array($source) && !($source instanceof \ArrayAccess)) {
            throw new Grid\GridException('Source of `ArraySource` should be array or implement ArrayAccess interface');
        }
        parent::setSource($source);
    }
59738
function _compile_source($resource_name, &$source_content, &$compiled_content, $cache_include_path=null)
	{
		if (file_exists(SMARTY_DIR . $this->compiler_file)) {
			require_once(SMARTY_DIR . $this->compiler_file);
		} else {
			// use include_path
			require_once($this->compiler_file);
		}


		$smarty_compiler = new $this->compiler_class;

		$smarty_compiler->template_dir      = $this->template_dir;
		$smarty_compiler->compile_dir       = $this->compile_dir;
		$smarty_compiler->plugins_dir       = $this->plugins_dir;
		$smarty_compiler->config_dir        = $this->config_dir;
		$smarty_compiler->force_compile     = $this->force_compile;
		$smarty_compiler->caching           = $this->caching;
		$smarty_compiler->php_handling      = $this->php_handling;
		$smarty_compiler->left_delimiter    = $this->left_delimiter;
		$smarty_compiler->right_delimiter   = $this->right_delimiter;
		$smarty_compiler->_version          = $this->_version;
		$smarty_compiler->security          = $this->security;
		$smarty_compiler->secure_dir        = $this->secure_dir;
		$smarty_compiler->security_settings = $this->security_settings;
		$smarty_compiler->trusted_dir       = $this->trusted_dir;
		$smarty_compiler->use_sub_dirs      = $this->use_sub_dirs;
		$smarty_compiler->_reg_objects      = &$this->_reg_objects;
		$smarty_compiler->_plugins          = &$this->_plugins;
		$smarty_compiler->_tpl_vars         = &$this->_tpl_vars;
		$smarty_compiler->default_modifiers = $this->default_modifiers;
		$smarty_compiler->compile_id        = $this->_compile_id;
		$smarty_compiler->_config            = $this->_config;
		$smarty_compiler->request_use_auto_globals  = $this->request_use_auto_globals;

		if (isset($cache_include_path) && isset($this->_cache_serials[$cache_include_path])) {
			$smarty_compiler->_cache_serial = $this->_cache_serials[$cache_include_path];
		}
		$smarty_compiler->_cache_include = $cache_include_path;


		$_results = $smarty_compiler->_compile_file($resource_name, $source_content, $compiled_content);

		if ($smarty_compiler->_cache_serial) {
			$this->_cache_include_info = array(
                'cache_serial'=>$smarty_compiler->_cache_serial
			,'plugins_code'=>$smarty_compiler->_plugins_code
			,'include_file_path' => $cache_include_path);

		} else {
			$this->_cache_include_info = null;

		}

		return $_results;
	}
125449
public function write(Smarty_Internal_Template $_template, $content)
    {
        if (!$_template->source->recompiled) {
            if ($this->handler->writeCachedContent($_template, $content)) {
                $this->content = null;
                $this->timestamp = time();
                $this->exists = true;
                $this->valid = true;
                if ($_template->smarty->cache_locking) {
                    $this->handler->releaseLock($_template->smarty, $this);
                }

                return true;
            }
        }

        return false;
    }
342274
public function populateCompiledFilepath(Smarty_Internal_Template $_template)
    {
        $_compile_id = isset($_template->compile_id) ? preg_replace('![^\w]+!', '_', $_template->compile_id) : null;
        if ($_template->source->isConfig) {
            $_flag = '_' .
                ((int) $_template->smarty->config_read_hidden + (int) $_template->smarty->config_booleanize * 2 +
                    (int) $_template->smarty->config_overwrite * 4);
        } else {
            $_flag =
                '_' . ((int) $_template->smarty->merge_compiled_includes + (int) $_template->smarty->escape_html * 2);
        }
        $_filepath = $_template->source->uid . $_flag;
        // if use_sub_dirs, break file into directories
        if ($_template->smarty->use_sub_dirs) {
            $_filepath = substr($_filepath, 0, 2) . DS . substr($_filepath, 2, 2) . DS . substr($_filepath, 4, 2) . DS .
                $_filepath;
        }
        $_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^';
        if (isset($_compile_id)) {
            $_filepath = $_compile_id . $_compile_dir_sep . $_filepath;
        }
        // caching token
        if ($_template->caching) {
            $_cache = '.cache';
        } else {
            $_cache = '';
        }
        $_compile_dir = $_template->smarty->getCompileDir();
        // set basename if not specified
        $_basename = $_template->source->handler->getBasename($_template->source);
        if ($_basename === null) {
            $_basename = basename(preg_replace('![^\w]+!', '_', $_template->source->name));
        }
        // separate (optional) basename by dot
        if ($_basename) {
            $_basename = '.' . $_basename;
        }

        $this->filepath = $_compile_dir . $_filepath . '.' . $_template->source->type . $_basename . $_cache . '.php';
        $this->exists = is_file($this->filepath);
        if (!$this->exists) {
            $this->timestamp = false;
        }
    }
511803
public function ignore(Smarty_Internal_Template $template)
    {
        // calculate Uid if not already done
        if ($template->source->uid == '') {
            $template->source->filepath;
        }
        $this->ignore_uid[$template->source->uid] = true;
    }
204700
public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template)
    {
        $compiled->filepath = false;
        $compiled->timestamp = false;
        $compiled->exists = false;
    }
715581
public function updateCache(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $no_output_filter)
    {
        if ($_template->source->handler->uncompiled) {
            ob_start();
            $_template->source->render($_template);
        } else {
            ob_start();
            if (!isset($_template->compiled)) {
                $_template->loadCompiled();
            }
            $_template->compiled->render($_template);
        }
        if ($_template->smarty->debugging) {
            $_template->smarty->_debug->start_cache($_template);
        }
        $this->removeNoCacheHash($cached, $_template, $no_output_filter);
        $compile_check = $_template->smarty->compile_check;
        $_template->smarty->compile_check = false;
        if (isset($_template->parent) && $_template->parent->_objType == 2) {
            $_template->compiled->unifunc = $_template->parent->compiled->unifunc;
        }
        if (!$_template->cached->processed) {
            $_template->cached->process($_template, true);
        }
        $_template->smarty->compile_check = $compile_check;
        $cached->getRenderedTemplateCode($_template);
        if ($_template->smarty->debugging) {
            $_template->smarty->_debug->end_cache($_template);
        }
    }
105706
public static function _getDefaultTemplate(Smarty_Template_Source $source)
    {
        if ($source->isConfig) {
            $default_handler = $source->smarty->default_config_handler_func;
        } else {
            $default_handler = $source->smarty->default_template_handler_func;
        }
        $_content = $_timestamp = null;
        $_return = call_user_func_array($default_handler, array($source->type, $source->name, &$_content, &$_timestamp,
                                                                $source->smarty));
        if (is_string($_return)) {
            $source->exists = is_file($_return);
            if ($source->exists) {
                $source->timestamp = filemtime($_return);
            }
            $source->filepath = $_return;
        } elseif ($_return === true) {
            $source->content = $_content;
            $source->timestamp = $_timestamp;
            $source->exists = true;
            $source->handler->recompiled = true;
            $source->filepath = false;
        }
    }
908193
public function template($template, $data = Array()){
        \Template::with($template, $data);
        \View::serve();
    }
1112200
public function read(Smarty_Internal_Template $_template)
    {
        if (!$_template->source->handler->recompiled) {
            return $this->handler->readCachedContent($_template);
        }
        return false;
    }
185864
public function prepareSource(&$source = null, $reference = false)
    {
        $headers = [];

        foreach ((array) $source as $key => $value) {
            $headers[HeaderHelper::normalizeHeaderName($key)] = implode(', ', $value);
        }

        parent::prepareSource($headers, $reference);
    }
1354054
public function end_compile(Smarty_Internal_Template $template)
    {
        if (!empty($template->compiler->trace_uid)) {
            $key = $template->compiler->trace_uid;
        } else {
            if (isset($this->ignore_uid[$template->source->uid])) {
                return;
            }

            $key = $this->get_key($template);
        }
        $this->template_data[$this->index][$key]['compile_time'] +=
            microtime(true) - $this->template_data[$this->index][$key]['start_time'];
    }
962811
public static function fillIfKeysExist(array $template, array $source)
    {
        $result = $template;
        foreach ($template as $key => $value) {
            if (array_key_exists($key, $source)) {
                $result[$key] = $source[$key];
            }
        }

        return $result;
    }