ServiceReferenceGraphNode.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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\Definition;
  12. use Symfony\Component\DependencyInjection\Alias;
  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. * Constructor.
  28. *
  29. * @param string $id The node identifier
  30. * @param mixed $value The node value
  31. */
  32. public function __construct($id, $value)
  33. {
  34. $this->id = $id;
  35. $this->value = $value;
  36. $this->inEdges = array();
  37. $this->outEdges = array();
  38. }
  39. /**
  40. * Adds an in edge to this node.
  41. *
  42. * @param ServiceReferenceGraphEdge $edge
  43. */
  44. public function addInEdge(ServiceReferenceGraphEdge $edge)
  45. {
  46. $this->inEdges[] = $edge;
  47. }
  48. /**
  49. * Adds an out edge to this node.
  50. *
  51. * @param ServiceReferenceGraphEdge $edge
  52. */
  53. public function addOutEdge(ServiceReferenceGraphEdge $edge)
  54. {
  55. $this->outEdges[] = $edge;
  56. }
  57. /**
  58. * Checks if the value of this node is an Alias.
  59. *
  60. * @return Boolean True if the value is an Alias instance
  61. */
  62. public function isAlias()
  63. {
  64. return $this->value instanceof Alias;
  65. }
  66. /**
  67. * Checks if the value of this node is a Definition.
  68. *
  69. * @return Boolean True if the value is a Definition instance
  70. */
  71. public function isDefinition()
  72. {
  73. return $this->value instanceof Definition;
  74. }
  75. /**
  76. * Returns the identifier.
  77. *
  78. * @return string
  79. */
  80. public function getId()
  81. {
  82. return $this->id;
  83. }
  84. /**
  85. * Returns the in edges.
  86. *
  87. * @return array The in ServiceReferenceGraphEdge array
  88. */
  89. public function getInEdges()
  90. {
  91. return $this->inEdges;
  92. }
  93. /**
  94. * Returns the out edges.
  95. *
  96. * @return array The out ServiceReferenceGraphEdge array
  97. */
  98. public function getOutEdges()
  99. {
  100. return $this->outEdges;
  101. }
  102. /**
  103. * Returns the value of this Node
  104. *
  105. * @return mixed The value
  106. */
  107. public function getValue()
  108. {
  109. return $this->value;
  110. }
  111. }