graphp/graphml
, (*1)
GraphML is an XML-based file format for graphs, (*2)
Note: This project is in early beta stage! Feel free to report any issues you encounter., (*3)
Table of contents, (*4)
Usage
Exporter
getOutput()
The getOutput(Graph $graph): string method can be used to
export the given graph instance., (*5)
$graph = new Fhaculty\Graph\Graph();
$a = $graph->createVertex('a');
$b = $graph->createVertex('b');
$a->createEdgeTo($b);
$exporter = new Graphp\GraphML\Exporter();
$data = $exporter->getOutput($graph);
file_put_contents('example.graphml', $data);
This method only supports exporting the basic graph structure, with all
vertices and directed and undirected edges., (*6)
Note that none of the attributes attached to any objects nor any of the
"advanced concepts" of GraphML (Nested Graphs, Hyperedges and Ports) are
currently implemented. We welcome PRs!, (*7)
Loader
loadContents()
The loadContents(string $contents): Graph method can be used to
load a graph instance from the given GraphML contents., (*8)
$data = file_get_contents('example.graphml');
$loader = new Graphp\GraphML\Loader();
$graph = $loader->loadContents($data);
foreach ($graph->getVertices() as $vertex) {
foreach ($vertex->getVerticesEdgeTo() as other) {
echo $vertex->getId() . ' connected with ' . $other->getId() . PHP_EOL;
}
}
This method supports loading the graph, all vertices and directed and
undirected edges among with any attributes attached from the GraphML
source., (*9)
Note that neither of the "advanced concepts" of GraphML (Nested Graphs,
Hyperedges and Ports) are currently implemented. We welcome PRs!, (*10)
Install
The recommended way to install this library is through composer. New to composer?, (*11)
{
"require": {
"graphp/graphml": "~0.1.0"
}
}
This project aims to run on any platform and thus does not require any PHP
extensions and supports running on legacy PHP 5.3 through current PHP 7+ and
HHVM.
It's highly recommended to use PHP 7+ for this project., (*12)
Tests
To run the test suite, you first need to clone this repo and then install all
dependencies through Composer:, (*13)
$ composer install
To run the test suite, go to the project root and run:, (*14)
$ php vendor/bin/phpunit
License
Released under the terms of the permissive MIT license., (*15)