Example #1
0
 /**
  * Exports a graph to a graphviz image.
  *
  * @param NodeInterface $node    - Graph.
  * @param array         $options - Options.
  *
  * @throws InvalidWriterTypeException
  *
  * @return Response
  */
 public function export(NodeInterface $node, array $options = [])
 {
     $options = array_replace_recursive(['writer' => 'graphviz'], $options);
     if (is_string($options['writer'])) {
         switch ($options['writer']) {
             case 'graphviz':
                 $options['path'] = $options['path'] ?? $this->generateRandomFilePath();
                 $options['writer'] = new GraphvizWriter();
                 break;
             default:
                 throw InvalidWriterTypeException::create($options['writer']);
         }
     }
     $config = new Config(['node' => $node], ['writer' => $options['writer']]);
     $config->save(['writerOptions' => $options]);
     $response = new Response();
     $response->setPath($options['path']);
     return $response;
 }