ServiceReferenceGraphNode.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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\DependencyInjection\Compiler;
  11. use Symfony\Component\DependencyInjection\Alias;
  12. use Symfony\Component\DependencyInjection\Definition;
  13. /**
  14. * Represents a node in your service graph.
  15. *
  16. * Value is typically a definition, or an alias.
  17. *
  18. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  19. */
  20. class ServiceReferenceGraphNode
  21. {
  22. private $id;
  23. private $inEdges = [];
  24. private $outEdges = [];
  25. private $value;
  26. /**
  27. * @param string $id The node identifier
  28. * @param mixed $value The node value
  29. */
  30. public function __construct(string $id, $value)
  31. {
  32. $this->id = $id;
  33. $this->value = $value;
  34. }
  35. public function addInEdge(ServiceReferenceGraphEdge $edge)
  36. {
  37. $this->inEdges[] = $edge;
  38. }
  39. public function addOutEdge(ServiceReferenceGraphEdge $edge)
  40. {
  41. $this->outEdges[] = $edge;
  42. }
  43. /**
  44. * Checks if the value of this node is an Alias.
  45. *
  46. * @return bool True if the value is an Alias instance
  47. */
  48. public function isAlias()
  49. {
  50. return $this->value instanceof Alias;
  51. }
  52. /**
  53. * Checks if the value of this node is a Definition.
  54. *
  55. * @return bool True if the value is a Definition instance
  56. */
  57. public function isDefinition()
  58. {
  59. return $this->value instanceof Definition;
  60. }
  61. /**
  62. * Returns the identifier.
  63. *
  64. * @return string
  65. */
  66. public function getId()
  67. {
  68. return $this->id;
  69. }
  70. /**
  71. * Returns the in edges.
  72. *
  73. * @return ServiceReferenceGraphEdge[]
  74. */
  75. public function getInEdges()
  76. {
  77. return $this->inEdges;
  78. }
  79. /**
  80. * Returns the out edges.
  81. *
  82. * @return ServiceReferenceGraphEdge[]
  83. */
  84. public function getOutEdges()
  85. {
  86. return $this->outEdges;
  87. }
  88. /**
  89. * Returns the value of this Node.
  90. *
  91. * @return mixed The value
  92. */
  93. public function getValue()
  94. {
  95. return $this->value;
  96. }
  97. /**
  98. * Clears all edges.
  99. */
  100. public function clear()
  101. {
  102. $this->inEdges = $this->outEdges = [];
  103. }
  104. }