public function dump() { $finder = new Finder(); $twigNamespaces = $this->loader->getNamespaces(); foreach ($twigNamespaces as $ns) { if (count($this->loader->getPaths($ns)) > 0) { $iterator = $finder->files()->in($this->loader->getPaths($ns)); foreach ($iterator as $file) { /** @var SplFileInfo $file */ $resource = new TwigResource($this->loader, '@' . $ns . '/' . $file->getRelativePathname()); $this->lam->addResource($resource, 'twig'); } } } foreach ($this->lam->getNames() as $name) { $asset = $this->lam->get($name); $formula = $this->lam->getFormula($name); $debug = isset($formula[2]['debug']) ? $formula[2]['debug'] : $this->lam->isDebug(); $combine = isset($formula[2]['combine']) ? $formula[2]['combine'] : null; if (null !== $combine ? !$combine : $debug) { foreach ($asset as $leaf) { $this->aw->writeAsset($leaf); } } else { $this->aw->writeAsset($asset); } } }
public function testPaths() { $basePath = dirname(__FILE__) . '/Fixtures'; $loader = new Twig_Loader_Filesystem(array($basePath . '/normal', $basePath . '/normal_bis')); $loader->setPaths(array($basePath . '/named', $basePath . '/named_bis'), 'named'); $loader->addPath($basePath . '/named_ter', 'named'); $loader->addPath($basePath . '/normal_ter'); $loader->prependPath($basePath . '/normal_final'); $loader->prependPath($basePath . '/named_final', 'named'); $this->assertEquals(array($basePath . '/normal_final', $basePath . '/normal', $basePath . '/normal_bis', $basePath . '/normal_ter'), $loader->getPaths()); $this->assertEquals(array($basePath . '/named_final', $basePath . '/named', $basePath . '/named_bis', $basePath . '/named_ter'), $loader->getPaths('named')); $this->assertEquals("path (final)\n", $loader->getSource('index.html')); $this->assertEquals("path (final)\n", $loader->getSource('@__main__/index.html')); $this->assertEquals("named path (final)\n", $loader->getSource('@named/index.html')); }
/** * Get the template directories * * @return TemplatePath[] */ public function getPaths() { $paths = []; foreach ($this->twigLoader->getNamespaces() as $namespace) { $name = $namespace !== TwigFilesystem::MAIN_NAMESPACE ? $namespace : null; foreach ($this->twigLoader->getPaths($namespace) as $path) { $paths[] = new TemplatePath($path, $name); } } return $paths; }
/** * Get a fully qualified path to a given template. * @param string $file Filename of the template to find in referenced templates directories. * @param string $namespace Namespace of a specific set of templates directories. * @return string The full pathname to the template or 'false' if not found. */ public function getTemplatePathname($file, $namespace = false) { $pathname = false; if ($this->_loader->exists($file)) { $paths = StringUtils::emptyOrSpaces($namespace) ? $this->_loader->getPaths() : $this->_loader->getPaths(trim($namespace)); foreach ($paths as $path) { $tmp_pathname = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim($file, DIRECTORY_SEPARATOR); if (file_exists($tmp_pathname)) { $pathname = $tmp_pathname; break; } } } return $pathname; }
/** * Determine the path of a template based on its name * * @param \Twig_Loader_Filesystem $filesystem * @param string $name * * @return string * * @throws Twig_Error_Loader */ public static function findTemplate(\Twig_Loader_Filesystem $filesystem, $name) { $name = self::normalizeName($name); self::validateName($name); list($namespace, $shortname) = self::parseName($name); $paths = $filesystem->getPaths($namespace); if (empty($paths)) { throw new Twig_Error_Loader(sprintf('There are no registered paths for namespace "%s".', $namespace)); } foreach ($paths as $path) { if (is_file($path . '/' . $shortname)) { if (false !== ($realpath = realpath($path . '/' . $shortname))) { return $realpath; } return $path . '/' . $shortname; } } throw new Twig_Error_Loader(sprintf('Unable to find template "%s" (looked into: %s).', $name, implode(', ', $paths))); }
public function testEmptyConstructor() { $loader = new Twig_Loader_Filesystem(); $this->assertEquals(array(), $loader->getPaths()); }
/** * @return string */ public function getScriptPath() { return $this->loader->getPaths(); }
/** * @return string */ public function getScriptPath() { $paths = $this->loader->getPaths(); return reset($paths); }
/** * Gets the paths of the rendering environment. * * @return mixed */ public function getPaths() { return $this->twigFileLoader->getPaths(); }
/** * @return string */ public function getScriptPath() { $this->script_path = $this->loader->getPaths(); return reset($this->script_path); }