DefinitionDecorator.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace Symfony\Component\DependencyInjection;
  3. /**
  4. * This definition decorates another definition.
  5. *
  6. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  7. */
  8. class DefinitionDecorator extends Definition
  9. {
  10. protected $parent;
  11. protected $changes;
  12. /**
  13. * Constructor.
  14. *
  15. * @param Definition $parent The Definition instance to decorate.
  16. */
  17. public function __construct($parent)
  18. {
  19. parent::__construct();
  20. $this->parent = $parent;
  21. $this->changes = array();
  22. }
  23. /**
  24. * Returns the Definition being decorated.
  25. *
  26. * @return Definition
  27. */
  28. public function getParent()
  29. {
  30. return $this->parent;
  31. }
  32. /**
  33. * Returns all changes tracked for the Definition object.
  34. *
  35. * @return array An array of changes for this Definition
  36. */
  37. public function getChanges()
  38. {
  39. return $this->changes;
  40. }
  41. /**
  42. * {@inheritDoc}
  43. */
  44. public function setClass($class)
  45. {
  46. $this->changes['class'] = true;
  47. return parent::setClass($class);
  48. }
  49. /**
  50. * {@inheritDoc}
  51. */
  52. public function setFactoryClass($class)
  53. {
  54. $this->changes['factory_class'] = true;
  55. return parent::setFactoryClass($class);
  56. }
  57. /**
  58. * {@inheritDoc}
  59. */
  60. public function setFactoryMethod($method)
  61. {
  62. $this->changes['factory_method'] = true;
  63. return parent::setFactoryMethod($method);
  64. }
  65. /**
  66. * {@inheritDoc}
  67. */
  68. public function setFactoryService($service)
  69. {
  70. $this->changes['factory_service'] = true;
  71. return parent::setFactoryService($service);
  72. }
  73. /**
  74. * {@inheritDoc}
  75. */
  76. public function setConfigurator($callable)
  77. {
  78. $this->changes['configurator'] = true;
  79. return parent::setConfigurator($callable);
  80. }
  81. /**
  82. * {@inheritDoc}
  83. */
  84. public function setFile($file)
  85. {
  86. $this->changes['file'] = true;
  87. return parent::setFile($file);
  88. }
  89. /**
  90. * {@inheritDoc}
  91. */
  92. public function setPublic($boolean)
  93. {
  94. $this->changes['public'] = true;
  95. return parent::setPublic($boolean);
  96. }
  97. /**
  98. * You should always use this method when overwriting existing arguments
  99. * of the parent definition.
  100. *
  101. * If you directly call setArguments() keep in mind that you must follow
  102. * certain conventions when you want to overwrite the arguments of the
  103. * parent definition, otherwise your arguments will only be appended.
  104. *
  105. * @param integer $index
  106. * @param mixed $value
  107. *
  108. * @return DefinitionDecorator the current instance
  109. * @throws \InvalidArgumentException when $index isnt an integer
  110. */
  111. public function setArgument($index, $value)
  112. {
  113. if (!is_int($index)) {
  114. throw new \InvalidArgumentException('$index must be an integer.');
  115. }
  116. $this->arguments['index_'.$index] = $value;
  117. return $this;
  118. }
  119. }