Compiles template extensions.

@param  string $template Template
@return string
19093
protected function extensions(string $template): string
	{
		// Replace first occurance of extends tag with an empty string
		// and append the template with a view tag

		if(preg_match('/^{%\s*extends:(.*?)\s*%}/i', $template, $matches) > 0)
		{
			$replacement = '<?php $__view__ = $__viewfactory__->create(' . $matches[1] . '); $__renderer__ = $__view__->getRenderer(); ?>';

			$template = preg_replace('/^{%\s*extends:(.*?)\s*%}/i', $replacement, $template, 1);

			$template .= '<?php echo $__view__->render(); ?>';
		}

		return $template;
	}
153070
protected function _renderPragmas($template) {
		$this->_localPragmas = $this->_pragmas;

		// no pragmas
		if (strpos($template, $this->_otag . '%') === false) {
			return $template;
		}

		$regEx = $this->_preparePragmaRegEx($this->_otag, $this->_ctag);
		return preg_replace_callback($regEx, array($this, '_renderPragma'), $template);
	}
473877
public function templateExtensions()
    {
        return array(
            new Extensions\Template\Extension\Debug(
                $this->components()->debug()
            ),
            new Extensions\Template\Extension\RouteTranslator(
                'http',
                $this->builder->http()->routeTranslator()
            )
        );
    }
324798
protected function templateExists($template)
    {
        $template = (string) $template;

        $loader = $this->twig->getLoader();
        if ($loader instanceof ExistsLoaderInterface || method_exists($loader, 'exists')) {
            return $loader->exists($template);
        }

        try {
            $loader->getSourceContext($template)->getCode();

            return true;
        } catch (LoaderError $e) {
        }

        return false;
    }
878121
private function getRenderer(string $template): string
    {
        if (is_readable($template) === false) {
            throw new View\Exception('Could not open file "' . basename($template) . '"');
        }

        $suffix = strtolower(pathinfo($template, PATHINFO_EXTENSION));

        if (isset($this->renderer[$suffix]) === false) {
            throw new View\Exception('No template engine registered for file extension "' . $suffix . '"');
        }

        return $this->renderer[$suffix];
    }
895890
public function setHTMLTemplate($template)
    {
        if (substr($template, -3) == '.ss') {
            $template = substr($template, 0, -3);
        }
        $this->HTMLTemplate = $template;

        return $this;
    }
1050836
protected function getTemplate($template)
    {
        $template = config("imagecache.templates.{$template}");

        switch (true) {
            // closure template found
            case is_callable($template):
                return $template;

            // filter template found
            case class_exists($template):
                return new $template;

            default:
                // template not found
                abort(404);
                break;
        }
    }
601046
protected function templateExists($template)
    {
        if ($this->isBackoffice() || $this->inBackofficeRoot()) {
            $template = '@ClasticBackofficeBundle/Exception/exception_full.html.twig';
        }

        return parent::templateExists($template);
    }
202567
private function _getParameterPattern($template)
	{
		// support star matches
		$template = preg_replace('/\*/','.*?',$template);

		return sprintf('#^%s$#',
			preg_replace_callback(
				self::REGEX_PARAM,
				array($this, '_typePatternCallback'),
				$template
			)
		);
	}
186565
public function compile($template, $data = array())
    {
        $compiler = new BladeCompiler($this->files, 'theme');

        // Get blade compiler.
        $parsed = $compiler->compileString($template);

        ob_start() and extract($data, EXTR_SKIP);
        try {
            eval('?>'.$parsed);
        } catch (\Exception $e) {
            ob_end_clean(); throw $e;
        }
        $template = ob_get_contents();
        ob_end_clean();

        return $template;
    }
733910
private function parseTemplateFile($template)
    {
        if ('' == pathinfo($template, PATHINFO_EXTENSION)) {
            if (strpos($template, '@')) {
                list($module, $template) = explode('@', $template);
            }

            if (0 !== strpos($template, '/')) {
                $template = str_replace(['/', ':'], $this->config['view_depr'], $template);
            } else {
                $template = str_replace(['/', ':'], $this->config['view_depr'], substr($template, 1));
            }

            if ($this->config['view_base']) {
                $module = isset($module) ? $module : '';
                $path   = $this->config['view_base'] . ($module ? $module . DIRECTORY_SEPARATOR : '');
            } else {
                $path = $this->config['view_path'];
            }

            $template = $path . $template . '.' . ltrim($this->config['view_suffix'], '.');
        }

        if (is_file($template)) {
            // 记录模板文件的更新时间
            $this->includeFile[$template] = filemtime($template);

            return $template;
        } else {
            throw new TemplateNotFoundException('template not exists:' . $template, $template);
        }
    }
1351301
public function getCompiledFile($template)
	{	
		$tplFile = static::getTemplateFile($template);
		if ($this->options['engine'] === 'php'){
			return $tplFile;
		}
		
		if(file_exists($tplFile)) {
		    if (is_file($template)) {
		        $tplCompiledFile = static::getCompiledPath() . '/_file/' . md5($template) . '.php';
		    } else {
                $tplCompiledFile = static::getCompiledPath() . $this->_getRelativeTemplate($template) . '.php';
		    }
		    
			if (!$this->options['isCompiled'] || !file_exists($tplCompiledFile) || (@filemtime($tplFile) > @filemtime($tplCompiledFile)) ) {
				$tplCompiledPath = dirname($tplCompiledFile);
				if (!file_exists($tplCompiledPath)) {
					Dir::create($tplCompiledPath, 0755);
				}
				
				$content = file_get_contents($tplFile);
				$content = $this->parse($content);
				
				$strlen = file_put_contents($tplCompiledFile, $content);
				chmod ($tplCompiledFile, 0755);
			}
			
			return $tplCompiledFile;
		} else {
			throw new ViewException('template: ' . $tplFile. ' is not exists.');
		}
	}
507701
protected function collectVerbatims(string $template): string
	{
		return preg_replace_callback('/{%\s*verbatim\s*%}(.*?){%\s*endverbatim\s*%}/is', function($matches)
		{
			$this->verbatims[] = $matches[1];

			return static::VERBATIM_PLACEHOLDER;
		}, $template);
	}
207655
private function tryCompile($template)
    {
        $cache = $this->getMaskedFileName($template);
        $path = $this->getConfig('cache_folder');

        if (! file_exists($path)) {
            mkdir($path, 0777, true); // recursive path creating
        }

        if (file_exists($cache) && (filemtime($cache) > filemtime($template))) {
            // CACHED
        } else {
            $this->writeToFile(
                $cache,
                $this->compile($template),
                $this->getFile()
            );
        }

        return $this->readBuffer($cache);
    }
1313107
public static function update_template($template) {

        $params = self::validate_parameters(self::update_template_parameters(), array('template' => $template));
        $params = $params['template'];
        $template = api::read_template($params['id']);
        self::validate_context($template->get_context());

        $params = (object) $params;

        return api::update_template($params);
    }
183875
public function setTemplate($template)
    {
        if(!$template instanceof TemplateInterface)
        {
            if(empty($template) || (is_string($template) && strpos($template, '.') === false) )
            {
                $identifier         = $this->getIdentifier()->toArray();
                $identifier['path'] = array('template');
                $identifier['name'] = $template;

                $identifier = $this->getIdentifier($identifier);
            }
            else $identifier = $this->getIdentifier($template);

            $template = $identifier;
        }

        $this->__template = $template;

        return $this->__template;
    }
899961
protected function renderTemplate($template)
    {
        // Build allowed extensions
        $allowedExtensions = new ArrayList();
        foreach (File::getAllowedExtensions() as $extension) {
            if ($extension) {
                $allowedExtensions->push(new ArrayData([
                    'Extension' => preg_quote($extension)
                ]));
            }
        }

        Config::nest();
        Config::modify()->set(SSViewer::class, 'source_file_comments', false);

        $viewer = SSViewer::create([$template]);
        $result = (string)$viewer->process(new ArrayData([
            'AllowedExtensions' => $allowedExtensions
        ]));

        Config::unnest();

        return $result;
    }