1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Grafizzi\Graph\Filter\DotFilter: a component of the Grafizzi library. |
6
|
|
|
* |
7
|
|
|
* (c) 2012 Frédéric G. MARAND <[email protected]> |
8
|
|
|
* |
9
|
|
|
* Grafizzi is free software: you can redistribute it and/or modify it under the |
10
|
|
|
* terms of the GNU Lesser General Public License as published by the Free |
11
|
|
|
* Software Foundation, either version 3 of the License, or (at your option) any |
12
|
|
|
* later version. |
13
|
|
|
* |
14
|
|
|
* Grafizzi is distributed in the hope that it will be useful, but WITHOUT ANY |
15
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
16
|
|
|
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
17
|
|
|
* details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
20
|
|
|
* along with Grafizzi, in the COPYING.LESSER.txt file. If not, see |
21
|
|
|
* <http://www.gnu.org/licenses/> |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace Grafizzi\Graph\Filter; |
25
|
|
|
|
26
|
|
|
use Grafizzi\Graph\Renderer; |
27
|
|
|
use Pimple\Container; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* A CommandFilter for the dot main commands: dot, neato, (s)fdp, circo, twopi. |
31
|
|
|
* |
32
|
|
|
* These filters share a common option regarding image format, as well as many |
33
|
|
|
* others not exposed here. |
34
|
|
|
*/ |
35
|
|
|
class DotFilter extends AbstractCommandFilter { |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var \Pimple\Container |
39
|
|
|
*/ |
40
|
|
|
protected $dic; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Valid output formats. |
44
|
|
|
* |
45
|
|
|
* @var array |
46
|
|
|
*/ |
47
|
|
|
public $formats = []; |
48
|
|
|
|
49
|
|
|
public static $commandName = 'dot'; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @throws \InvalidArgumentException |
53
|
|
|
* |
54
|
|
|
* @param string $format |
55
|
|
|
* |
56
|
|
|
* @return boolean |
57
|
|
|
*/ |
58
|
4 |
|
public function image($format) { |
59
|
4 |
|
if (empty($this->formats)) { |
60
|
|
|
// In case of failure, this will hold an empty array, not null. |
61
|
4 |
|
$this->formats = Renderer::getFormats($this->dic); |
62
|
|
|
} |
63
|
|
|
|
64
|
4 |
|
if (!in_array($format, $this->formats)) { |
65
|
3 |
|
$ret = false; |
66
|
3 |
|
if (!empty($this->dic['use_exceptions'])) { |
67
|
3 |
|
throw new \InvalidArgumentException('Invalid image format'); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
else { |
71
|
1 |
|
$ret = true; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
// TODO perform rendering. |
75
|
3 |
|
return $ret; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param Container $dic |
80
|
|
|
* |
81
|
|
|
* @return $this |
82
|
|
|
*/ |
83
|
5 |
|
public function setDic(Container $dic) { |
84
|
5 |
|
$this->dic = $dic; |
85
|
5 |
|
return $this; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|