2017 © Pedro Peláez
 

library gremlin-php

gremlin-server client for php

image

chekun/gremlin-php

gremlin-server client for php

  • Saturday, July 4, 2015
  • by chekun
  • Repository
  • 1 Watchers
  • 0 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 8 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

This is a Gremlin server client for PHP. Supported versions : M9-RC3, (*1)

Changes

There are many changes but bellow are the most noticeable if you've used rexpro-php before, (*2)

  • Client now throw errors that you will need to catch
  • Connection params have changes
  • Messages class has been revamped and is independant from Connection (see documentation on how to use this)
  • Unit testing will require some more configuration
  • Runs sessionless by default (rexpro-php 2.3 & 2.4+ ran with sessions as the default)
  • Gremlin code change g.V/E should now be written as g.V()/E()

Installation

PHP Gremlin-Server Client

For Gremlin-Server 3.0.0-M5+

Prefered method is through composer. Add the following to your composer.json file:, (*3)

{
    "repositories": [
        {
            "type": "git",
            "url": "https://github.com/PommeVerte/gremlin-php.git"
        }
    ],
    "require": {
        "brightzone/gremlin-php": "master"
    }
}

If you just want to pull and use the library do:, (*4)

git clone https://github.com/PommeVerte/gremlin-php.git
cd gremlin-php
composer install --no-dev # required to set autoload files

Namespace

The Connection class exists within the rexpro namespace. (history: rexpro used to be the old protocol used by the driver in Tinkerpop2). This means that you have to do either of the two following:, (*5)

require_once('vendor/autoload.php');
use \brightzone\rexpro\Connection;

$db = new Connection;

Or, (*6)

require_once('vendor/autoload.php');

$db = new \brightzone\rexpro\Connection;

Examples

You can find more information by reading the API in the wiki., (*7)

Here are a few basic usages., (*8)

Example 1 :, (*9)

$db = new Connection;
//you can set $db->timeout = 0.5; if you wish
$db->open('localhost', 'graph');

$result = $db->send('g.V(2)');
//do something with result
$db->close();

Note that "graph" is the name of the graph configured in gremlin-server (not the reference to the traversal which is g = graph.traversal()), (*10)

Example 1 bis (Writing the same with message object) :, (*11)

$db = new Connection;
//you can set $db->timeout = 0.5; if you wish
$db->open('localhost', 'graph');

$db->message->gremlin = 'g.V(2)';
$result = $db->send(); //automatically fetches the message
//do something with result
$db->close();

Example 2 (with bindings) :, (*12)

$db = new Connection;
$db->open('localhost:8182', 'graph');

$db->message->bindValue('CUSTO_BINDING', 2);
$result = $db->send('g.V(CUSTO_BINDING)'); //mix between Example 1 and 1B
//do something with result
$db->close();

Example 3 (with session) :, (*13)

$db = new Connection;
$db->open('localhost:8182');
$db->send('cal = 5+5', 'session');
$result = $db->send('cal', 'session'); // result = [10]
//do something with result
$db->close();

Example 4 (transaction) :, (*14)

$db = new Connection;
$db->open('localhost:8182','graphT');

$db->transactionStart();

$db->send('n.addVertex("name","michael")');
$db->send('n.addVertex("name","john")');

$db->transactionStop(FALSE); //rollback changes. Set to true to commit.
$db->close();

Note that "graphT" above refers to a graph that supports transactions. And that transactions start a session automatically., (*15)

Example 5 (Using message object) :, (*16)

$message = new Messages;
$message->gremlin = 'g.V()';
$message->op = 'eval';
$message->processor = '';
$message->setArguments([
                'language' => 'gremlin-groovy',
                // .... etc
]);
$message->registerSerializer('\brightzone\rexpro\serializers\Json');

$db = new Connection;
$db->open();
$result = $db->send($message);
//do something with result
$db->close();

Of course you can affect the current db message in the same manner through $db->message., (*17)

Adding Serializers

This library comes with a Json and an unused legacy Msgpack serializer. Any other serializer that implements SerializerInterface can be added dynamically with:, (*18)

$db = new Connection;
$serializer = $db->message->getSerializer() ; // returns an instance of the default JSON serializer
echo $serializer->getName(); // JSON
echo $serializer->getMimeType(); // application/json

$db->message->registerSerializer('namespace\to\my\CustomSerializer', TRUE); // sets this as default
$serializer = $db->message->getSerializer(); // returns an instance the CustomSerializer serializer (default)
$serializer = $db->message->getSerializer('application/json'); // returns an instance the JSON serializer

You can add many serializers in this fashion. When gremlin-server responds to your requests, gremlin-client-php will be capable of using the appropriate one to unserialize the message., (*19)

Unit testing

You will then need to run gremlin-server with the following configuration file : src/tests/gremlin-server-php.yaml, (*20)

Just copy this file to <gremlin-server-root-dir>/conf/ And run the server using :, (*21)

bin/gremlin-server.sh conf/gremlin-server-php.yaml

Note that you will not be able to test Transactions without a titan09-SNAPSHOT installation and custom configuration. Start an issue if you need more information., (*22)

The Versions

04/07 2015

dev-master

9999999-dev

gremlin-server client for php

  Sources   Download

The Development Requires

by Brightzone

driver rexpro-php rexpro gremlin gremlin-server

04/07 2015

1.0.0

1.0.0.0

gremlin-server client for php

  Sources   Download

The Development Requires

by Brightzone

driver rexpro-php rexpro gremlin gremlin-server

24/06 2015

1.0.0-beta.1

1.0.0.0-beta1

gremlin-server client for php

  Sources   Download

The Development Requires

by Brightzone

driver rexpro-php rexpro gremlin gremlin-server