/**
  * 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;
 }
 /**
  * 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];
 }
 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);
 }
Beispiel #4
0
 /**
  * {@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);
     }
 }
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testThrowsAnExceptionWhenTemplateIsNotATemplateReferenceInterface()
 {
     $locator = new TemplateLocator($this->getFileLocator());
     $locator->locate('template');
 }
Beispiel #6
0
 /**
  * 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);
 }
 /**
  * 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);
 }