specialweb/gremlin-dsl 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

specialweb/gremlin-dsl

Composer 安装命令:

composer require specialweb/gremlin-dsl

包简介

Gremlin DSL PHP integration

README 文档

README

PHPCS PHPUnit License Downloads Latest version codecov

Information

As the original repository was discontinued this is the continuing package to work with.

Introduction

Gremlin is a graph traversal language developed by Apache TinkerPop.

Many graph vendors like Neo4j, Azure Cosmos, AWS Neptune and many more supports Gremlin.

This package provides a basic integration of gremlin for php applications.

This version is built from TinkerPop v3.6.1.

Installation

composer require specialweb/gremlin-dsl

Configuration

This packages provides a static Configuration Class with some configuration options.

Option Scope Type Default Description
GREMLIN_DSL_REGISTER_GLOBAL_FUNCTIONS Constant boolean false Globally register short-functions for gremlin.
E.g. the global g-function will be available to start the traversal.
enableShortFunctions Configuration boolean false Globally register short-functions for gremlin.
E.g. the global g-function will be available to start the traversal.
sendClosure Configuration Closure null Register a global callback for the pseudo send step

You can either configure it from array:

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,
]);

or set the desired settings directly:

use SpecialWeb\GremlinDSL\Configuration;

/** @var \Brightzone\GremlinDriver\Connection $connection */
$connection = null;

Configuration::getInstance()
    ->setSendClosure(function (string $traversalString) use ($connection) {
        return $connection->send($traversalString);
    })
    ->enableShortFunctions()
;

Usage

Just install the package and begin traversing.

<?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")

Sending the graph traversal string

There is a pseudo send step provided with this package.

You can either globally configure a closure for the send step or provide it with every call.

<?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);

Instead of a closure you can also provide an instance of 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
    }
}

Short functions

Short functions are simplifying the graph traversal generation and usage of predicates.

You've to enable GREMLIN_DSL_REGISTER_GLOBAL_FUNCTIONS, manually load e.g. resources/predicates.php or call Configuration::enableShortFunctions() to make short functions available.

<?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")

With GREMLIN_DSL_REGISTER_GLOBAL_FUNCTIONS constant:

<?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")

Development

DSL generation

The DSL generation is based on the java base-classes.

To (re)generate the DSL just call make generate that will first generate the JSON methods structure and afterwards the php file generation.

Generate JSON only

Just call make generate-json or mvn -f generator -P glv-json compile

Generate PHP only

To e.g. adjust the php file generation you can either call php generate.php [dsl:generate [<in-file>]] or make generate-php

specialweb/gremlin-dsl 适用场景与选型建议

specialweb/gremlin-dsl 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 10 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 specialweb/gremlin-dsl 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 specialweb/gremlin-dsl 我们能提供哪些服务?
定制开发 / 二次开发

基于 specialweb/gremlin-dsl 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-05