TemplateReference.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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\Component\Templating;
  11. /**
  12. * Internal representation of a template.
  13. *
  14. * @author Victor Berchet <victor@suumit.com>
  15. */
  16. class TemplateReference implements TemplateReferenceInterface
  17. {
  18. protected $parameters;
  19. public function __construct($name = null, $engine = null)
  20. {
  21. $this->parameters = array(
  22. 'name' => $name,
  23. 'engine' => $engine,
  24. );
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function __toString()
  30. {
  31. return $this->getLogicalName();
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function set($name, $value)
  37. {
  38. if (array_key_exists($name, $this->parameters)) {
  39. $this->parameters[$name] = $value;
  40. } else {
  41. throw new \InvalidArgumentException(sprintf('The template does not support the "%s" parameter.', $name));
  42. }
  43. return $this;
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. public function get($name)
  49. {
  50. if (array_key_exists($name, $this->parameters)) {
  51. return $this->parameters[$name];
  52. }
  53. throw new \InvalidArgumentException(sprintf('The template does not support the "%s" parameter.', $name));
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function all()
  59. {
  60. return $this->parameters;
  61. }
  62. /**
  63. * {@inheritdoc}
  64. */
  65. public function getPath()
  66. {
  67. return $this->parameters['name'];
  68. }
  69. /**
  70. * {@inheritdoc}
  71. */
  72. public function getLogicalName()
  73. {
  74. return $this->parameters['name'];
  75. }
  76. }