beyondcode /
laravel-er-diagram-generator
| 1 | <?php |
||
| 2 | |||
| 3 | namespace BeyondCode\ErdGenerator; |
||
| 4 | |||
| 5 | use phpDocumentor\GraphViz\Node; |
||
| 6 | |||
| 7 | /** |
||
| 8 | * Class Edge |
||
| 9 | * @package BeyondCode\ErdGenerator |
||
| 10 | * @method void setLabel(string $name) |
||
| 11 | * @method void setXLabel(string $name) |
||
| 12 | * |
||
| 13 | */ |
||
| 14 | class Edge extends \phpDocumentor\GraphViz\Edge |
||
| 15 | { |
||
| 16 | protected $fromPort = null; |
||
| 17 | |||
| 18 | protected $toPort = null; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @param Node $from |
||
| 22 | * @param Node $to |
||
| 23 | * @return Edge|\phpDocumentor\GraphViz\Edge |
||
| 24 | */ |
||
| 25 | public static function create(Node $from, Node $to) { |
||
| 26 | return new static($from, $to); |
||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @param null $fromPort |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 31 | */ |
||
| 32 | public function setFromPort($fromPort): void |
||
| 33 | { |
||
| 34 | $this->fromPort = $fromPort; |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param null $toPort |
||
|
0 ignored issues
–
show
|
|||
| 39 | */ |
||
| 40 | public function setToPort($toPort): void |
||
| 41 | { |
||
| 42 | $this->toPort = $toPort; |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Returns the edge definition as is requested by GraphViz. |
||
| 47 | * |
||
| 48 | * @return string |
||
| 49 | */ |
||
| 50 | public function __toString() |
||
| 51 | { |
||
| 52 | $attributes = array(); |
||
| 53 | foreach ($this->attributes as $value) { |
||
| 54 | $attributes[] = (string)$value; |
||
| 55 | } |
||
| 56 | $attributes = implode("\n", $attributes); |
||
| 57 | |||
| 58 | $from_name = addslashes($this->getFrom()->getName()); |
||
| 59 | $to_name = addslashes($this->getTo()->getName()); |
||
| 60 | $from_name .= (!empty($this->fromPort)) ? ':' . $this->fromPort : ''; |
||
| 61 | $to_name .= (!empty($this->toPort)) ? ':' . $this->toPort : ''; |
||
| 62 | |||
| 63 | return <<<DOT |
||
| 64 | $from_name -> $to_name [ |
||
| 65 | $attributes |
||
| 66 | ] |
||
| 67 | DOT; |
||
| 68 | } |
||
| 69 | } |