-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #312 from tapestry-cloud/2.0.0-issue297-dev
2.0.0 issue297 dev
- Loading branch information
Showing
79 changed files
with
4,412 additions
and
206 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Tapestry\Entities\DependencyGraph; | ||
|
||
class Debug | ||
{ | ||
/** | ||
* @var Graph | ||
*/ | ||
private $graph; | ||
|
||
/** | ||
* Debug constructor. | ||
* @param Graph $graph | ||
*/ | ||
public function __construct(Graph $graph) | ||
{ | ||
$this->graph = $graph; | ||
} | ||
|
||
/** | ||
* @param string $edge | ||
* @param array|null $arr | ||
* @return string | ||
* @throws \Tapestry\Exceptions\GraphException | ||
*/ | ||
public function graphViz(string $edge, $arr = null): String | ||
{ | ||
if (is_null($arr)) { | ||
$arr = [ | ||
'digraph Tapestry {', | ||
' rankdir=LR;', | ||
' bgcolor="0 0 .91";', | ||
' node [shape=circle];', | ||
]; | ||
} | ||
$arr = array_merge($arr, $this->walkGraph($edge, [])); | ||
$arr[] = '}'; | ||
|
||
return implode(PHP_EOL, $arr); | ||
} | ||
|
||
/** | ||
* @param string $edge | ||
* @param array $arr | ||
* @return array | ||
* @throws \Tapestry\Exceptions\GraphException | ||
*/ | ||
private function walkGraph(string $edge, array $arr): array | ||
{ | ||
$node = $this->graph->getEdge($edge); | ||
foreach ($node->getEdges() as $edge) { | ||
$arr[] = sprintf(' "%s" -> "%s"', $node->getUid(), $edge->getUid()); | ||
if (count($edge->getEdges()) > 0) { | ||
$arr = $this->walkGraph($edge->getUid(), $arr); | ||
} | ||
} | ||
|
||
return $arr; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace Tapestry\Entities\DependencyGraph; | ||
|
||
use Tapestry\Exceptions\GraphException; | ||
|
||
class Graph | ||
{ | ||
/** | ||
* @var Node | ||
*/ | ||
private $root; | ||
|
||
/** | ||
* uid -> obj node lookup table. | ||
* | ||
* @var Node[] | ||
*/ | ||
private $table = []; | ||
|
||
/** | ||
* Graph constructor. | ||
* @param Node|null $root | ||
*/ | ||
public function __construct(Node $root = null) | ||
{ | ||
if (! is_null($root)) { | ||
$this->setRoot($root); | ||
} | ||
} | ||
|
||
/** | ||
* This method acts to reset the Graph before | ||
* setting the root node. | ||
* | ||
* @param Node $node | ||
*/ | ||
public function setRoot(Node $node) | ||
{ | ||
$this->table = []; | ||
$this->root = $node; | ||
$this->table[$node->getUid()] = $node; | ||
} | ||
|
||
/** | ||
* @param string $uid | ||
* @param Node $node | ||
* @throws GraphException | ||
*/ | ||
public function addEdge(string $uid, Node $node) | ||
{ | ||
if (! isset($this->table[$uid])) { | ||
throw new GraphException('The edge ['.$uid.'] is not found in graph.'); | ||
} | ||
$this->table[$uid]->addEdge($node); | ||
$this->table[$node->getUid()] = $node; | ||
} | ||
|
||
/** | ||
* @param string $uid | ||
* @return Node | ||
* @throws GraphException | ||
*/ | ||
public function getEdge(string $uid): Node | ||
{ | ||
if (! isset($this->table[$uid])) { | ||
throw new GraphException('The edge ['.$uid.'] is not found in graph.'); | ||
} | ||
|
||
return $this->table[$uid]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Tapestry\Entities\DependencyGraph; | ||
|
||
interface Node | ||
{ | ||
/** | ||
* Get this nodes uid. | ||
* | ||
* @return string | ||
*/ | ||
public function getUid(): string; | ||
|
||
/** | ||
* Add a source that depends upon this source. | ||
* | ||
* @param Node $node | ||
*/ | ||
public function addEdge(Node $node); | ||
|
||
/** | ||
* @return Node[]|array | ||
*/ | ||
public function getEdges(): array; | ||
|
||
/** | ||
* Compare a node (from cache) to see if it is valid. | ||
* | ||
* Useful for reducing the node graph to just those that have | ||
* been modified. | ||
* | ||
* Will return false if the node being compared is newer or different. | ||
* | ||
* Must be used against nodes of the same id, will throw an exception | ||
* if the id is different. | ||
* | ||
* @param Node $node | ||
* @return bool | ||
*/ | ||
public function isSame(Node $node): bool; | ||
} |
Oops, something went wrong.