TemplateReference.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.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. public function __toString()
  27. {
  28. return json_encode($this->parameters);
  29. }
  30. /**
  31. * {@inheritDoc}
  32. */
  33. public function getSignature()
  34. {
  35. return md5(serialize($this->parameters));
  36. }
  37. /**
  38. * {@inheritDoc}
  39. */
  40. public function set($name, $value)
  41. {
  42. if (array_key_exists($name, $this->parameters)) {
  43. $this->parameters[$name] = $value;
  44. } else {
  45. throw new \InvalidArgumentException(sprintf('The template does not support the "%s" parameter.', $name));
  46. }
  47. return $this;
  48. }
  49. /**
  50. * {@inheritDoc}
  51. */
  52. public function get($name)
  53. {
  54. if (array_key_exists($name, $this->parameters)) {
  55. return $this->parameters[$name];
  56. } else {
  57. throw new \InvalidArgumentException(sprintf('The template does not support the "%s" parameter.', $name));
  58. }
  59. }
  60. /**
  61. * {@inheritDoc}
  62. */
  63. public function all()
  64. {
  65. return $this->parameters;
  66. }
  67. /**
  68. * {@inheritDoc}
  69. */
  70. public function getPath()
  71. {
  72. return $this->parameters['name'];
  73. }
  74. }