[ Index ] |
PHP Cross Reference of phpBB-3.3.14-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 * @final since version 3.4 25 */ 26 class ServiceReferenceGraph 27 { 28 /** 29 * @var ServiceReferenceGraphNode[] 30 */ 31 private $nodes = []; 32 33 /** 34 * Checks if the graph has a specific node. 35 * 36 * @param string $id Id to check 37 * 38 * @return bool 39 */ 40 public function hasNode($id) 41 { 42 return isset($this->nodes[$id]); 43 } 44 45 /** 46 * Gets a node by identifier. 47 * 48 * @param string $id The id to retrieve 49 * 50 * @return ServiceReferenceGraphNode 51 * 52 * @throws InvalidArgumentException if no node matches the supplied identifier 53 */ 54 public function getNode($id) 55 { 56 if (!isset($this->nodes[$id])) { 57 throw new InvalidArgumentException(sprintf('There is no node with id "%s".', $id)); 58 } 59 60 return $this->nodes[$id]; 61 } 62 63 /** 64 * Returns all nodes. 65 * 66 * @return ServiceReferenceGraphNode[] 67 */ 68 public function getNodes() 69 { 70 return $this->nodes; 71 } 72 73 /** 74 * Clears all nodes. 75 */ 76 public function clear() 77 { 78 foreach ($this->nodes as $node) { 79 $node->clear(); 80 } 81 $this->nodes = []; 82 } 83 84 /** 85 * Connects 2 nodes together in the Graph. 86 * 87 * @param string $sourceId 88 * @param mixed $sourceValue 89 * @param string $destId 90 * @param mixed $destValue 91 * @param string $reference 92 */ 93 public function connect($sourceId, $sourceValue, $destId, $destValue = null, $reference = null/*, bool $lazy = false, bool $weak = false, bool $byConstructor = false*/) 94 { 95 $lazy = \func_num_args() >= 6 ? func_get_arg(5) : false; 96 $weak = \func_num_args() >= 7 ? func_get_arg(6) : false; 97 $byConstructor = \func_num_args() >= 8 ? func_get_arg(7) : false; 98 99 if (null === $sourceId || null === $destId) { 100 return; 101 } 102 103 $sourceNode = $this->createNode($sourceId, $sourceValue); 104 $destNode = $this->createNode($destId, $destValue); 105 $edge = new ServiceReferenceGraphEdge($sourceNode, $destNode, $reference, $lazy, $weak, $byConstructor); 106 107 $sourceNode->addOutEdge($edge); 108 $destNode->addInEdge($edge); 109 } 110 111 /** 112 * Creates a graph node. 113 * 114 * @param string $id 115 * @param mixed $value 116 * 117 * @return ServiceReferenceGraphNode 118 */ 119 private function createNode($id, $value) 120 { 121 if (isset($this->nodes[$id]) && $this->nodes[$id]->getValue() === $value) { 122 return $this->nodes[$id]; 123 } 124 125 return $this->nodes[$id] = new ServiceReferenceGraphNode($id, $value); 126 } 127 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |