Exemplo n.º 1
0
 public function __construct()
 {
     $client = ClientBuilder::create()->addDefaultLocalConnection()->build();
     $this->connector = $client;
     $this->loader = new Loader();
     $this->validator = new JSONValidator();
 }
 public function testConversion()
 {
     $gen = new Neogen();
     $p = '(person:Person {firstname:firstName, lastname:lastName} *5)-[:WORKS_AT *n..1]->(company:Company {name:company} *10)
     (actor:Person:Actor {name:fullName, birthdate:{dateTimeBetween:["-50 years","-18 years"]}} *10)-[:WORKS_AT {since:{dateTimeBetween:["-5 years","-1 years"]}} *n..1]->(company)';
     $graph = $gen->generateGraphFromCypher($p);
     $converter = new CypherStatementsConverter();
     $converter->convert($graph);
     $client = ClientBuilder::create()->addDefaultLocalConnection()->build();
     $client->sendCypherQuery('MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE r,n');
     $statements = $converter->getStatements();
     foreach ($statements['constraints'] as $st) {
         $client->sendCypherQuery($st['statement']);
     }
     foreach ($statements['nodes'] as $st) {
         $client->sendCypherQuery($st['statement'], $st['parameters']);
     }
     foreach ($statements['edges'] as $st) {
         if (!isset($st['parameters'])) {
             $parameters = array();
         } else {
             $parameters = $st['parameters'];
         }
         $client->sendCypherQuery($st['statement'], $parameters);
     }
 }
 /**
  * @group formatter
  */
 public function testPreparedTxWithoutNewFormatting()
 {
     $client = ClientBuilder::create()->addConnection('default', 'http', 'localhost', 7474, true, 'neo4j', 'veryCoolMax')->setAutoFormatResponse(true)->build();
     $tx = $client->prepareTransaction();
     $tx->pushQuery('CREATE (a:Test) RETURN a');
     $results = $tx->commit();
     $this->assertInstanceOf('Neoxygen\\NeoClient\\Request\\Response', $results);
 }
 /**
  * @group config
  */
 public function testWithConfigArrayLoading()
 {
     $config = array('connections' => array('default' => array('scheme' => 'http', 'host' => 'localhost', 'port' => 7474, 'auth' => true, 'user' => 'neo4j', 'password' => 'password')), 'ha_mode' => array('type' => 'enterprise', 'enabled' => true, 'master' => 'default'));
     $builder = ClientBuilder::create()->loadConfiguration($config);
     $this->assertArrayHasKey('default', $builder->getConfiguration()['connections']);
     $client = ClientBuilder::create()->loadConfiguration($config)->build();
     $conn = $client->getConnectionManager()->getWriteConnection();
     $this->assertEquals('password', $conn->getAuthPassword());
 }
Exemplo n.º 5
0
 public function client()
 {
     static $client;
     if ($client === NULL) {
         $config = Helpers::config('database');
         $client = ClientBuilder::create()->addConnection('default', 'http', $config['hostname'], $config['port'], TRUE, $config['username'], $config['password'])->setAutoFormatResponse(TRUE)->build();
     }
     return $client;
 }
 public function testAddConnection()
 {
     $client = ClientBuilder::create()->addConnection('default', 'http', 'localhost', 7474, true, '', '4287e44985b04c7536c523ca6ea8e67c')->build();
     $this->assertTrue($client->getConnectionManager()->hasConnection('default'));
     $this->assertInstanceOf('Neoxygen\\NeoClient\\Connection\\Connection', $client->getConnection('default'));
     $conn = $client->getConnection('default');
     $this->assertEquals('http', $conn->getScheme());
     $this->assertEquals('localhost', $conn->getHost());
     $this->assertEquals(7474, $conn->getPort());
 }
 /**
  * @group issue-property
  */
 public function testPropertyWithZeroValueIsFormattedCorrectly()
 {
     $client = ClientBuilder::create()->addConnection('default', 'http', 'localhost', 7474, true, 'neo4j', 'veryCoolMax')->setAutoFormatResponse(true)->build();
     $client->sendCypherQuery('MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE r,n');
     $insert = 'CREATE (n:Node {count: 0})';
     $client->sendCypherQuery($insert);
     $q = 'MATCH (n:Node) RETURN n';
     $result = $client->sendCypherQuery($q)->getResult();
     $v = $result->get('n')->getProperty('count');
     $this->assertTrue(0 === $v);
     $this->assertTrue(null === $result->get('n')->getProperty('unk', null));
     $this->setExpectedException('InvalidArgumentException');
     $result->get('n')->getProperty('unk');
 }
Exemplo n.º 8
0
$start = microtime(true);
$statements = [];
for ($i = 0; $i < 1000; $i++) {
    $q = 'CREATE (n {tx_id:{id}})';
    $p = ['id' => $i];
    $st = ['statement' => $q, 'parameters' => $p];
    $statements[] = $st;
}
$client->sendMultiple($statements);
$end = microtime(true);
$usage = convert(memory_get_peak_usage(true));
$diff = $end - $start;
$output .= sprintf('Runned in %s seconds, using %s memory', $diff, $usage) . PHP_EOL;
$output .= '--------------------------' . PHP_EOL;
$client = null;
$i = null;
$p = null;
$q = null;
// ----- Handling big graph response format
$output .= 'Handling big graph Response format, 1000 nodes with more edges' . PHP_EOL;
$client = ClientBuilder::create()->addConnection('default', 'http', 'localhost', 7474, true, 'neo4j', 'veryCoolMax')->setAutoFormatResponse(true)->build();
$client->sendCypherQuery('MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE r,n');
$start = microtime(true);
$q = 'MATCH (n) OPTIONAL MATCH (n)-[r]-() RETURN r,n LIMIT 1000';
$r = $client->sendCypherQuery($q)->getResult();
$end = microtime(true);
$usage = convert(memory_get_peak_usage(true));
$diff = $end - $start;
$output .= sprintf('Runned in %s seconds, using %s memory', $diff, $usage) . PHP_EOL;
$output .= '--------------------------' . PHP_EOL;
file_put_contents($outputfile, $output);
Exemplo n.º 9
0
<?php

use Silex\Application;
use Symfony\Component\HttpFoundation\Request, Symfony\Component\HttpFoundation\JsonResponse;
use Neoxygen\NeoClient\ClientBuilder;
require __DIR__ . '/vendor/autoload.php';
$app = new Application();
$settings = ['scheme' => 'http', 'host' => 'localhost', 'port' => 7474, 'auth' => false, 'user' => null, 'pass' => null];
if (getenv('GRAPHSTORY_URL') !== false) {
    $settings = array_merge($settings, parse_url(getenv('GRAPHSTORY_URL')));
    $settings['auth'] = true;
}
$neo4j = ClientBuilder::create()->addConnection('default', $settings['scheme'], $settings['host'], $settings['port'], $settings['auth'], $settings['user'], $settings['pass'])->setAutoFormatResponse(true)->setDefaultTimeout(25)->build();
$app->get('/', function () {
    return file_get_contents(__DIR__ . '/static/index.html');
});
$app->get('/graph', function (Request $request) use($neo4j) {
    $limit = $request->get('limit', 50);
    $params = ['limit' => $limit];
    $q = 'MATCH (m:Movie)<-[r:ACTED_IN]-(p:Person) RETURN m,r,p LIMIT {limit}';
    $result = $neo4j->sendCypherQuery($q, $params)->getResult();
    $nodes = [];
    $edges = [];
    $nodesPositions = [];
    $i = 0;
    foreach ($result->getNodes() as $node) {
        $prop = $node->getLabel() === 'Movie' ? 'title' : 'name';
        $nodes[] = ['title' => $node->getProperty($prop), 'label' => $node->getLabel()];
        $nodesPositions[$node->getId()] = $i;
        $i++;
    }
Exemplo n.º 10
0
 private static function buildConnection()
 {
     return ClientBuilder::create()->addConnection('default', Config::get('database.neo4j.profiles.default.scheme'), Config::get('database.neo4j.profiles.default.host'), (int) Config::get('database.neo4j.profiles.default.port'), true, Config::get('database.neo4j.profiles.default.username'), Config::get('database.neo4j.profiles.default.password'))->setAutoFormatResponse(true)->build();
 }
Exemplo n.º 11
0
session_start();
if (!isset($_SESSION['username'])) {
    header("Location: logreg.php");
    exit;
}
$_SESSION['flag'] = "0";
$_SESSION['picpath'] = "images/profile_pics/{$_SESSION['userid']}.jpg";
if (!file_exists($_SESSION['picpath'])) {
    $_SESSION['picpath'] = "images/profile_pics/default_profile.jpg";
}
require_once 'vendor/autoload.php';
use Neoxygen\NeoClient\ClientBuilder;
$usr = "******";
$pwd = "root";
$client = ClientBuilder::create()->addConnection('default', 'http', 'localhost', 7474, true, $usr, $pwd)->setAutoFormatResponse(true)->build();
$query = "Match (u:User)-[r]->(t:Type) Where u.email = {userid} Return *";
$parameters = ['userid' => $_SESSION['userid']];
$result = $client->sendCypherQuery($query, $parameters)->getRows();
$op = json_encode($result);
$data = json_decode($op);
if ($data == null) {
    $query = "Match (u:User) Where u.email = {userid} Return *";
    $parameters = ['userid' => $_SESSION['userid']];
    $result = $client->sendCypherQuery($query, $parameters)->getRows();
    $op = json_encode($result);
    $data = json_decode($op);
}
$fname = $data->u[0]->fname;
$lname = $data->u[0]->lname;
$userid = $data->u[0]->email;
 /**
  * Creates a connection to the database with the provided settings.
  *
  * @param $host
  * @param $port
  * @param null $user
  * @param null $password
  * @param bool $https
  *
  * @return \Neoxygen\NeoClient\Client
  */
 public function createConnection($host, $port, $user = null, $password = null, $https = false)
 {
     $scheme = false !== $https ? 'https' : 'http';
     $client = ClientBuilder::create()->addConnection('default', $scheme, $host, (int) $port, true, $user, $password)->setDefaultTimeout(10)->setAutoFormatResponse(true)->build();
     return $client;
 }
Exemplo n.º 13
0
 public function __construct()
 {
     $this->connection = ClientBuilder::create()->addConnection('default', 'http', 'ec2-54-94-173-25.sa-east-1.compute.amazonaws.com', 7474, true, 'neo4j', '123456')->setAutoFormatResponse(true)->build();
 }
 public function setUp()
 {
     $this->client = ClientBuilder::create()->addConnection('default', 'http', 'localhost', 7474, true, 'neo4j', 'veryCoolMax')->setAutoFormatResponse(true)->build();
     // empty db
     $this->client->sendCypherQuery('MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE r,n');
 }
Exemplo n.º 15
0
 /**
  * Create a new command instance.
  *
  */
 public function __construct()
 {
     parent::__construct();
     $this->neo4j = ClientBuilder::create()->addConnection('default', Config::get('database.neo4j.profiles.default.scheme'), Config::get('database.neo4j.profiles.default.host'), (int) Config::get('database.neo4j.profiles.default.port'), true, Config::get('database.neo4j.profiles.default.username'), Config::get('database.neo4j.profiles.default.password'))->setAutoFormatResponse(true)->build();
 }
Exemplo n.º 16
0
 private function getDBConnection($dbConnection)
 {
     $defaults = ['scheme' => 'http', 'host' => 'localhost', 'port' => 7474];
     $conn = array_merge($defaults, parse_url($dbConnection));
     if (!array_key_exists('scheme', $conn) || !array_key_exists('host', $conn) || !array_key_exists('port', $conn)) {
         throw new InvalidArgumentException('The connection settings does not seem to be correct');
     }
     $client = ClientBuilder::create()->addConnection('default', $conn['scheme'], $conn['host'], $conn['port'])->build();
     return $client;
 }
Exemplo n.º 17
0
use Pson\Db;
use Pson\DbException;
use Pson\DbConstraintViolation;
use Pson\ValidationException;
$app = new App();
$app['debug'] = true;
// Configure database
$app['db'] = $app->share(function () {
    $host = getenv("PSON_DB_HOST");
    $port = intval(getenv("PSON_DB_PORT"));
    $user = getenv("PSON_DB_USER");
    $pass = getenv("PSON_DB_PASS");
    if ($host === FALSE || $port === FALSE || $user === FALSE || $pass === FALSE) {
        throw new Exception("Database is not configured");
    }
    $client = ClientBuilder::create()->addConnection('default', 'http', $host, $port, true, $user, $pass)->build();
    return new Db($client);
});
// configure logging
$app->register(new Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => __DIR__ . '/logs/app.log', 'monolog.name' => 'Pson'));
// register default error handler
$app->error(function (\Exception $e) {
    if ($e instanceof DbConstraintViolation) {
        $message = "Input data violates DB constaints";
        $code = 409;
    } elseif ($e instanceof DbException) {
        $message = "Problems with database";
        $code = 500;
    } elseif ($e instanceof ValidationException) {
        $message = $e->getMessage();
        $code = 409;
 private function connectDatabase($db_name, $protocol, $host_name, $port, $username, $password)
 {
     $this->connector = ClientBuilder::create()->addConnection($db_name, $protocol, $host_name, $port, true, $username, $password)->setAutoFormatResponse(true)->setDefaultTimeout(20000)->build();
 }
Exemplo n.º 19
0
};
// -----------------------------------------------------------------------------
// Service factories
// -----------------------------------------------------------------------------
// monolog
$container['logger'] = function ($c) {
    $settings = $c->get('settings');
    $logger = new \Monolog\Logger($settings['logger']['name']);
    $logger->pushProcessor(new \Monolog\Processor\UidProcessor());
    $logger->pushHandler(new \Monolog\Handler\StreamHandler($settings['logger']['path'], \Monolog\Logger::DEBUG));
    return $logger;
};
// neoClient
$container['neoClient'] = function ($c) {
    $settings = $c->get('settings');
    $client = \Neoxygen\NeoClient\ClientBuilder::create()->addConnection($settings['neo4j']['alias'], $settings['neo4j']['protocol'], $settings['neo4j']['host'], $settings['neo4j']['port'], $settings['neo4j']['authmode'], $settings['neo4j']['username'], $settings['neo4j']['password'])->setDefaultTimeout($settings['neo4j']['timeout'])->setLogger('neoClient', $c->get('logger'))->setAutoFormatResponse(true)->build();
    return $client;
};
// postService
$container['postService'] = function ($c) {
    $authorRepo = new \GraphBlog\Repository\AuthorRepository();
    $categoryRepo = new \GraphBlog\Repository\CategoryRepository();
    $postRepo = new \GraphBlog\Repository\PostRepository($c->get('neoClient'), $c->get('logger'));
    $tagRepo = new \GraphBlog\Repository\TagRepository();
    $postService = new \GraphBlog\Service\PostService($postRepo, $authorRepo, $categoryRepo, $tagRepo, $c->get('logger'));
    return $postService;
};
// -----------------------------------------------------------------------------
// Action factories
// -----------------------------------------------------------------------------
$container['GraphBlog\\Action\\HomeAction'] = function ($c) {
Exemplo n.º 20
0
<?php

require_once $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';
use Neoxygen\NeoClient\ClientBuilder;
$neoUser = "******";
$neoPass = "******";
$neoClient = ClientBuilder::create()->addConnection('default', 'http', 'turtleboys.com', 7474, true, $neoUser, $neoPass)->setAutoFormatResponse(true)->build();
Exemplo n.º 21
0
<?php

require_once __DIR__ . '/bootstrap.php';
use Neoxygen\NeoClient\ClientBuilder;
$app = new Silex\Application();
$app->register(new Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => __DIR__ . '/../logs/graph.log'));
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app->register(new Igorw\Silex\ConfigServiceProvider(__DIR__ . "/../config/" . ENV . ".json"));
$app['neo'] = $app->share(function () use($app) {
    $client = ClientBuilder::create()->addConnection($app['db']['alias'], $app['db']['schema'], $app['db']['host'], $app['db']['port'])->setAutoFormatResponse(true)->build();
    return $client;
});
require_once __DIR__ . '/../config/routes/all.php';
return $app;
Exemplo n.º 22
0
use Neoxygen\NeoClient\ClientBuilder;
$skipSchemaSetup = false;
$dropDbOnInit = false;
if (!isset($argv[1]) || empty($argv[1])) {
    throw new \InvalidArgumentException('You need to pass the event ID as argument : php import.php 12345678');
}
if (isset($argv[2]) && true == (bool) $argv[2]) {
    $skipSchemaSetup = true;
}
if (isset($argv[3]) && (bool) $argv[3] == true) {
    $dropDbOnInit = true;
}
$eventId = (int) $argv[1];
$config = YAML::parse(file_get_contents(__DIR__ . '/config.yml'));
$meetupClient = MeetupKeyAuthClient::factory(array('key' => $config['meetup_api_key']));
$neoClient = ClientBuilder::create()->addConnection('default', $config['neo4j_scheme'], $config['neo4j_host'], $config['neo4j_port'], true, $config['neo4j_user'], $config['neo4j_password'])->setAutoFormatResponse(true)->build();
// Creating Schema Indexes And Constraints
if (!$skipSchemaSetup) {
    $neoClient->createUniqueConstraint('Event', 'id');
    $neoClient->createUniqueConstraint('Member', 'id');
    $neoClient->createUniqueConstraint('Topic', 'id');
    $neoClient->createUniqueConstraint('Country', 'code');
    $neoClient->createIndex('City', 'name');
    echo 'Schema created' . "\n";
} else {
    echo 'Skipping Schema Creation' . "\n";
}
if ($dropDbOnInit) {
    echo 'Dropping DB' . "\n";
    $neoClient->sendCypherQuery('MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE r,n');
}
Exemplo n.º 23
0
 public function setUp()
 {
     $client = ClientBuilder::create()->addConnection('default', 'http', 'localhost', 7474, true, 'neo4j', 'veryCoolMax')->setAutoFormatResponse(true)->setDefaultTimeout(15)->build();
     $this->client = $client;
 }
Exemplo n.º 24
0
 protected function getClient()
 {
     return ClientBuilder::create()->addConnection('default', 'http', 'localhost', 7474, true, 'neo4j', 'veryCoolMax')->setAutoFormatResponse(true)->build();
 }
 public function getNodeCommunityProfile($id)
 {
     putenv("TMPDIR=/seniortmp");
     $client = ClientBuilder::create()->addConnection('default', 'http', 'localhost', 7474, true, 'neo4j', 'aiscu')->setAutoFormatResponse(true)->build();
     $selectedProfile = Input::get('sendprofile');
     $query = "WHERE ";
     foreach ($selectedProfile as $key => $value) {
         $query = $query . " n." . $key . " IN " . (string) $value . " AND ";
     }
     $query = substr($query, 0, strlen($query) - 5);
     $q = 'MATCH (n:ProcessedCom' . $id . ') ' . (string) $query . ' RETURN n.communityID';
     $results = $client->sendCypherQuery($q)->getResult()->getTableFormat();
     $communities_list = array();
     foreach ($results as $key => $result) {
         array_push($communities_list, $result['n.communityID']);
     }
     return response()->json($communities_list);
 }
 public function testHAMode()
 {
     $builder = ClientBuilder::create()->addConnection('default', 'http', 'localhost', 7474, true, 'neo4j', 'neo4j')->enableHAMode();
     $this->assertEquals(true, $builder->getConfiguration()['ha_mode']['enabled']);
     $this->assertEquals('enterprise', $builder->getConfiguration()['ha_mode']['type']);
 }
 public function getConnection()
 {
     return ClientBuilder::create()->addConnection('default', 'http', 'localhost', 7474, true, 'neo4j', 'veryCoolMax')->setAutoFormatResponse(true)->enableNewFormattingService()->build();
 }
Exemplo n.º 28
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use Neoxygen\NeoClient\ClientBuilder;
$app = new Silex\Application();
$app['neo'] = $app->share(function () {
    $client = ClientBuilder::create()->addDefaultLocalConnection()->setAutoFormatResponse(true)->build();
    return $client;
});
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../src/views'));
$app->register(new Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => __DIR__ . '/../logs/social.log'));
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app->get('/', 'Ikwattro\\SocialNetwork\\Controller\\WebController::home')->bind('home');
$app->get('/user/{login}', 'Ikwattro\\SocialNetwork\\Controller\\WebController::showUser')->bind('show_user');
$app->post('/relationship/create', 'Ikwattro\\SocialNetwork\\Controller\\WebController::createRelationship')->bind('relationship_create');
$app->post('/relationship/remove', 'Ikwattro\\SocialNetwork\\Controller\\WebController::removeRelationship')->bind('relationship_remove');
$app->run();
 /**
  * @group legacy
  */
 public function tesLegacyUniqueConstraintsWithNewFormattingService()
 {
     $client = ClientBuilder::create()->addConnection('default', 'http', 'localhost', 7474, true, 'neo4j', 'veryCoolMax')->setAutoFormatResponse(true)->enableNewFormattingService()->build();
     $constraints = $client->getUniqueConstraints();
     $this->assertArrayHasKey('User', $constraints->getBody());
 }
Exemplo n.º 30
0
 public function getClient()
 {
     if (null === $this->client) {
         $client = ClientBuilder::create()->addDefaultLocalConnection()->setAutoFormatResponse(true)->build();
         $this->client = $client;
     }
     return $this->client;
 }