Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies in order to improve MS Windows support #23

Merged
merged 2 commits into from
Nov 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"homepage": "https://github.com/clue/graph-composer",
"license": "MIT",
"require": {
"clue/graph": "0.7.*",
"clue/graph": "~0.9.0",
"jms/composer-deps-analyzer": "0.1.*",
"symfony/console": "~2.1"
"symfony/console": "~2.1",
"graphp/graphviz": "~0.2.0"
},
"autoload": {
"psr-0": {"Clue": "src/"}
Expand Down
151 changes: 117 additions & 34 deletions composer.lock

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

90 changes: 53 additions & 37 deletions src/Clue/GraphComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace Clue;

use Fhaculty\Graph\GraphViz;
use Fhaculty\Graph\Graph;
use Fhaculty\Graph\Attribute\AttributeAware;
use Fhaculty\Graph\Attribute\AttributeBagNamespaced;
use Graphp\GraphViz\GraphViz;

class GraphComposer
{
Expand All @@ -13,96 +15,110 @@ class GraphComposer
'shape' => 'box',
'fontcolor' => '#314B5F'
);

private $layoutVertexRoot = array(
'style' => 'filled, rounded, bold'
);

private $layoutEdge = array(
'fontcolor' => '#767676',
'fontsize' => 10,
'color' => '#1A2833'
);

private $layoutEdgeDev = array(
'style' => 'dashed'
);

private $dependencyGraph;

private $format = 'svg';


/**
* @var GraphViz
*/
private $graphviz;

/**
*
*
* @param string $dir
* @param GraphViz|null $graphviz
*/
public function __construct($dir)
public function __construct($dir, GraphViz $graphviz = null)
{
if ($graphviz === null) {
$graphviz = new GraphViz();
}
$analyzer = new \JMS\Composer\DependencyAnalyzer();
$this->dependencyGraph = $analyzer->analyze($dir);
$this->graphviz = $graphviz;
}

/**
*
*
* @param string $dir
* @return \Fhaculty\Graph\Graph
*/
public function createGraph()
{
$graph = new Graph();

foreach ($this->dependencyGraph->getPackages() as $package) {
$name = $package->getName();
$start = $graph->createVertex($name, true);

$label = $name;
if ($package->getVersion() !== null) {
$label .= ': ' . $package->getVersion();
}
$start->setLayout(array('label' => $label) + $this->layoutVertex);

$this->setLayout($start, array('label' => $label) + $this->layoutVertex);

foreach ($package->getOutEdges() as $requires) {
$targetName = $requires->getDestPackage()->getName();
$target = $graph->createVertex($targetName, true);

$label = $requires->getVersionConstraint();

$edge = $start->createEdgeTo($target)->setLayout(array('label' => $label) + $this->layoutEdge);


$edge = $start->createEdgeTo($target);
$this->setLayout($edge, array('label' => $label) + $this->layoutEdge);

if ($requires->isDevDependency()) {
$edge->setLayout($this->layoutEdgeDev);
$this->setLayout($edge, $this->layoutEdgeDev);
}
}
}

$graph->getVertex($this->dependencyGraph->getRootPackage()->getName())->setLayout($this->layoutVertexRoot);

$root = $graph->getVertex($this->dependencyGraph->getRootPackage()->getName());
$this->setLayout($root, $this->layoutVertexRoot);

return $graph;
}


private function setLayout(AttributeAware $entity, array $layout)
{
$bag = new AttributeBagNamespaced($entity->getAttributeBag(), 'graphviz.');
$bag->setAttributes($layout);

return $entity;
}

public function displayGraph()
{
$graph = $this->createGraph();

$graphviz = new GraphViz($graph);
$graphviz->setFormat($this->format);
$graphviz->display();

$this->graphviz->display($graph);
}

public function getImagePath()
{
$graph = $this->createGraph();

$graphviz = new GraphViz($graph);
$graphviz->setFormat($this->format);

return $graphviz->createImageFile();

return $this->graphviz->createImageFile($graph);
}

public function setFormat($format)
{
$this->format = $format;
$this->graphviz->setFormat($format);

return $this;
}
}
Loading