當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Twig_Loader_Filesystem::validateName方法代碼示例

本文整理匯總了PHP中Twig_Loader_Filesystem::validateName方法的典型用法代碼示例。如果您正苦於以下問題:PHP Twig_Loader_Filesystem::validateName方法的具體用法?PHP Twig_Loader_Filesystem::validateName怎麽用?PHP Twig_Loader_Filesystem::validateName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Twig_Loader_Filesystem的用法示例。


在下文中一共展示了Twig_Loader_Filesystem::validateName方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: findTemplate

 /**
  * Find the template
  *
  * Override for Twig_Loader_Filesystem::findTemplate to add support
  *	for loading from safe directories.
  */
 protected function findTemplate($name)
 {
     $name = (string) $name;
     // normalize name
     $name = preg_replace('#/{2,}#', '/', strtr($name, '\\', '/'));
     // If this is in the cache we can skip the entire process below
     //	as it should have already been validated
     if (isset($this->cache[$name])) {
         return $this->cache[$name];
     }
     // First, find the template name. The override above of validateName
     //	causes the validateName process to be skipped for this call
     $file = parent::findTemplate($name);
     try {
         // Try validating the name (which may throw an exception)
         parent::validateName($name);
     } catch (\Twig_Error_Loader $e) {
         if (strpos($e->getRawMessage(), 'Looks like you try to load a template outside configured directories') === 0) {
             // Ok, so outside of the configured template directories, we
             //	can now check if we're within a "safe" directory
             // Find the real path of the directory the file is in
             $directory = src_realpath(dirname($file));
             if ($directory === false) {
                 // Some sort of error finding the actual path, must throw the exception
                 throw $e;
             }
             foreach ($this->safe_directories as $safe_directory) {
                 if (strpos($directory, $safe_directory) === 0) {
                     // The directory being loaded is below a directory
                     // that is "safe". We're good to load it!
                     return $file;
                 }
             }
         }
         // Not within any safe directories
         throw $e;
     }
     // No exception from validateName, safe to load.
     return $file;
 }
開發者ID:,項目名稱:,代碼行數:46,代碼來源:


注:本文中的Twig_Loader_Filesystem::validateName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。