コード例 #1
0
 /**
  * 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 the template is not an instance of TemplateReferenceInterface
  * @throws \InvalidArgumentException When file is not found
  */
 public function locate($template, $currentPath = null, $first = true)
 {
     if (!$template instanceof TemplateReferenceInterface) {
         throw new \InvalidArgumentException("The template must be an instance of TemplateReferenceInterface.");
     }
     $path = $this->getCachedTemplatePath($template);
     return $path === null ? parent::locate($template) : $path;
 }
コード例 #2
0
 /**
  * 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];
 }
コード例 #3
0
 public function locate($template, $currentPath = null, $first = true)
 {
     if ($template instanceof MagentoTemplateReference) {
         $logicalName = (string) $template;
         if (isset($this->cache[$logicalName])) {
             return $this->cache[$logicalName];
         }
         $mageDesignDir = \Mage::getBaseDir('design');
         $file = $mageDesignDir . DIRECTORY_SEPARATOR . $logicalName;
         if (!file_exists($file)) {
             throw new \Twig_Error_Loader(sprintf('Unable to find magento template "%s".', $logicalName), -1, null, $e);
         }
         return $this->cache[$logicalName] = $file;
     }
     return parent::locate($template, $currentPath, $first);
 }
コード例 #4
0
ファイル: TemplateLocator.php プロジェクト: ngydat/CoreBundle
 /**
  * {@inheritDoc}
  */
 public function locate($template, $currentPath = null, $first = true)
 {
     if (!$template instanceof TemplateReferenceInterface) {
         throw new \InvalidArgumentException('The template must be an instance of TemplateReferenceInterface.');
     }
     $theme = $this->themeManager->getCurrentTheme();
     if (!$theme) {
         // no custom localization if no theme (e.g. in test environment)
         return parent::locate($template, $currentPath, $first);
     }
     $bundle = $this->getBundle($theme);
     $template = $this->locateTemplate($template, $bundle, $theme, $currentPath);
     $key = $this->getCacheKey($template);
     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);
     }
 }
コード例 #5
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testThrowsAnExceptionWhenTemplateIsNotATemplateReferenceInterface()
 {
     $locator = new TemplateLocator($this->getFileLocator());
     $locator->locate('template');
 }
コード例 #6
0
ファイル: TemplateLocator.php プロジェクト: geoffreytran/zym
 /**
  * Constructor.
  *
  * @param FileLocatorInterface $locator  A FileLocatorInterface instance
  * @param string               $cacheDir The cache path
  * @param ActiveTheme          $theme    The theme instance
  */
 public function __construct(FileLocatorInterface $locator, $cacheDir = null, ThemeManager $themeManager = null)
 {
     $this->themeManager = $themeManager;
     parent::__construct($locator, $cacheDir);
 }
コード例 #7
0
 /**
  * Constructor.
  *
  * @param FileLocatorInterface $locator     A FileLocatorInterface instance
  * @param string               $cacheDir    The cache path
  * @param ActiveTheme          $activeTheme
  */
 public function __construct(FileLocatorInterface $locator, $cacheDir = null, ActiveTheme $activeTheme = null)
 {
     $this->activeTheme = $activeTheme;
     parent::__construct($locator, $cacheDir);
 }