specialweb / gremlin-dsl
Gremlin DSL PHP集成
Requires
- php: >=8.0
- ext-json: *
Requires (Dev)
- nette/php-generator: ^v4.0.0
- phpcompatibility/php-compatibility: ^9.3
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.7
- symfony/console: ^6.0
- symfony/var-dumper: ^6.0
Suggests
- brightzone/gremlin-php: gremlin-server client for php
Replaces
- dev-main
- 1.0.1
- 1.0.0
- 0.5.0
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.0
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.0
- dev-dependabot/composer/phpunit/phpunit-tw-9.5or-tw-10.0
- dev-dependabot/maven/generator/org.apache.tinkerpop-tinkerpop-3.6.2
- dev-dependabot/github_actions/actions/checkout-3.3.0
- dev-dependabot/github_actions/php-actions/phpunit-9
This package is auto-updated.
Last update: 2024-09-30 01:23:22 UTC
README
信息
由于原始仓库已停止维护,这是继续工作的包。
简介
Gremlin是由Apache TinkerPop开发的一种图遍历语言。
许多图数据库供应商,如Neo4j、Azure Cosmos、AWS Neptune和许多其他,都支持Gremlin。
此包为PHP应用程序提供Gremlin的基本集成。
此版本基于TinkerPop v3.6.1构建。
安装
composer require specialweb/gremlin-dsl
配置
此包提供了一些配置选项的静态配置类。
您可以从数组中配置它
use SpecialWeb\GremlinDSL\Configuration; /** @var \Brightzone\GremlinDriver\Connection $connection */ $connection = null; Configuration::fromConfig([ 'sendClosure' => function (string $traversalString) use ($connection) { return $connection->send($traversalString); }, 'enableShortFunctions' => true, ]);
或直接设置所需的设置
use SpecialWeb\GremlinDSL\Configuration; /** @var \Brightzone\GremlinDriver\Connection $connection */ $connection = null; Configuration::getInstance() ->setSendClosure(function (string $traversalString) use ($connection) { return $connection->send($traversalString); }) ->enableShortFunctions() ;
使用方法
只需安装此包即可开始遍历。
<?php require_once 'vendor/autoload.php'; echo \SpecialWeb\GremlinDSL\Traversal\GraphTraversal::g() ->V(1)->out('knows')->has('age', new \SpecialWeb\GremlinDSL\Traversal\Predicates\Gt(30))->values('name'); # g.V(1).out("knows").has("age", gt(30)).values("name")
发送图遍历字符串
此包提供了一个伪send
步骤。
您可以为send步骤全局配置一个闭包,或为每个调用提供它。
<?php require_once 'vendor/autoload.php'; use SpecialWeb\GremlinDSL\Configuration; /** @var \Brightzone\GremlinDriver\Connection $connection */ $connection = null; $sendClosure = function (string $traversalString) use ($connection) { return $connection->send($traversalString); }; Configuration::getInstance()->setSendClosure($sendClosure); g()->V(1)->out("knows")->has("age", gt(30))->values("name")->send(); # or g()->V(1)->out("knows")->has("age", gt(30))->values("name")->send($sendClosure);
您也可以提供一个SendClosureInterface的实例。
use SpecialWeb\GremlinDSL\Traversal\SendClosureInterface; use SpecialWeb\GremlinDSL\Traversal\GraphTraversalInterface; class SendClosure implements SendClosureInterface { public function __invoke(GraphTraversalInterface $graphTraversal, string $traversalString) { // handle the send } }
简短函数
简短函数简化了图遍历生成和谓词的使用。
您需要启用GREMLIN_DSL_REGISTER_GLOBAL_FUNCTIONS
,手动加载例如resources/predicates.php或调用Configuration::enableShortFunctions()
来使简短函数可用。
<?php require_once 'vendor/autoload.php'; \SpecialWeb\GremlinDSL\Configuration::getInstance()->enableShortFunctions(); g()->V(1)->out('knows')->has('age', gt(30))->values('name'); # g.V(1).out("knows").has("age", gt(30)).values("name")
使用GREMLIN_DSL_REGISTER_GLOBAL_FUNCTIONS
常量
<?php define('GREMLIN_DSL_REGISTER_GLOBAL_FUNCTIONS', true); require_once 'vendor/autoload.php'; # With GREMLIN_DSL_REGISTER_GLOBAL_FUNCTIONS enabled: g()->V(1)->out('knows')->has('age', gt(30))->values('name'); # g.V(1).out("knows").has("age", gt(30)).values("name")
开发
DSL生成
DSL生成基于java基础类。
要(重新)生成DSL,只需调用make generate
,它将首先生成JSON方法结构,然后生成PHP文件。
仅生成JSON
只需调用make generate-json
或mvn -f generator -P glv-json compile
仅生成PHP
例如,要调整PHP文件生成,您可以调用php generate.php [dsl:generate [<in-file>]]
或make generate-php