Skip to content

Commit

Permalink
Merge pull request #312 from tapestry-cloud/2.0.0-issue297-dev
Browse files Browse the repository at this point in the history
2.0.0 issue297 dev
  • Loading branch information
carbontwelve authored Aug 15, 2018
2 parents bbe4d4e + ff46a28 commit 97f2e48
Show file tree
Hide file tree
Showing 79 changed files with 4,412 additions and 206 deletions.
48 changes: 24 additions & 24 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/Entities/ContentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
use Tapestry\Entities\Collections\FlatCollection;
use Tapestry\Modules\Renderers\ContentRendererFactory;

/**
* Class ContentType.
* @deprecated use Tapestry\Modules\ContentTypes\ContentType
*/
class ContentType
{
/**
Expand Down
61 changes: 61 additions & 0 deletions src/Entities/DependencyGraph/Debug.php
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;
}
}
72 changes: 72 additions & 0 deletions src/Entities/DependencyGraph/Graph.php
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];
}
}
41 changes: 41 additions & 0 deletions src/Entities/DependencyGraph/Node.php
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;
}
Loading

0 comments on commit 97f2e48

Please sign in to comment.