php Symfony-Component-Templating-TemplateReferenceInterface类(方法)实例源码

下面列出了php Symfony-Component-Templating-TemplateReferenceInterface 类(方法)源码代码实例,从而了解它的用法。

作者:symfon    项目:symfon   
public function load(TemplateReferenceInterface $template)
 {
     if (method_exists($this, $method = 'get' . ucfirst($template->get('name')) . 'Template')) {
         return new StringStorage($this->{$method}());
     }
     return false;
 }

作者:RuntyCybi    项目:csymfon   
/**
  * 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);
 }

作者:artz2    项目:Tv-shows-zon   
/**
  * 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);
 }

作者:mkemich    项目:Annuair   
/**
  * 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);
 }

作者:laiell    项目:mediathequescru   
/**
  * 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;
 }

作者:Ener-Getic    项目:symfon   
/**
  * 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;
 }

作者:noel    项目:symfony-dem   
/**
  * 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];
 }

作者:xabbu    项目:LiipThemeBundl   
/**
  * 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;
 }

作者:rooste    项目:symfon   
/**
  * 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];
 }

作者:brennanto    项目:hackazo   
/**
  * 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]);
 }

作者:TheMadelein    项目:Syliu   
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]);
 }

作者:migueliber    项目:meinho   
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;
 }

作者:richardmille    项目:Linktuesday.co   
/**
  * 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);
     }
 }

作者:Syliu    项目:SyliusThemeBundl   
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);
 }

作者:artz2    项目:Tv-shows-zon   
/**
  * 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);
     }
 }

作者:ChMa    项目:CoreBundl   
/**
  * @param TemplateReferenceInterface                    $template
  * @param string                                        $bundle
  * @param \Claroline\CoreBundle\Entity\Theme\Theme|null $theme
  * @param string                                        $currentPath
  *
  * @return TemplateReferenceInterface
  */
 private function locateTemplate(TemplateReferenceInterface $template, $bundle, $theme, $currentPath)
 {
     $newTemplate = clone $template;
     $controller = $template->get('controller');
     if (null !== $theme) {
         $controller = sprintf('theme/%s/%s', $template->get('bundle'), $template->get('controller'));
     }
     $newTemplate->set('bundle', $bundle)->set('controller', $controller);
     try {
         $this->locator->locate($newTemplate->getPath(), $currentPath);
     } catch (\Exception $e) {
         $newTemplate = $template;
     }
     return $newTemplate;
 }

作者:geoffreytra    项目:zy   
/**
  * 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.");
     }
     $curTheme = $this->themeManager->getActiveTheme();
     if ($template instanceof ThemeTemplateReference && $template->get('theme')) {
         $this->themeManager->setActiveTheme($template->get('theme'));
     }
     $key = $this->getCacheKey($template);
     if (!isset($this->cache[$key])) {
         try {
             $this->cache[$key] = $this->locator->locate($template->getPath(), $currentPath);
         } catch (\InvalidArgumentException $e) {
             throw new \InvalidArgumentException(sprintf('Unable to find template "%s" in "%s".', $template, $e->getMessage()), 0, $e);
         }
     }
     $this->themeManager->setActiveTheme($curTheme);
     return $this->cache[$key];
 }

作者:Sywooc    项目:WellCommerc   
/**
  * Returns cache key for a given template
  *
  * @param TemplateReferenceInterface $template
  *
  * @return string
  */
 protected function getCacheKey($template)
 {
     $name = $template->getLogicalName();
     return $name;
 }

作者:robertowes    项目:CuteFlow-V   
public function load(TemplateReferenceInterface $template)
 {
     if (isset($this->templates[$template->getLogicalName()])) {
         return new StringStorage($this->templates[$template->getLogicalName()]);
     }
     return false;
 }

作者:chigi    项目:chiji-bundl   
/**
  * Get the realpath for the target TemplateReference object
  * @param TemplateReferenceInterface $template
  * @return string
  * @throws \InvalidArgumentException
  * @throws \RuntimeException
  */
 protected function getTemplatePath(TemplateReferenceInterface $template)
 {
     $name = $template->getPath();
     if ('@' !== substr($name, 0, 1)) {
         throw new \InvalidArgumentException(sprintf('A resource name must start with @ ("%s" given).', $name));
     }
     if (false !== strpos($name, '..')) {
         throw new \RuntimeException(sprintf('File name "%s" contains invalid characters (..).', $name));
     }
     $bundleName = substr($name, 1);
     $path = '';
     if (false !== strpos($bundleName, '/')) {
         list($bundleName, $path) = explode('/', $bundleName, 2);
     }
     return $this->getApplication()->getKernel()->getBundle($bundleName)->getPath() . '/' . $path;
 }


问题


面经


文章

微信
公众号

扫码关注公众号