plasmaconduit / dependency-graph
此包已被放弃且不再维护。没有建议的替代包。
此包的最新版本(v0.1.0)没有可用的许可信息。
v0.1.0
2013-03-26 05:52 UTC
Requires
- plasmaconduit/either: 0.2.*
- plasmaconduit/map: 0.1.*
- plasmaconduit/option: 0.2.*
This package is not auto-updated.
Last update: 2016-11-24 06:35:06 UTC
README
依赖关系图实现。
示例
<?php use PlasmaConduit\DependencyGraph; use PlasmaConduit\dependencygraph\DependencyGraphNode; use PlasmaConduit\dependencygraph\DependencyGraphNodes; // Initialize the graph and some stand alone nodes $graph = new DependencyGraph(); $nodeA = new DependencyGraphNode("A"); $nodeB = new DependencyGraphNode("B"); $nodeC = new DependencyGraphNode("C"); $nodeD = new DependencyGraphNode("D"); $nodeE = new DependencyGraphNode("E"); $nodeF = new DependencyGraphNode("F"); $nodeG = new DependencyGraphNode("G"); // Add the root node A $graph->addRoot($nodeA); $graph->addDependency($nodeA, $nodeB); $graph->addDependency($nodeA, $nodeC); $graph->addDependency($nodeB, $nodeD); $graph->addDependency($nodeC, $nodeE); $graph->addDependency($nodeC, $nodeF); // Tree Status: // A // / \ // B C // / / \ // D E F echo json_encode($graph->toArray(), JSON_PRETTY_PRINT); // Outputs: // [ // { // "A": [ // { // "B": [ // "D" // ] // }, // { // "C": [ // "D", // "E" // ] // } // ] // } // ] // Try to create a circular dependency by making E dependent on A // This should fail and refuse to fulfill the dependency $graph->addDependency($nodeE, $nodeA); echo json_encode($graph->toArray(), JSON_PRETTY_PRINT); // Outputs: // [ // { // "A": [ // { // "B": [ // "D" // ] // }, // { // "C": [ // "D", // "E" // ] // } // ] // } // ] // Add a node that already has dependencies to an adjacent branch $graph->addDependency($nodeD, $nodeC); // Tree Status: // A // / \ // B C // / / \ // D E F // \ // C // / \ // E F echo json_encode($graph->toArray(), JSON_PRETTY_PRINT); // Outputs: // [ // { // "A": [ // { // "B": [ // { // "D": [ // { // "C": [ // "E", // "F" // ] // } // ] // } // ] // }, // { // "C": [ // "E", // "F" // ] // } // ] // } // ] echo implode(",", $graph->flatten());