本文整理汇总了PHP中Twig_Loader_Filesystem::findTemplate方法的典型用法代码示例。如果您正苦于以下问题:PHP Twig_Loader_Filesystem::findTemplate方法的具体用法?PHP Twig_Loader_Filesystem::findTemplate怎么用?PHP Twig_Loader_Filesystem::findTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twig_Loader_Filesystem
的用法示例。
在下文中一共展示了Twig_Loader_Filesystem::findTemplate方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findTemplate
/**
* Returns the path to the template file.
*
* The file locator is used to locate the template when the naming convention
* is the symfony one (i.e. the name can be parsed).
* Otherwise the template is located using the locator from the twig library.
*
* @param string|TemplateReferenceInterface $template The template
* @param bool $throw When true, a \Twig_Error_Loader exception will be thrown if a template could not be found
*
* @return string The path to the template file
*
* @throws \Twig_Error_Loader if the template could not be found
*/
protected function findTemplate($template, $throw = true)
{
$logicalName = (string) $template;
if (isset($this->cache[$logicalName])) {
return $this->cache[$logicalName];
}
$file = null;
$previous = null;
try {
$file = parent::findTemplate($logicalName);
} catch (\Twig_Error_Loader $e) {
$twigLoaderException = $e;
// for BC
try {
$template = $this->parser->parse($template);
$file = $this->locator->locate($template);
} catch (\Exception $e) {
}
}
if (false === $file || null === $file) {
if ($throw) {
throw $twigLoaderException;
}
return false;
}
return $this->cache[$logicalName] = $file;
}
示例2: findTemplate
/**
* Returns the path to the template file.
*
* The file locator is used to locate the template when the naming convention
* is the symfony one (i.e. the name can be parsed).
* Otherwise the template is located using the locator from the twig library.
*
* @param string|TemplateReferenceInterface $template The template
*
* @throws \Twig_Error_Loader if the template could not be found
*
* @return string The path to the template file
*/
protected function findTemplate($template)
{
$logicalName = (string) $template;
if (isset($this->cache[$logicalName])) {
return $this->cache[$logicalName];
}
$file = null;
$previous = null;
try {
$template = $this->parser->parse($template);
try {
$file = $this->locator->locate($template);
} catch (\InvalidArgumentException $e) {
$previous = $e;
}
} catch (\Exception $e) {
try {
$file = parent::findTemplate($template);
} catch (\Twig_Error_Loader $e) {
$previous = $e;
}
}
if (false === $file || null === $file) {
throw new \Twig_Error_Loader(sprintf('Unable to find template "%s".', $logicalName), -1, null, $previous);
}
return $this->cache[$logicalName] = $file;
}
示例3: findTemplate
protected function findTemplate($name)
{
// strip away bundle name
$parts = explode(':', $name);
return parent::findTemplate(end($parts));
}
示例4: findTemplate
public function findTemplate($name)
{
try {
return parent::findTemplate($name . $this->extension);
} catch (\Exception $e) {
return parent::findTemplate($name);
}
}
示例5: findTemplate
/**
* @param $name
* @return mixed
*/
protected function findTemplate($name)
{
if (isset($this->cache[$name])) {
return $this->cache[$name];
}
if (is_file($name)) {
$this->cache[$name] = $name;
return $name;
}
return parent::findTemplate($name);
}
示例6: findTemplate
protected function findTemplate($name)
{
if (null !== $this->locator) {
if (isset($this->cache[$name])) {
return $this->cache[$name];
}
if ($path = call_user_func($this->locator, $name)) {
return $this->cache[$name] = $path;
}
}
return parent::findTemplate($name);
}
示例7: findTemplate
/**
* Do same stuff than Twig_Loader_Filesystem::exists() plus returns the file
* itself if it is readable.
*
* @see Twig_Loader_Filesystem::findTemplate()
*/
protected function findTemplate($name)
{
try {
return parent::findTemplate($name);
} catch (\Twig_Error_Loader $e) {
$namespace = self::MAIN_NAMESPACE;
if (is_readable($name)) {
return $name;
}
throw new \Twig_Error_Loader(sprintf('Unable to find template "%s" (looked into: %s).', $name, implode(', ', $this->paths[$namespace])));
}
}
示例8: findTemplate
/**
* @param array|string $names
* @throws \Twig_Error_Loader
* @return string
*/
protected function findTemplate($names)
{
if (!is_array($names)) {
return parent::findTemplate($names);
}
foreach ($names as $name) {
try {
return parent::findTemplate($name);
} catch (\Twig_Error_Loader $e) {
}
}
throw new \Twig_Error_Loader(sprintf('Unable to find template "%s".', implode(', ', $names)));
}
示例9: findTemplate
/**
* {@inheritdoc}
*/
protected function findTemplate($name)
{
$real_name = realpath($name);
// Make the filename relative to the template directory
foreach ($this->getPaths() as $path) {
$real_path = realpath($path);
if (strpos($real_name, $real_path) === 0) {
$name = ltrim(str_replace($real_path, '', $real_name), '/');
break;
}
}
// Ensure that the file extension is always present
if (!preg_match("/\\.{$this->extension}\$/", $name)) {
$name .= ".{$this->extension}";
}
return parent::findTemplate($name);
}
示例10: findTemplate
/**
* Find the template
*
* Override for Twig_Loader_Filesystem::findTemplate to add support
* for loading from safe directories.
*/
protected function findTemplate($name)
{
$name = (string) $name;
// normalize name
$name = preg_replace('#/{2,}#', '/', strtr($name, '\\', '/'));
// If this is in the cache we can skip the entire process below
// as it should have already been validated
if (isset($this->cache[$name])) {
return $this->cache[$name];
}
// First, find the template name. The override above of validateName
// causes the validateName process to be skipped for this call
$file = parent::findTemplate($name);
try {
// Try validating the name (which may throw an exception)
parent::validateName($name);
} catch (\Twig_Error_Loader $e) {
if (strpos($e->getRawMessage(), 'Looks like you try to load a template outside configured directories') === 0) {
// Ok, so outside of the configured template directories, we
// can now check if we're within a "safe" directory
// Find the real path of the directory the file is in
$directory = src_realpath(dirname($file));
if ($directory === false) {
// Some sort of error finding the actual path, must throw the exception
throw $e;
}
foreach ($this->safe_directories as $safe_directory) {
if (strpos($directory, $safe_directory) === 0) {
// The directory being loaded is below a directory
// that is "safe". We're good to load it!
return $file;
}
}
}
// Not within any safe directories
throw $e;
}
// No exception from validateName, safe to load.
return $file;
}
示例11: findTemplate
/**
* Returns the path to the template file
*
* @param $name The template logical name
*
* @return string The path to the template file
*/
protected function findTemplate($name)
{
try {
$tpl = $this->parser->parse($name);
} catch (\Exception $e) {
return parent::findTemplate($name);
}
if (isset($this->cache[$key = $tpl->getLogicalName()])) {
return $this->cache[$key];
}
$file = null;
$previous = null;
try {
$file = $this->locator->locate($tpl);
} catch (\InvalidArgumentException $e) {
$previous = $e;
}
if (false === $file || null === $file) {
throw new \Twig_Error_Loader(sprintf('Unable to find template "%s".', $tpl), -1, null, $previous);
}
return $this->cache[$key] = $file;
}
示例12: getFinalName
/**
* Get the final name where a template lives, regardless of whether it was called with an extension or not.
*
*
* @param string $name The template name.
* @return string The final template name.
*
* @throws \Twig_Error_Loader
*/
public function getFinalName($name)
{
try {
return parent::findTemplate($name);
} catch (\Twig_Error_Loader $e) {
$exts = \App::config('TEMPLATE_EXTENSION');
if ($exts) {
if (!is_array($exts)) {
$exts = array($exts);
}
//if
foreach ($exts as $e) {
try {
return parent::findTemplate($name . $e);
} catch (\Twig_Error_Loader $e) {
}
}
//foreach
}
//if
}
//catch
throw new \Twig_Error_Loader("Twig Error Loader Exception : Could name find template `{$name}`");
}
示例13: findTemplate
/**
* {@inheritdoc}
*/
protected function findTemplate($name)
{
return $this->loader->findTemplate($name);
}
示例14: findTemplate
/**
* Returns the path to the template file.
*
* The file locator is used to locate the template when the naming convention
* is the symfony one (i.e. the name can be parsed).
* Otherwise the template is located using the locator from the twig library.
*
* @param string|TemplateReferenceInterface $template The template
*
* @return string The path to the template file
*
* @throws \Twig_Error_Loader if the template could not be found
*/
protected function findTemplate($template)
{
$logicalName = (string) $template;
if (isset($this->cache[$logicalName])) {
return $this->cache[$logicalName];
}
$file = null;
$previous = null;
try {
$file = parent::findTemplate($logicalName);
} catch (\Twig_Error_Loader $e) {
throw new \Twig_Error_Loader(sprintf('Unable to find frame "%s".', $logicalName), -1, null, $previous);
}
return $this->cache[$logicalName] = $file;
}