[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12 namespace Symfony\Component\DependencyInjection\Compiler; 13 14 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; 15 16 /** 17 * This is a directed graph of your services. 18 * 19 * This information can be used by your compiler passes instead of collecting 20 * it themselves which improves performance quite a lot. 21 * 22 * @author Johannes M. Schmitt <schmittjoh@gmail.com> 23 */ 24 class ServiceReferenceGraph 25 { 26 /** 27 * @var ServiceReferenceGraphNode[] 28 */ 29 private $nodes = array(); 30 31 /** 32 * Checks if the graph has a specific node. 33 * 34 * @param string $id Id to check 35 * 36 * @return bool 37 */ 38 public function hasNode($id) 39 { 40 return isset($this->nodes[$id]); 41 } 42 43 /** 44 * Gets a node by identifier. 45 * 46 * @param string $id The id to retrieve 47 * 48 * @return ServiceReferenceGraphNode 49 * 50 * @throws InvalidArgumentException if no node matches the supplied identifier 51 */ 52 public function getNode($id) 53 { 54 if (!isset($this->nodes[$id])) { 55 throw new InvalidArgumentException(sprintf('There is no node with id "%s".', $id)); 56 } 57 58 return $this->nodes[$id]; 59 } 60 61 /** 62 * Returns all nodes. 63 * 64 * @return ServiceReferenceGraphNode[] 65 */ 66 public function getNodes() 67 { 68 return $this->nodes; 69 } 70 71 /** 72 * Clears all nodes. 73 */ 74 public function clear() 75 { 76 $this->nodes = array(); 77 } 78 79 /** 80 * Connects 2 nodes together in the Graph. 81 * 82 * @param string $sourceId 83 * @param mixed $sourceValue 84 * @param string $destId 85 * @param mixed $destValue 86 * @param string $reference 87 */ 88 public function connect($sourceId, $sourceValue, $destId, $destValue = null, $reference = null) 89 { 90 if (null === $sourceId || null === $destId) { 91 return; 92 } 93 $sourceNode = $this->createNode($sourceId, $sourceValue); 94 $destNode = $this->createNode($destId, $destValue); 95 $edge = new ServiceReferenceGraphEdge($sourceNode, $destNode, $reference); 96 97 $sourceNode->addOutEdge($edge); 98 $destNode->addInEdge($edge); 99 } 100 101 /** 102 * Creates a graph node. 103 * 104 * @param string $id 105 * @param mixed $value 106 * 107 * @return ServiceReferenceGraphNode 108 */ 109 private function createNode($id, $value) 110 { 111 if (isset($this->nodes[$id]) && $this->nodes[$id]->getValue() === $value) { 112 return $this->nodes[$id]; 113 } 114 115 return $this->nodes[$id] = new ServiceReferenceGraphNode($id, $value); 116 } 117 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |