2017 © Pedro Peláez
 

library rexpro-php

rexpro client for php

image

brightzone/rexpro-php

rexpro client for php

  • Saturday, September 5, 2015
  • by PommeVerte
  • Repository
  • 1 Watchers
  • 7 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Please note that the current version of TinkerPop (TP) is TP3. You can find a driver for that version here. If you are already running a TP2 project and want a driver for that version then read on.

This is a rexpro client for PHP. It's main purpose was for it to be integrated into frameworks, and therefore it will fail silently and not throw any exceptions. See Error handling section, (*1)

Installation

MsgPack (optional)

rexpro-php does not require MsgPack anymore as it can also serialize using json. If you wish you can still use it though: MsgPack ., (*2)

Install MsgPack from PEAR:, (*3)

sudo pecl install msgpack-beta
sudo sh -c 'echo "extension=msgpack.so" > /etc/php5/mods-available/msgpack.ini'
sudo php5enmod msgpack

PHP Rexster Client

For TP3 and a Gremlin-Server version of this client go here :

https://github.com/PommeVerte/gremlin-php, (*4)

For Rexster 2.4+

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

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

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

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

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

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

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

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

Error Handling

The PHP Client does not throw Exceptions. It was built with the goal of being wrapped into a PHP framework and therefore fails silently (you can still get errors by checking method return values)., (*9)

For instance:, (*10)

if($db->open('localhost:8184','tinkergraph',null,null) === false)
  throw new Exception($db->error->code . ' : ' . $db->error->description);
$db->script = 'g.v(2)';
$result = $db->runScript();
if($result === false)
   throw new Exception($db->error->code . ' : ' . $db->error->description);
//do something with result

Namespace

The Connection class exists within the rexpro namespace. This means that you have to do either of the two following:, (*11)

require_once 'rexpro-php/src/Connection.php';
use \brightzone\rexpro\Connection;

$db = new Connection;

Or, (*12)

require_once 'rexpro-php/src/Connection.php';

$db = new \brightzone\rexpro\Connection;

Serializer

rexpro-php will use the pecl msgpack extention by default. But if it isn't installed on the system it will automatically revert to using JSON., (*13)

If you wish to force a specific serializer type you may do so like this:, (*14)

$db = new Connection;
echo $db->getSerializer(); // will echo 'MSGPACK'
$db->setSerializer(Messages::SERIALIZER_JSON);
echo $db->getSerializer(); // will echo 'JSON'
// do something with $db Connection Object.

Examples

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

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

Example 1:, (*17)

$db = new Connection;
//you can set $db->timeout = 0.5; if you wish
$db->open('localhost:8184','tinkergraph',null,null);
$db->script = 'g.v(2)';
$result = $db->runScript();
//do something with result
$db->close();

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

$db = new Connection;
$db->open('localhost:8184','tinkergraph','username','password');

$db->script = 'g.v(CUSTO_BINDING)';
$db->bindValue('CUSTO_BINDING',2);
$result = $db->runScript();
//do something with result
$db->close();

Example 3 (sessionless):, (*19)

$db = new Connection;
$db->open('localhost:8184');
$db->script = 'g.v(2).map()';
$db->graph = 'tinkergraph'; //need to provide graph
$result = $db->runScript(false);
//do something with result
$b->close();

Example 4 (transaction):, (*20)

$db = new Connection;
$db->open('localhost:8184','neo4jsample',null,null);

$db->transactionStart();

$db->script = 'g.addVertex([name:"michael"])';
$result = $db->runScript();
$db->script = 'g.addVertex([name:"john"])';
$result = $db->runScript();

$db->transactionStop(true);//accept commit of changes. set to false if you wish to cancel changes
$db->close();

Unit testing

If your test rexster server uses credentials for loging in you will need to run the following to set up proper credentials for tests:, (*21)

DBUSER=<username> DBPASS=<password> phpunit src/tests/

Using env variables allows us to pass these arguments to a CI environment if needed., (*22)

The Versions

05/09 2015

dev-master

9999999-dev

rexpro client for php

  Sources   Download

The Development Requires

by Brightzone

rexpro-php rexpro