TemplateReference.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\FrameworkBundle\Templating;
  11. use Symfony\Component\Templating\TemplateReference as BaseTemplateReference;
  12. /**
  13. * Internal representation of a template.
  14. *
  15. * @author Victor Berchet <victor@suumit.com>
  16. */
  17. class TemplateReference extends BaseTemplateReference
  18. {
  19. public function __construct($bundle = null, $controller = null, $name = null, $format = null, $engine = null)
  20. {
  21. $this->parameters = array(
  22. 'bundle' => $bundle,
  23. 'controller' => $controller,
  24. 'name' => $name,
  25. 'format' => $format,
  26. 'engine' => $engine,
  27. );
  28. }
  29. /**
  30. * Returns the path to the template
  31. * - as a path when the template is not part of a bundle
  32. * - as a resource when the template is part of a bundle.
  33. *
  34. * @return string A path to the template or a resource
  35. */
  36. public function getPath()
  37. {
  38. $controller = str_replace('\\', '/', $this->get('controller'));
  39. $path = (empty($controller) ? '' : $controller.'/').$this->get('name').'.'.$this->get('format').'.'.$this->get('engine');
  40. return empty($this->parameters['bundle']) ? 'views/'.$path : '@'.$this->get('bundle').'/Resources/views/'.$path;
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function getLogicalName()
  46. {
  47. return sprintf('%s:%s:%s.%s.%s', $this->parameters['bundle'], $this->parameters['controller'], $this->parameters['name'], $this->parameters['format'], $this->parameters['engine']);
  48. }
  49. }