src/Export/Writer/GraphvizWriter.php
public function write(array $data, array $options)
    {
        if (!$this->getUtils()->isDotInstalled()) {
            throw ExportException::create(
                'Can\'t export to a Graphviz image because "dot" binary is not available. Verify that the ' .
                '"graphviz" package is installed on your system.'
            );
        }

        if (!isset($data['node']) || !($data['node'] instanceof NodeInterface)) {
            throw ValidationException::create(
                'Data attribute "node" must be an instance of IronEdge\Component\Graphs\Node\NodeInterface.'
            );
        }

        if (!isset($options['path']) || !is_string($options['path']) || $options['path'] === '') {
            throw ValidationException::create(
                'To be able to export this graph to a graphviz image, you must set option "path" with a string ' .
                'with the path to the target file.'
            );
        }

        /** @var NodeInterface $graph */
        $graph = $data['node'];
        $file = $options['path'];

        $graphvizCode = 'digraph ' . $graph->getId() . ' {' . PHP_EOL;
        $graphAttributes = $graph->getMetadataAttr('graphviz.nodeAttributes', []);

        if ($graphAttributes) {
            foreach ($graphAttributes as $k => $v) {
                $graphvizCode .= '  ' . $k . '=' . $v . ';' . PHP_EOL;
            }

            $graphvizCode .= PHP_EOL;
        }

        $graphvizCode .= $this->generateNodeCode($graph);

        $graphvizCode .= '}';

        $this->generateGraphvizOutputFile($graphvizCode, $file, ['targetType' => 'png']);
    }
public function write(array $data, array $options)
    {
        if (!$this->getUtils()->isDotInstalled()) {
            throw ExportException::create(
                'Can\'t export to a Graphviz image because "dot" binary is not available. Verify that the ' .
                '"graphviz" package is installed on your system.'
            );
        }

        if (!isset($data['node']) || !($data['node'] instanceof NodeInterface)) {
            throw ValidationException::create(
                'Data attribute "node" must be an instance of IronEdge\Component\Graphs\Node\NodeInterface.'
            );
        }

        if (!isset($options['path']) || !is_string($options['path']) || $options['path'] === '') {
            throw ValidationException::create(
                'To be able to export this graph to a graphviz image, you must set option "path" with a string ' .
                'with the path to the target file.'
            );
        }

        /** @var NodeInterface $graph */
        $graph = $data['node'];
        $file = $options['path'];

        $graphvizCode = 'digraph ' . $graph->getId() . ' {' . PHP_EOL;
        $graphAttributes = $graph->getMetadataAttr('graphviz.nodeAttributes', []);

        if ($graphAttributes) {
            foreach ($graphAttributes as $k => $v) {
                $graphvizCode .= '  ' . $k . '=' . $v . ';' . PHP_EOL;
            }

            $graphvizCode .= PHP_EOL;
        }

        $graphvizCode .= $this->generateNodeCode($graph);

        $graphvizCode .= '}';

        $this->generateGraphvizOutputFile($graphvizCode, $file, ['targetType' => 'png']);
    }
public function write ( array $ data , array $ options ) { if ( ! $ this -> getUtils ( ) -> isDotInstalled ( ) ) { throw ExportException :: create ( 'Can\'t export to a Graphviz image because "dot" binary is not available. Verify that the ' . '"graphviz" package is installed on your system.' ) ; } if ( ! isset ( $ data [ 'node' ] ) || ! ( $ data [ 'node' ] instanceof NodeInterface ) ) { throw ValidationException :: create ( 'Data attribute "node" must be an instance of IronEdge\Component\Graphs\Node\NodeInterface.' ) ; } if ( ! isset ( $ options [ 'path' ] ) || ! is_string ( $ options [ 'path' ] ) || $ options [ 'path' ] === '' ) { throw ValidationException :: create ( 'To be able to export this graph to a graphviz image, you must set option "path" with a string ' . 'with the path to the target file.' ) ; } /** @var NodeInterface $graph */ $ graph = $ data [ 'node' ] ; $ file = $ options [ 'path' ] ; $ graphvizCode = 'digraph ' . $ graph -> getId ( ) . ' {' . PHP_EOL ; $ graphAttributes = $ graph -> getMetadataAttr ( 'graphviz.nodeAttributes' , [ ] ) ; if ( $ graphAttributes ) { foreach ( $ graphAttributes as $ k => $ v ) { $ graphvizCode .= '  ' . $ k . '=' . $ v . ';' . PHP_EOL ; } $ graphvizCode .= PHP_EOL ; } $ graphvizCode .= $ this -> generateNodeCode ( $ graph ) ; $ graphvizCode .= '}' ; $ this -> generateGraphvizOutputFile ( $ graphvizCode , $ file , [ 'targetType' => 'png' ] ) ; }
Writes the data into a graphviz image.

@param array $data    - Data.
@param array $options - Options.

@throws ValidationException
@throws ExportException

@return void
Writes the data into a graphviz image .