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


PHP Twig_Loader_Filesystem::findTemplate方法代碼示例

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


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

示例1: findTemplate

 /**
  * Returns the path to the template file.
  *
  * The file locator is used to locate the template when the naming convention
  * is the symfony one (i.e. the name can be parsed).
  * Otherwise the template is located using the locator from the twig library.
  *
  * @param string|TemplateReferenceInterface $template The template
  * @param bool                              $throw    When true, a \Twig_Error_Loader exception will be thrown if a template could not be found
  *
  * @return string The path to the template file
  *
  * @throws \Twig_Error_Loader if the template could not be found
  */
 protected function findTemplate($template, $throw = true)
 {
     $logicalName = (string) $template;
     if (isset($this->cache[$logicalName])) {
         return $this->cache[$logicalName];
     }
     $file = null;
     $previous = null;
     try {
         $file = parent::findTemplate($logicalName);
     } catch (\Twig_Error_Loader $e) {
         $twigLoaderException = $e;
         // for BC
         try {
             $template = $this->parser->parse($template);
             $file = $this->locator->locate($template);
         } catch (\Exception $e) {
         }
     }
     if (false === $file || null === $file) {
         if ($throw) {
             throw $twigLoaderException;
         }
         return false;
     }
     return $this->cache[$logicalName] = $file;
 }
開發者ID:symfony,項目名稱:symfony,代碼行數:41,代碼來源:FilesystemLoader.php

示例2: findTemplate

 /**
  * Returns the path to the template file.
  *
  * The file locator is used to locate the template when the naming convention
  * is the symfony one (i.e. the name can be parsed).
  * Otherwise the template is located using the locator from the twig library.
  *
  * @param string|TemplateReferenceInterface $template The template
  *
  * @throws \Twig_Error_Loader if the template could not be found
  *
  * @return string The path to the template file
  */
 protected function findTemplate($template)
 {
     $logicalName = (string) $template;
     if (isset($this->cache[$logicalName])) {
         return $this->cache[$logicalName];
     }
     $file = null;
     $previous = null;
     try {
         $template = $this->parser->parse($template);
         try {
             $file = $this->locator->locate($template);
         } catch (\InvalidArgumentException $e) {
             $previous = $e;
         }
     } catch (\Exception $e) {
         try {
             $file = parent::findTemplate($template);
         } catch (\Twig_Error_Loader $e) {
             $previous = $e;
         }
     }
     if (false === $file || null === $file) {
         throw new \Twig_Error_Loader(sprintf('Unable to find template "%s".', $logicalName), -1, null, $previous);
     }
     return $this->cache[$logicalName] = $file;
 }
開發者ID:dragoonis,項目名稱:framework,代碼行數:40,代碼來源:FileSystemLoader.php

示例3: findTemplate

    protected function findTemplate($name)
    {
        // strip away bundle name
        $parts = explode(':', $name);

        return parent::findTemplate(end($parts));
    }
開發者ID:nacef,項目名稱:symfony,代碼行數:7,代碼來源:StubFilesystemLoader.php

示例4: findTemplate

 public function findTemplate($name)
 {
     try {
         return parent::findTemplate($name . $this->extension);
     } catch (\Exception $e) {
         return parent::findTemplate($name);
     }
 }
開發者ID:reekoheek,項目名稱:twig-theme,代碼行數:8,代碼來源:Filesystem.php

示例5: findTemplate

 /**
  * @param $name
  * @return mixed
  */
 protected function findTemplate($name)
 {
     if (isset($this->cache[$name])) {
         return $this->cache[$name];
     }
     if (is_file($name)) {
         $this->cache[$name] = $name;
         return $name;
     }
     return parent::findTemplate($name);
 }
開發者ID:hoangsoft90,項目名稱:hw-hoangweb-plugin,代碼行數:15,代碼來源:class-template-twig-system.php

示例6: findTemplate

 protected function findTemplate($name)
 {
     if (null !== $this->locator) {
         if (isset($this->cache[$name])) {
             return $this->cache[$name];
         }
         if ($path = call_user_func($this->locator, $name)) {
             return $this->cache[$name] = $path;
         }
     }
     return parent::findTemplate($name);
 }
開發者ID:ddliu,項目名稱:tinyark,代碼行數:12,代碼來源:loader.php

示例7: findTemplate

 /**
  * Do same stuff than Twig_Loader_Filesystem::exists() plus returns the file
  * itself if it is readable.
  *
  * @see  Twig_Loader_Filesystem::findTemplate()
  */
 protected function findTemplate($name)
 {
     try {
         return parent::findTemplate($name);
     } catch (\Twig_Error_Loader $e) {
         $namespace = self::MAIN_NAMESPACE;
         if (is_readable($name)) {
             return $name;
         }
         throw new \Twig_Error_Loader(sprintf('Unable to find template "%s" (looked into: %s).', $name, implode(', ', $this->paths[$namespace])));
     }
 }
開發者ID:gobjila,項目名稱:BackBee,代碼行數:18,代碼來源:TwigLoaderFilesystem.php

示例8: findTemplate

 /**
  * @param array|string $names
  * @throws \Twig_Error_Loader
  * @return string
  */
 protected function findTemplate($names)
 {
     if (!is_array($names)) {
         return parent::findTemplate($names);
     }
     foreach ($names as $name) {
         try {
             return parent::findTemplate($name);
         } catch (\Twig_Error_Loader $e) {
         }
     }
     throw new \Twig_Error_Loader(sprintf('Unable to find template "%s".', implode(', ', $names)));
 }
開發者ID:buildwithcraft,項目名稱:craft-utensils,代碼行數:18,代碼來源:Filesystem.php

示例9: findTemplate

 /**
  * {@inheritdoc}
  */
 protected function findTemplate($name)
 {
     $real_name = realpath($name);
     // Make the filename relative to the template directory
     foreach ($this->getPaths() as $path) {
         $real_path = realpath($path);
         if (strpos($real_name, $real_path) === 0) {
             $name = ltrim(str_replace($real_path, '', $real_name), '/');
             break;
         }
     }
     // Ensure that the file extension is always present
     if (!preg_match("/\\.{$this->extension}\$/", $name)) {
         $name .= ".{$this->extension}";
     }
     return parent::findTemplate($name);
 }
開發者ID:akuzemchak,項目名稱:laratwig,代碼行數:20,代碼來源:FileLoader.php

示例10: 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,代碼來源:

示例11: findTemplate

 /**
  * Returns the path to the template file
  *
  * @param $name The template logical name
  *
  * @return string The path to the template file
  */
 protected function findTemplate($name)
 {
     try {
         $tpl = $this->parser->parse($name);
     } catch (\Exception $e) {
         return parent::findTemplate($name);
     }
     if (isset($this->cache[$key = $tpl->getLogicalName()])) {
         return $this->cache[$key];
     }
     $file = null;
     $previous = null;
     try {
         $file = $this->locator->locate($tpl);
     } catch (\InvalidArgumentException $e) {
         $previous = $e;
     }
     if (false === $file || null === $file) {
         throw new \Twig_Error_Loader(sprintf('Unable to find template "%s".', $tpl), -1, null, $previous);
     }
     return $this->cache[$key] = $file;
 }
開發者ID:renegare,項目名稱:symfony,代碼行數:29,代碼來源:FilesystemLoader.php

示例12: getFinalName

 /**
  * Get the final name where a template lives, regardless of whether it was called with an extension or not.
  *
  *
  * @param string $name The template name.
  * @return string The final template name.
  *
  * @throws \Twig_Error_Loader
  */
 public function getFinalName($name)
 {
     try {
         return parent::findTemplate($name);
     } catch (\Twig_Error_Loader $e) {
         $exts = \App::config('TEMPLATE_EXTENSION');
         if ($exts) {
             if (!is_array($exts)) {
                 $exts = array($exts);
             }
             //if
             foreach ($exts as $e) {
                 try {
                     return parent::findTemplate($name . $e);
                 } catch (\Twig_Error_Loader $e) {
                 }
             }
             //foreach
         }
         //if
     }
     //catch
     throw new \Twig_Error_Loader("Twig Error Loader Exception : Could name find template `{$name}`");
 }
開發者ID:discophp,項目名稱:framework,代碼行數:33,代碼來源:TemplateLoader.class.php

示例13: findTemplate

 /**
  * {@inheritdoc}
  */
 protected function findTemplate($name)
 {
     return $this->loader->findTemplate($name);
 }
開發者ID:Alltricks,項目名稱:multisite-bundle,代碼行數:7,代碼來源:MultisiteLoader.php

示例14: findTemplate

 /**
  * Returns the path to the template file.
  *
  * The file locator is used to locate the template when the naming convention
  * is the symfony one (i.e. the name can be parsed).
  * Otherwise the template is located using the locator from the twig library.
  *
  * @param string|TemplateReferenceInterface $template The template
  *
  * @return string The path to the template file
  *
  * @throws \Twig_Error_Loader if the template could not be found
  */
 protected function findTemplate($template)
 {
     $logicalName = (string) $template;
     if (isset($this->cache[$logicalName])) {
         return $this->cache[$logicalName];
     }
     $file = null;
     $previous = null;
     try {
         $file = parent::findTemplate($logicalName);
     } catch (\Twig_Error_Loader $e) {
         throw new \Twig_Error_Loader(sprintf('Unable to find frame "%s".', $logicalName), -1, null, $previous);
     }
     return $this->cache[$logicalName] = $file;
 }
開發者ID:conjecto,項目名稱:nemrod,代碼行數:28,代碼來源:JsonLdFrameLoader.php


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