当前位置: 首页>>代码示例>>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;未经允许,请勿转载。