PHP code example of specialweb / gremlin-dsl

1. Go to this page and download the library: Download specialweb/gremlin-dsl library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

specialweb / gremlin-dsl example snippets


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



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


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

use SpecialWeb\GremlinDSL\Traversal\SendClosureInterface;
use SpecialWeb\GremlinDSL\Traversal\GraphTraversalInterface;

class SendClosure implements SendClosureInterface
{
    public function __invoke(GraphTraversalInterface $graphTraversal, string $traversalString) {
        // handle the send
    }
}



ialWeb\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")



define('GREMLIN_DSL_REGISTER_GLOBAL_FUNCTIONS', true);
(1)->out('knows')->has('age', gt(30))->values('name');
# g.V(1).out("knows").has("age", gt(30)).values("name")