Exemplo n.º 1
0
 public function testLoadFile()
 {
     $graph = Graph::loadFile(__DIR__ . '/../../../examples/linecount/count.json');
     $readFile = $graph->getNode('ReadFile');
     $this->assertEquals('ReadFile', $readFile['id']);
     $this->assertEquals(4, count($graph->nodes));
 }
Exemplo n.º 2
0
 /**
  * Load PhpFlo graph definition from file.
  *
  * @param string $file
  * @return \PhpFlo\Network
  */
 public static function loadFile($file)
 {
     $graph = Graph::loadFile($file);
     return Network::create($graph);
 }
Exemplo n.º 3
0
 /**
  * Load PhpFlo graph definition.
  *
  * @param stdClass $definition
  * @return \PhpFlo\Graph
  */
 public static function loadDefinition($definition)
 {
     $graph = new Graph($definition->properties->name);
     foreach ($definition->processes as $id => $def) {
         $graph->addNode($id, $def->component);
     }
     foreach ($definition->connections as $conn) {
         if (isset($conn->data)) {
             $graph->addInitial($conn->data, $conn->tgt->process, $conn->tgt->port);
             continue;
         }
         $graph->addEdge($conn->src->process, $conn->src->port, $conn->tgt->process, $conn->tgt->port);
     }
     return $graph;
 }
Exemplo n.º 4
0
 public static function loadFile($file)
 {
     if (!file_exists($file)) {
         throw new \InvalidArgumentException("File {$file} not found");
     }
     $definition = @json_decode(file_get_contents($file));
     if (!$definition) {
         throw new \InvalidArgumentException("Failed to parse PhpFlo graph definition file {$file}");
     }
     $graph = new Graph($definition->properties->name);
     foreach ($definition->processes as $id => $def) {
         $graph->addNode($id, $def->component);
     }
     foreach ($definition->connections as $conn) {
         if (isset($conn->data)) {
             $graph->addInitial($conn->data, $conn->tgt->process, $conn->tgt->port);
             continue;
         }
         $graph->addEdge($conn->src->process, $conn->src->port, $conn->tgt->process, $conn->tgt->port);
     }
     return $graph;
 }