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


PHP Templating\TemplateReferenceInterface類代碼示例

本文整理匯總了PHP中Symfony\Component\Templating\TemplateReferenceInterface的典型用法代碼示例。如果您正苦於以下問題:PHP TemplateReferenceInterface類的具體用法?PHP TemplateReferenceInterface怎麽用?PHP TemplateReferenceInterface使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: load

 public function load(TemplateReferenceInterface $template)
 {
     if (method_exists($this, $method = 'get' . ucfirst($template->get('name')) . 'Template')) {
         return new StringStorage($this->{$method}());
     }
     return false;
 }
開發者ID:symfony,項目名稱:symfony,代碼行數:7,代碼來源:CacheLoaderTest.php

示例2: load

 /**
  * Loads a template.
  *
  * @param TemplateReferenceInterface $template A template
  *
  * @return Storage|bool false if the template cannot be loaded, a Storage instance otherwise
  */
 public function load(TemplateReferenceInterface $template)
 {
     $key = hash('sha256', $template->getLogicalName());
     $dir = $this->dir . DIRECTORY_SEPARATOR . substr($key, 0, 2);
     $file = substr($key, 2) . '.tpl';
     $path = $dir . DIRECTORY_SEPARATOR . $file;
     if (is_file($path)) {
         if (null !== $this->logger) {
             $this->logger->debug('Fetching template from cache.', array('name' => $template->get('name')));
         } elseif (null !== $this->debugger) {
             // just for BC, to be removed in 3.0
             $this->debugger->log(sprintf('Fetching template "%s" from cache.', $template->get('name')));
         }
         return new FileStorage($path);
     }
     if (false === ($storage = $this->loader->load($template))) {
         return false;
     }
     $content = $storage->getContent();
     if (!is_dir($dir)) {
         mkdir($dir, 0777, true);
     }
     file_put_contents($path, $content);
     if (null !== $this->logger) {
         $this->logger->debug('Storing template in cache.', array('name' => $template->get('name')));
     } elseif (null !== $this->debugger) {
         // just for BC, to be removed in 3.0
         $this->debugger->log(sprintf('Storing template "%s" in cache.', $template->get('name')));
     }
     return new FileStorage($path);
 }
開發者ID:RuntyCybin,項目名稱:csymfony,代碼行數:38,代碼來源:CacheLoader.php

示例3: load

 /**
  * Loads a template.
  *
  * @param TemplateReferenceInterface $template A template
  *
  * @return Storage|Boolean false if the template cannot be loaded, a Storage instance otherwise
  */
 public function load(TemplateReferenceInterface $template)
 {
     $key = md5($template->getLogicalName());
     $dir = $this->dir . DIRECTORY_SEPARATOR . substr($key, 0, 2);
     $file = substr($key, 2) . '.tpl';
     $path = $dir . DIRECTORY_SEPARATOR . $file;
     if (file_exists($path)) {
         if (null !== $this->debugger) {
             $this->debugger->log(sprintf('Fetching template "%s" from cache', $template->get('name')));
         }
         return new FileStorage($path);
     }
     if (false === ($storage = $this->loader->load($template))) {
         return false;
     }
     $content = $storage->getContent();
     if (!file_exists($dir)) {
         mkdir($dir, 0777, true);
     }
     file_put_contents($path, $content);
     if (null !== $this->debugger) {
         $this->debugger->log(sprintf('Storing template "%s" in cache', $template->get('name')));
     }
     return new FileStorage($path);
 }
開發者ID:artz20,項目名稱:Tv-shows-zone,代碼行數:32,代碼來源:CacheLoader.php

示例4: load

 /**
  * Loads a template.
  *
  * @param TemplateReferenceInterface $template A template
  *
  * @return Storage|bool false if the template cannot be loaded, a Storage instance otherwise
  */
 public function load(TemplateReferenceInterface $template)
 {
     $key = md5($template->getLogicalName());
     $dir = $this->dir . DIRECTORY_SEPARATOR . substr($key, 0, 2);
     $file = substr($key, 2) . '.tpl';
     $path = $dir . DIRECTORY_SEPARATOR . $file;
     if (is_file($path)) {
         if (null !== $this->debugger) {
             $this->debugger->log(sprintf('Fetching template "%s" from cache', $template->get('name')));
         }
         return new FileStorage($path);
     }
     if (false === ($storage = $this->loader->load($template))) {
         return false;
     }
     $content = $storage->getContent();
     if (!is_dir($dir) && !@mkdir($dir, 0777, true) && !is_dir($dir)) {
         throw new \RuntimeException(sprintf('Cache Loader was not able to create directory "%s"', $dir));
     }
     file_put_contents($path, $content);
     if (null !== $this->debugger) {
         $this->debugger->log(sprintf('Storing template "%s" in cache', $template->get('name')));
     }
     return new FileStorage($path);
 }
開發者ID:mkemiche,項目名稱:Annuaire,代碼行數:32,代碼來源:CacheLoader.php

示例5: load

 /**
  * Loads a template.
  *
  * @param TemplateReferenceInterface $template A template
  *
  * @return Storage|Boolean false if the template cannot be loaded, a Storage instance otherwise
  *
  * @api
  */
 public function load(TemplateReferenceInterface $template)
 {
     $file = $template->get('name');
     if (self::isAbsolutePath($file) && file_exists($file)) {
         return new FileStorage($file);
     }
     $replacements = array();
     foreach ($template->all() as $key => $value) {
         $replacements['%' . $key . '%'] = $value;
     }
     $logs = array();
     foreach ($this->templatePathPatterns as $templatePathPattern) {
         if (is_file($file = strtr($templatePathPattern, $replacements)) && is_readable($file)) {
             if (null !== $this->debugger) {
                 $this->debugger->log(sprintf('Loaded template file "%s"', $file));
             }
             return new FileStorage($file);
         }
         if (null !== $this->debugger) {
             $logs[] = sprintf('Failed loading template file "%s"', $file);
         }
     }
     if (null !== $this->debugger) {
         foreach ($logs as $log) {
             $this->debugger->log($log);
         }
     }
     return false;
 }
開發者ID:laiello,項目名稱:mediathequescrum,代碼行數:38,代碼來源:FilesystemLoader.php

示例6: load

 /**
  * Loads a template.
  *
  * @param TemplateReferenceInterface $template A template
  *
  * @return Storage|bool false if the template cannot be loaded, a Storage instance otherwise
  */
 public function load(TemplateReferenceInterface $template)
 {
     $file = $template->get('name');
     if (self::isAbsolutePath($file) && is_file($file)) {
         return new FileStorage($file);
     }
     $replacements = array();
     foreach ($template->all() as $key => $value) {
         $replacements['%' . $key . '%'] = $value;
     }
     $fileFailures = array();
     foreach ($this->templatePathPatterns as $templatePathPattern) {
         if (is_file($file = strtr($templatePathPattern, $replacements)) && is_readable($file)) {
             if (null !== $this->logger) {
                 $this->logger->debug('Loaded template file.', array('file' => $file));
             }
             return new FileStorage($file);
         }
         if (null !== $this->logger) {
             $fileFailures[] = $file;
         }
     }
     // only log failures if no template could be loaded at all
     foreach ($fileFailures as $file) {
         if (null !== $this->logger) {
             $this->logger->debug('Failed loading template file.', array('file' => $file));
         }
     }
     return false;
 }
開發者ID:Ener-Getick,項目名稱:symfony,代碼行數:37,代碼來源:FilesystemLoader.php

示例7: locate

 /**
  * Returns a full path for a given file.
  *
  * @param TemplateReferenceInterface $template    The template
  * @param string                     $currentPath Unused
  * @param Boolean                    $first       Unused
  *
  * @return string The full path for the file
  *
  * @throws \InvalidArgumentException When file is not found
  */
 public function locate($template, $currentPath = null, $first = true)
 {
     $key = $template->getSignature();
     if (!isset($this->templates[$key])) {
         throw new \InvalidArgumentException(sprintf('Unable to find template "%s".', json_encode($template)));
     }
     return $this->templates[$key];
 }
開發者ID:noelg,項目名稱:symfony-demo,代碼行數:19,代碼來源:CachedTemplateLocator.php

示例8: getCacheKey

 /**
  * Returns a full path for a given file.
  *
  * @param TemplateReferenceInterface $template A template
  *
  * @return string The full path for the file
  */
 protected function getCacheKey($template)
 {
     $name = $template->getLogicalName();
     if ($this->activeTheme) {
         $name .= '|' . $this->activeTheme->getName();
     }
     return $name;
 }
開發者ID:xabbuh,項目名稱:LiipThemeBundle,代碼行數:15,代碼來源:TemplateLocator.php

示例9: locate

 /**
  * Returns a full path for a given file.
  *
  * @param TemplateReferenceInterface $template    The template
  * @param string                     $currentPath Unused
  * @param Boolean                    $first       Unused
  *
  * @return string The full path for the file
  *
  * @throws \InvalidArgumentException When file is not found
  */
 public function locate($template, $currentPath = null, $first = true)
 {
     $key = $template->getSignature();
     if (!isset($this->templates[$key])) {
         return parent::locate($template, $currentPath, $first);
     }
     return $this->templates[$key];
 }
開發者ID:rooster,項目名稱:symfony,代碼行數:19,代碼來源:CachedTemplateLocator.php

示例10: load

 /**
  * Loads a template.
  *
  * @param TemplateReferenceInterface $template A template
  *
  * @return Storage|bool false if the template cannot be loaded, a Storage instance otherwise
  *
  * @api
  */
 public function load(TemplateReferenceInterface $template)
 {
     $method = $template->get('name');
     if (!method_exists($this->templates, $method)) {
         return false;
     }
     return new ClassStorage([$this->templates, $method]);
 }
開發者ID:brennantom,項目名稱:hackazon,代碼行數:17,代碼來源:ClassTemplateLoader.php

示例11:

 function it_throws_resource_not_found_exception_if_the_location_found_in_cache_is_null(TemplateLocatorInterface $decoratedTemplateLocator, Cache $cache, TemplateReferenceInterface $template, ThemeInterface $theme)
 {
     $template->getLogicalName()->willReturn('Logical:Name');
     $template->getPath()->willReturn('@Acme/template.html.twig');
     $theme->getName()->willReturn('theme/name');
     $cache->contains('Logical:Name|theme/name')->willReturn(true);
     $cache->fetch('Logical:Name|theme/name')->willReturn(null);
     $decoratedTemplateLocator->locateTemplate(Argument::cetera())->shouldNotBeCalled();
     $this->shouldThrow(ResourceNotFoundException::class)->during('locateTemplate', [$template, $theme]);
 }
開發者ID:TheMadeleine,項目名稱:Sylius,代碼行數:10,代碼來源:CachedTemplateLocatorSpec.php

示例12: load

 public function load(TemplateReferenceInterface $template)
 {
     $file = $template->get('name');
     foreach ($this->paths as $path) {
         $template->set('name', $path . '/' . $file);
         $result = parent::load($template);
         if ($result) {
             return $result;
         }
     }
     return false;
 }
開發者ID:miguelibero,項目名稱:meinhof,代碼行數:12,代碼來源:FilesystemLoader.php

示例13: locate

 /**
  * Returns a full path for a given file.
  *
  * @param TemplateReferenceInterface    $template     A template
  * @param string                        $currentPath  Unused
  * @param Boolean                       $first        Unused
  *
  * @return string The full path for the file
  *
  * @throws \InvalidArgumentException When file is not found
  */
 public function locate($template, $currentPath = null, $first = true)
 {
     $key = $template->getSignature();
     if (isset($this->cache[$key])) {
         return $this->cache[$key];
     }
     try {
         return $this->cache[$key] = $this->locator->locate($template->getPath(), $this->path);
     } catch (\InvalidArgumentException $e) {
         throw new \InvalidArgumentException(sprintf('Unable to find template "%s" in "%s".', $template, $this->path), 0, $e);
     }
 }
開發者ID:richardmiller,項目名稱:Linktuesday.com,代碼行數:23,代碼來源:TemplateLocator.php

示例14:

 function it_builds_cache_by_warming_up_every_template_and_every_theme_together(TemplateFinderInterface $templateFinder, TemplateLocatorInterface $templateLocator, ThemeRepositoryInterface $themeRepository, Cache $cache, ThemeInterface $theme, TemplateReferenceInterface $firstTemplate, TemplateReferenceInterface $secondTemplate)
 {
     $templateFinder->findAllTemplates()->willReturn([$firstTemplate, $secondTemplate]);
     $themeRepository->findAll()->willReturn([$theme]);
     $theme->getName()->willReturn('theme/name');
     $firstTemplate->getLogicalName()->willReturn('Logical:Name:First');
     $secondTemplate->getLogicalName()->willReturn('Logical:Name:Second');
     $templateLocator->locateTemplate($firstTemplate, $theme)->willReturn('/First/Theme/index.html.twig');
     $templateLocator->locateTemplate($secondTemplate, $theme)->willThrow(ResourceNotFoundException::class);
     $cache->save('Logical:Name:First|theme/name', '/First/Theme/index.html.twig')->shouldBeCalled();
     $cache->save('Logical:Name:Second|theme/name', null)->shouldBeCalled();
     $this->warmUp(null);
 }
開發者ID:Sylius,項目名稱:SyliusThemeBundle,代碼行數:13,代碼來源:TemplatePathsCacheWarmerSpec.php

示例15: locate

 /**
  * Returns a full path for a given file.
  *
  * @param TemplateReferenceInterface $template    A template
  * @param string                     $currentPath Unused
  * @param Boolean                    $first       Unused
  *
  * @return string The full path for the file
  *
  * @throws \InvalidArgumentException When the template is not an instance of TemplateReferenceInterface
  * @throws \InvalidArgumentException When the template file can not be found
  */
 public function locate($template, $currentPath = null, $first = true)
 {
     if (!$template instanceof TemplateReferenceInterface) {
         throw new \InvalidArgumentException("The template must be an instance of TemplateReferenceInterface.");
     }
     $key = $template->getLogicalName();
     if (isset($this->cache[$key])) {
         return $this->cache[$key];
     }
     try {
         return $this->cache[$key] = $this->locator->locate($template->getPath(), $currentPath);
     } catch (\InvalidArgumentException $e) {
         throw new \InvalidArgumentException(sprintf('Unable to find template "%s" : "%s".', $template, $e->getMessage()), 0, $e);
     }
 }
開發者ID:artz20,項目名稱:Tv-shows-zone,代碼行數:27,代碼來源:TemplateLocator.php


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