graphp / graphml
GraphML 是一种基于 XML 的图文件格式
v0.1.0
2015-06-07 22:43 UTC
Requires
- php: >=5.3
- ext-simplexml: *
- clue/graph: ~0.9.0|~0.8.0
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is auto-updated.
Last update: 2024-08-29 01:40:38 UTC
README
GraphML 是一种基于 XML 的图文件格式
注意:此项目处于早期测试阶段!欢迎报告您遇到的任何问题。
目录
使用方法
导出器
getOutput()
可以使用 getOutput(Graph $graph): string
方法来导出给定的图实例。
$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);
此方法仅支持导出基本图结构,包括所有顶点和有向和无向边。
请注意,当前尚未实现任何对象附加的属性或 GraphML 的“高级概念”(嵌套图、超边和端口)。我们欢迎 PRs!
加载器
loadContents()
可以使用 loadContents(string $contents): Graph
方法从给定的 GraphML 内容加载图实例。
$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; } }
此方法支持从 GraphML 源加载图、所有顶点以及有向和无向边,包括任何附加的属性。
请注意,当前尚未实现 GraphML 的“高级概念”(嵌套图、超边和端口)。我们欢迎 PRs!
安装
建议使用 composer 安装此库。 您是 composer 新手?
{ "require": { "graphp/graphml": "~0.1.0" } }
此项目旨在在任何平台上运行,因此不要求任何 PHP 扩展,并支持从旧版 PHP 5.3 运行到当前 PHP 7+ 和 HHVM。强烈建议使用 PHP 7+ 来使用此项目。
测试
要运行测试套件,首先需要克隆此存储库,然后通过 Composer 安装所有依赖项
$ composer install
要运行测试套件,请转到项目根目录并运行
$ php vendor/bin/phpunit
许可证
在 MIT 许可证的条款下发布。