]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/libs/sysplugins/smarty_internal_method_gettags.php
Add Smarty to Composer
[friendica.git] / vendor / smarty / smarty / libs / sysplugins / smarty_internal_method_gettags.php
1 <?php
2
3 /**
4  * Smarty Method GetTags
5  *
6  * Smarty::getTags() method
7  *
8  * @package    Smarty
9  * @subpackage PluginsInternal
10  * @author     Uwe Tews
11  */
12 class Smarty_Internal_Method_GetTags
13 {
14     /**
15      * Valid for Smarty and template object
16      *
17      * @var int
18      */
19     public $objMap = 3;
20
21     /**
22      * Return array of tag/attributes of all tags used by an template
23      *
24      * @api  Smarty::getTags()
25      * @link http://www.smarty.net/docs/en/api.get.tags.tpl
26      *
27      * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
28      * @param null|string|Smarty_Internal_Template                            $template
29      *
30      * @return array of tag/attributes
31      * @throws \SmartyException
32      */
33     public function getTags(Smarty_Internal_TemplateBase $obj, $template = null)
34     {
35         /* @var Smarty $smarty */
36         $smarty = $obj->_getSmartyObj();
37         if ($obj->_isTplObj() && !isset($template)) {
38             $tpl = clone $obj;
39         } elseif (isset($template) && $template->_isTplObj()) {
40             $tpl = clone $template;
41         } elseif (isset($template) && is_string($template)) {
42             /* @var Smarty_Internal_Template $tpl */
43             $tpl = new $smarty->template_class($template, $smarty);
44             // checks if template exists
45             if (!$tpl->source->exists) {
46                 throw new SmartyException("Unable to load template {$tpl->source->type} '{$tpl->source->name}'");
47             }
48         }
49         if (isset($tpl)) {
50             $tpl->smarty = clone $tpl->smarty;
51             $tpl->smarty->_cache[ 'get_used_tags' ] = true;
52             $tpl->_cache[ 'used_tags' ] = array();
53             $tpl->smarty->merge_compiled_includes = false;
54             $tpl->smarty->disableSecurity();
55             $tpl->caching = false;
56             $tpl->loadCompiler();
57             $tpl->compiler->compileTemplate($tpl);
58             return $tpl->_cache[ 'used_tags' ];
59         }
60         throw new SmartyException("Missing template specification");
61     }
62 }