ServiceReferenceGraphNode.php 2.5 KB

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