[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of the phpBB Forum Software package. 5 * 6 * @copyright (c) phpBB Limited <https://www.phpbb.com> 7 * @license GNU General Public License, version 2 (GPL-2.0) 8 * 9 * For full copyright and license information, please see 10 * the docs/CREDITS.txt file. 11 * 12 */ 13 14 namespace phpbb\template\twig; 15 16 class environment extends \Twig_Environment 17 { 18 /** @var \phpbb\config\config */ 19 protected $phpbb_config; 20 21 /** @var \phpbb\path_helper */ 22 protected $phpbb_path_helper; 23 24 /** @var \phpbb\extension\manager */ 25 protected $extension_manager; 26 27 /** @var string */ 28 protected $phpbb_root_path; 29 30 /** @var string */ 31 protected $web_root_path; 32 33 /** @var array **/ 34 protected $namespace_look_up_order = array('__main__'); 35 36 /** 37 * Constructor 38 * 39 * @param \phpbb\config\config $phpbb_config The phpBB configuration 40 * @param \phpbb\path_helper $path_helper phpBB path helper 41 * @param \phpbb\extension\manager $extension_manager phpBB extension manager 42 * @param \Twig_LoaderInterface $loader Twig loader interface 43 * @param array $options Array of options to pass to Twig 44 */ 45 public function __construct($phpbb_config, \phpbb\path_helper $path_helper, \phpbb\extension\manager $extension_manager = null, \Twig_LoaderInterface $loader = null, $options = array()) 46 { 47 $this->phpbb_config = $phpbb_config; 48 49 $this->phpbb_path_helper = $path_helper; 50 $this->extension_manager = $extension_manager; 51 52 $this->phpbb_root_path = $this->phpbb_path_helper->get_phpbb_root_path(); 53 $this->web_root_path = $this->phpbb_path_helper->get_web_root_path(); 54 55 return parent::__construct($loader, $options); 56 } 57 58 /** 59 * Get the list of enabled phpBB extensions 60 * 61 * Used in EVENT node 62 * 63 * @return array 64 */ 65 public function get_phpbb_extensions() 66 { 67 return ($this->extension_manager) ? $this->extension_manager->all_enabled() : array(); 68 } 69 70 /** 71 * Get phpBB config 72 * 73 * @return \phpbb\config\config 74 */ 75 public function get_phpbb_config() 76 { 77 return $this->phpbb_config; 78 } 79 80 /** 81 * Get the phpBB root path 82 * 83 * @return string 84 */ 85 public function get_phpbb_root_path() 86 { 87 return $this->phpbb_root_path; 88 } 89 90 /** 91 * Get the web root path 92 * 93 * @return string 94 */ 95 public function get_web_root_path() 96 { 97 return $this->web_root_path; 98 } 99 100 /** 101 * Get the phpbb path helper object 102 * 103 * @return \phpbb\path_helper 104 */ 105 public function get_path_helper() 106 { 107 return $this->phpbb_path_helper; 108 } 109 110 /** 111 * Get the namespace look up order 112 * 113 * @return array 114 */ 115 public function getNamespaceLookUpOrder() 116 { 117 return $this->namespace_look_up_order; 118 } 119 120 /** 121 * Set the namespace look up order to load templates from 122 * 123 * @param array $namespace 124 * @return \Twig_Environment 125 */ 126 public function setNamespaceLookUpOrder($namespace) 127 { 128 $this->namespace_look_up_order = $namespace; 129 130 return $this; 131 } 132 133 /** 134 * Loads a template by name. 135 * 136 * @param string $name The template name 137 * @param integer $index The index if it is an embedded template 138 * @return \Twig_TemplateInterface A template instance representing the given template name 139 * @throws \Twig_Error_Loader 140 */ 141 public function loadTemplate($name, $index = null) 142 { 143 if (strpos($name, '@') === false) 144 { 145 foreach ($this->getNamespaceLookUpOrder() as $namespace) 146 { 147 try 148 { 149 if ($namespace === '__main__') 150 { 151 return parent::loadTemplate($name, $index); 152 } 153 154 return parent::loadTemplate('@' . $namespace . '/' . $name, $index); 155 } 156 catch (\Twig_Error_Loader $e) 157 { 158 } 159 } 160 161 // We were unable to load any templates 162 throw $e; 163 } 164 else 165 { 166 return parent::loadTemplate($name, $index); 167 } 168 } 169 170 /** 171 * Finds a template by name. 172 * 173 * @param string $name The template name 174 * @return string 175 * @throws \Twig_Error_Loader 176 */ 177 public function findTemplate($name) 178 { 179 if (strpos($name, '@') === false) 180 { 181 foreach ($this->getNamespaceLookUpOrder() as $namespace) 182 { 183 try 184 { 185 if ($namespace === '__main__') 186 { 187 return parent::getLoader()->getCacheKey($name); 188 } 189 190 return parent::getLoader()->getCacheKey('@' . $namespace . '/' . $name); 191 } 192 catch (\Twig_Error_Loader $e) 193 { 194 } 195 } 196 197 // We were unable to load any templates 198 throw $e; 199 } 200 else 201 { 202 return parent::getLoader()->getCacheKey($name); 203 } 204 } 205 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |