本文整理匯總了PHP中Symfony\Component\Templating\TemplateReferenceInterface::getPath方法的典型用法代碼示例。如果您正苦於以下問題:PHP TemplateReferenceInterface::getPath方法的具體用法?PHP TemplateReferenceInterface::getPath怎麽用?PHP TemplateReferenceInterface::getPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Templating\TemplateReferenceInterface
的用法示例。
在下文中一共展示了TemplateReferenceInterface::getPath方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1:
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]);
}
示例2: locate
/**
* 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);
}
}
示例3: locate
/**
* 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);
}
}
示例4: addTemplate
/**
* Adds twig templates to the tracker.
*
* @param TemplateReferenceInterface $reference
* @return Tracker
*/
private function addTemplate(TemplateReferenceInterface $reference)
{
if ($reference->get('engine') !== 'twig') {
return $this;
}
if (false !== ($path = $this->resolvePath($reference->getPath()))) {
$this->templates[] = $path;
return $this->addPath($path);
}
// Can't resolve the template. This shouldn't happen, unless somebody placed a template in a very weird place.
$this->untracked_templates[] = $reference->getPath();
return $this;
}
示例5: getTemplatePath
/**
* 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;
}
示例6: locateTemplate
/**
* {@inheritdoc}
*/
public function locateTemplate(TemplateReferenceInterface $template, ThemeInterface $theme)
{
return $this->resourceLocator->locateResource($template->getPath(), $theme);
}
示例7:
function it_does_not_catch_exceptions_thrown_while_locating_template_to_resource_locator_even(ResourceLocatorInterface $resourceLocator, TemplateReferenceInterface $template, ThemeInterface $theme)
{
$template->getPath()->willReturn('@AcmeBundle/Resources/views/index.html.twig');
$resourceLocator->locateResource('@AcmeBundle/Resources/views/index.html.twig', $theme)->willThrow(ResourceNotFoundException::class);
$this->shouldThrow(ResourceNotFoundException::class)->during('locateTemplate', [$template, $theme]);
}
示例8: addTemplate
/**
* Adds twig templates to the tracker.
*
* @param TemplateReferenceInterface $reference the reference to the twig template to be added.
* @return Tracker this instance
*/
private function addTemplate(TemplateReferenceInterface $reference)
{
if ($reference->get('engine') !== 'twig') {
return $this;
}
if (false !== ($path = $this->resolvePath($reference->getPath()))) {
$this->templates[] = $path;
return $this->addPath($path);
}
return $this;
}