rnd / gremlin-dsl
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: 2023-02-03 23:07:44 UTC
README
信息
由于原始存储库已被停止,这是继续使用的软件包。
简介
Gremlin 是由 Apache TinkerPop 开发的图遍历语言。
许多图数据库供应商,如 Neo4j、Azure Cosmos、AWS Neptune 以及更多,都支持 Gremlin。
该软件包为 PHP 应用程序提供 Gremlin 的基本集成。
此版本基于 TinkerPop v3.6.1 构建。
安装
composer require specialweb/gremlin-dsl
配置
此软件包提供了一个静态的 Configuration 类,其中包含一些配置选项。
选项 | 范围 | 类型 | 默认值 | 描述 |
---|---|---|---|---|
GREMLIN_DSL_REGISTER_GLOBAL_FUNCTIONS | 常量 | 布尔值 | false | 全局注册 Gremlin 的 短函数。 例如,全局的 g 函数可用于启动遍历。 |
enableShortFunctions | 配置 | 布尔值 | false | 全局注册 Gremlin 的 短函数。 例如,全局的 g 函数可用于启动遍历。 |
sendClosure | 配置 | 闭包 | null | 注册全局回调以用于 伪发送步骤。 |
您可以从数组中进行配置
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
步骤。
您可以为发送步骤全局配置一个闭包,或每次调用时提供它。
<?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