Example #1
0
 /**
  * @param string $type
  *
  * @return PhpOrient
  * @throws \Exception
  */
 protected function createClient($type = '')
 {
     $config = static::getConfig($type);
     $client = new PhpOrient();
     $client->configure(array('username' => $config['username'], 'password' => $config['password'], 'hostname' => $config['hostname'], 'port' => $config['port']));
     return $client;
 }
 protected function createDBConnection()
 {
     $client = new PhpOrient();
     $client->configure(['username' => 'root', 'password' => '369', 'hostname' => 'localhost', 'port' => 2424]);
     $client->connect();
     $client->dbOpen('logistics');
     return $client;
 }
Example #3
0
 public function createConnection()
 {
     $client = new PhpOrient();
     $client->configure(['username' => $this->getUsername(), 'password' => $this->getPassword(), 'hostname' => $this->getHostname(), 'port' => $this->getPort()]);
     $client->connect();
     $client->dbOpen($this->getDatabase(), $this->getUsername(), $this->getPassword());
     return $client;
 }
 /**
  *
  */
 public function testLinkSetCreation()
 {
     $config = static::getConfig('connect');
     $client = new PhpOrient('localhost', 2424);
     $client->configure(array('username' => $config['username'], 'password' => $config['password']));
     $client->connect();
     $this->skipTestByOrientDBVersion(['2.1.3', '2.0.13', '1.7.10']);
     try {
         $client->dbDrop('temp', Constants::STORAGE_TYPE_MEMORY);
     } catch (\Exception $e) {
         //            echo $e->getMessage();
         $client->getTransport()->debug($e->getMessage());
     }
     $client->dbCreate('temp', Constants::STORAGE_TYPE_MEMORY, Constants::DATABASE_TYPE_DOCUMENT);
     $client->dbOpen('temp');
     $client->sqlBatch('create class Test1;' . 'create property Test1.aString string;' . 'insert into Test1 (aString) VALUES ("b"),("c"),("d");' . 'create class Test2;' . 'create property Test2.aString string;' . 'create property Test2.anEmbeddedSetOfString embeddedset string;' . 'create property Test2.aLinkedSetOfTest1 linkset Test1;');
     $clusterTest1 = $client->query("select classes[name='Test1'].defaultClusterId from 0:1", -1)[0]['classes'];
     $clusterTest2 = $client->query("select classes[name='Test2'].defaultClusterId from 0:1", -1)[0]['classes'];
     if ($client->getTransport()->getProtocolVersion() < 30) {
         $this->assertEquals('9', $clusterTest1);
         $this->assertEquals('10', $clusterTest2);
     } else {
         $this->assertEquals('11', $clusterTest1);
         $this->assertEquals('12', $clusterTest2);
     }
     $newRecord = ['oClass' => 'Test2', 'oData' => ['aString' => 'Test record', 'anEmbeddedSetOfString' => ['something 1', 'something 2', 'more other'], 'aLinkedSetOfTest1' => [new ID($clusterTest1, 1), new ID($clusterTest1, 2)]]];
     $newRecordObject = Record::fromConfig($newRecord);
     $newRecordObject->setRid(new ID($clusterTest2));
     $tmp = $client->recordCreate($newRecordObject);
     $this->assertInstanceOf('\\PhpOrient\\Protocols\\Binary\\Data\\Record', $tmp);
     /**
      * @var \PhpOrient\Protocols\Binary\Data\Record $record
      */
     $record = $client->recordLoad($tmp->getRid())[0];
     $this->assertEquals('Test record', $record->aString);
     $this->assertArrayHasKey(0, $record->anEmbeddedSetOfString);
     $this->assertArrayHasKey(1, $record->anEmbeddedSetOfString);
     $this->assertArrayHasKey(2, $record->anEmbeddedSetOfString);
     $this->assertEquals('something 1', $record->anEmbeddedSetOfString[0]);
     $this->assertEquals('something 2', $record->anEmbeddedSetOfString[1]);
     $this->assertEquals('more other', $record->anEmbeddedSetOfString[2]);
     $this->assertArrayHasKey(0, $record->aLinkedSetOfTest1);
     $this->assertArrayHasKey(1, $record->aLinkedSetOfTest1);
     $this->assertInstanceOf('\\PhpOrient\\Protocols\\Binary\\Data\\ID', $record->aLinkedSetOfTest1[0]);
     $this->assertInstanceOf('\\PhpOrient\\Protocols\\Binary\\Data\\ID', $record->aLinkedSetOfTest1[1]);
     $aLinkedSetOfTest1 = $record->aLinkedSetOfTest1;
     /**
      * @var \PhpOrient\Protocols\Binary\Data\ID[] $aLinkedSetOfTest1
      */
     if ($client->getTransport()->getProtocolVersion() < 30) {
         $this->assertEquals('#9:1', $aLinkedSetOfTest1[0]->jsonSerialize());
         $this->assertEquals('#9:2', $aLinkedSetOfTest1[1]->__toString());
     } else {
         $this->assertEquals('#11:1', $aLinkedSetOfTest1[0]->jsonSerialize());
         $this->assertEquals('#11:2', $aLinkedSetOfTest1[1]->__toString());
     }
 }
Example #5
0
 public function testRestrictedProperties()
 {
     //        $this->markTestSkipped('Pupù');
     $client = new PhpOrient('localhost', 2424);
     $client->dbOpen("GratefulDeadConcerts", 'admin', 'admin');
     $result = $client->query('SELECT @rid, @class, @version FROM #11:0');
     //        $result = $client->query('select from followed_by limit 1');
     usleep(1000);
 }
Example #6
0
 public function testLoadWithCache()
 {
     $client = new PhpOrient('localhost', 2424);
     $client->dbOpen('GratefulDeadConcerts', 'admin', 'admin');
     $myFunction = function (Record $record) {
         $this->assertInstanceOf('\\PhpOrient\\Protocols\\Binary\\Data\\Record', $record);
     };
     $records = $client->recordLoad(new ID("9", "1"), ['fetch_plan' => '*:3', '_callback' => $myFunction]);
     $this->assertNotEmpty($records);
 }
Example #7
0
 public function skipTestByOrientDBVersion(array $skipVersions)
 {
     $orientVersion = $this->client->getTransport()->getOrientVersion();
     $vString = $orientVersion->getRelease();
     foreach ($skipVersions as $version) {
         if (stripos($vString, $version) !== false) {
             $this->markTestSkipped('Bug sqlBatch on OrientDB version ' . $vString);
         }
     }
 }
Example #8
0
 protected function getClient()
 {
     $client = new PhpOrient();
     $client->hostname = '127.0.0.1';
     $client->port = 2424;
     $client->username = '******';
     $client->password = '******';
     $client->connect();
     $client->dbOpen('Smile', 'root', 'root');
     return $client;
 }
Example #9
0
 public function testSetFetchClass()
 {
     $this->client->setFetchClass('PhpOrient\\TestClassRecord');
     $this->assertEquals('PhpOrient\\TestClassRecord', PhpOrient::getFetchClass());
     $this->client->setFetchClass('PhpOrient\\TestClass');
     $this->assertNull(PhpOrient::getFetchClass());
 }
Example #10
0
 public function testDoubleDeserialization()
 {
     $db_name = 'test_date';
     $client = new PhpOrient('localhost', 2424);
     $client->connect('root', 'root');
     try {
         $client->dbDrop($db_name, Constants::STORAGE_TYPE_MEMORY);
     } catch (\Exception $e) {
         //            echo $e->getMessage();
         $client->getTransport()->debug($e->getMessage());
     }
     $client->dbCreate($db_name, Constants::STORAGE_TYPE_MEMORY, Constants::DATABASE_TYPE_GRAPH);
     $client->dbOpen($db_name, 'admin', 'admin');
     $client->command("create class Test extends V");
     $client->command("create property Test.myDate date");
     $client->command("insert into Test set myDate='2015-01-01'");
     $start = microtime(true);
     $result = $client->query("SELECT FROM Test WHERE myDate <= '2015-10-17'");
     $end = microtime(true);
     $this->assertTrue($end - $start < 1);
     $this->assertNotEmpty($result);
 }
Example #11
0
 public function setUp()
 {
     $this->client = $this->createClient('connect');
     $this->client->connect();
     try {
         $this->client->dbDrop($this->db_name, Constants::STORAGE_TYPE_MEMORY);
     } catch (\Exception $e) {
         //            echo $e->getMessage();
         $this->client->getTransport()->debug($e->getMessage());
     }
     $this->client->dbCreate($this->db_name, Constants::STORAGE_TYPE_MEMORY, Constants::DATABASE_TYPE_GRAPH);
     $this->cluster_struct = $this->client->dbOpen($this->db_name, 'admin', 'admin');
     $this->thisTest = microtime(true);
 }
 /**
  * @inheritdoc
  */
 public function getDatabaseInfo()
 {
     // TODO: Implement getDatabaseInfo() method.
     $res = $this->client->recordLoad(new ID(0, 1));
     $this->clusterMap;
 }
Example #13
0
 public function testWrongClusterID()
 {
     $client = new PhpOrient('localhost', 2424);
     $client->dbOpen('GratefulDeadConcerts', 'admin', 'admin');
     $records = $client->query('select song_type, name from V ');
     /**
      * @var Record[] $records
      */
     foreach ($records as $k => $rec) {
         if ($client->getTransport()->getProtocolVersion() < 26) {
             $this->assertEquals($k + 1, $rec->getRid()->position);
         } else {
             $this->assertEquals($k, $rec->getRid()->position);
         }
         $this->assertEquals(-2, $rec->getRid()->cluster);
     }
 }
 /**
  * Creates the client connection instance.
  * This method is called by [[open]] to establish a DB connection.
  * The default implementation will create a PhpOrient instance.
  * You may override this method if the default client needs to be adapted for certain DBMS.
  * @return client the pdo instance
  */
 public function createClientInstance()
 {
     $client = new PhpOrient();
     $client->configure(['username' => $this->username, 'password' => $this->password, 'hostname' => $this->hostname, 'port' => $this->port]);
     $client->connect();
     $client->dbOpen($this->dbname);
     return $client;
 }
 public function beginTransaction()
 {
     $this->transaction = $this->connection->getTransactionStatement();
     $this->transaction->begin();
 }
Example #16
0
 /**
  * Override the ConfigurableTrait fromConfig method to handle custom classes for records
  *
  * @param array $options
  *
  * @return mixed
  */
 public static function fromConfig(array $options = array())
 {
     // Get the custom fetch class name if available
     $fetchClass = PhpOrient::getFetchClass();
     if ($fetchClass) {
         $object = new $fetchClass();
     } else {
         $object = new self();
     }
     return $object->configure($options);
 }
Example #17
0
 public function testRecordData()
 {
     $db_name = 'test_record_data';
     $client = new PhpOrient('localhost', 2424);
     $client->connect('root', 'root');
     $this->skipTestByOrientDBVersion(['2.0.13', '1.7.10']);
     try {
         $client->dbDrop($db_name, Constants::STORAGE_TYPE_MEMORY);
     } catch (\Exception $e) {
         //            echo $e->getMessage();
         $client->getTransport()->debug($e->getMessage());
     }
     $client->dbCreate($db_name, Constants::STORAGE_TYPE_MEMORY, Constants::DATABASE_TYPE_GRAPH);
     $client->dbOpen($db_name, 'admin', 'admin');
     $client->command("create class Test extends V");
     $client->command("create property Test.id string");
     $client->command("alter property Test.id DEFAULT uuid()");
     $rec = (new Record())->setOData([])->setRid(new ID(11));
     $record = $client->recordCreate($rec);
     $this->assertArrayHasKey('id', $record);
     $this->assertNotEmpty($record['id']);
 }
 public function testWrongTokenWithNoInitialization()
 {
     //        print_r( new \DateTime() );
     $client = new PhpOrient('localhost', 2424);
     $client->setSessionToken(true);
     // set true to enable the token based authentication
     $clusterID = $client->dbOpen("GratefulDeadConcerts", 'admin', 'admin');
     $sessionToken = $client->getSessionToken();
     // store this token somewhere
     file_put_contents("token.bin", $sessionToken);
     unset($client);
     $sessionToken = file_get_contents("token.bin");
     unlink("token.bin");
     // start a new connection
     $client = new PhpOrient('localhost', 2424);
     // set the previous received token to re-attach to the old session
     $client->setSessionToken($sessionToken . "WRONG_TOKEN");
     //        $client->setSessionToken( $sessionToken );
     $this->setExpectedException('\\PhpOrient\\Exceptions\\SocketException');
     //now the dbOpen is not needed to perform database operations
     $client->query('select * from V limit 10');
 }
<?php

use PhpOrient\PhpOrient;
use PhpOrient\Protocols\Binary\Data\ID;
use PhpOrient\Protocols\Binary\Data\Record;
require 'vendor/autoload.php';
$client = new PhpOrient('orientdb3', 2424);
$client->connect('root', 'rootpwd');
if ($client->dbExists('demo')) {
    $client->dbDrop('demo');
}
$client->dbCreate('demo');
$client->dbOpen('demo');
// Create a new collection
$clusterId = $client->command('create class Elements extends V');
// Add new documents
$document1 = new Record();
$document1->setOData(['now' => date('Y-m-d H:i:s')]);
$document1->setRid(new ID($clusterId));
$document2 = new Record();
$document2->setOData(["created" => ['during' => ['VilniusPHP', 'event']]]);
$document2->setRid(new ID($clusterId));
$record1 = $client->recordCreate($document1);
$record2 = $client->recordCreate($document2);
// Read them all
$documents = $client->query('select from Elements');
foreach ($documents as $document) {
    /** @var $document Record */
    echo '<h2>' . $document->getRid() . '</h2>';
    echo "<div><b>Class:</b> {$document->getOClass()}</b>";
    echo "<div><b>Revision:</b> {$document->getVersion()}</b>";
 public function testRecordEmbedded()
 {
     $client = PhpOrient::fromConfig(array('username' => 'root', 'password' => 'root', 'hostname' => 'localhost', 'port' => 2424));
     $res = $client->execute('connect');
     try {
         $client->dbDrop("db_test_embed", Constants::STORAGE_TYPE_MEMORY);
     } catch (\Exception $e) {
         //            echo $e->getMessage();
         $client->getTransport()->debug($e->getMessage());
     }
     $client->dbCreate("db_test_embed", Constants::STORAGE_TYPE_MEMORY, Constants::DATABASE_TYPE_GRAPH);
     $orientInfo = $client->dbOpen("db_test_embed", 'admin', 'admin');
     $client->command("create class Test extends V");
     $client->command("create class TestInfo");
     $client->command("create property Test.attr1 string");
     $client->command("create property Test.attr2 embedded TestInfo");
     $recID = $client->command('insert into Test set attr1 = "test", attr2 = {"@class": "TestInfo", "@type": "d", "subAttr1": "sub test"}');
     $this->assertNotEmpty($recID->getRid());
     $record = $client->recordLoad($recID->getRid())[0];
     $this->assertEquals($recID, $record);
     $updatedRecord = $client->recordUpdate($record);
     $this->assertEquals($record, $updatedRecord);
 }
 public function testWrongProtocol_2()
 {
     $client = new PhpOrient('localhost', 2424);
     $this->setExpectedException('\\PhpOrient\\Exceptions\\PhpOrientWrongProtocolVersionException');
     $client->dbOpen('GratefulDeadConcerts', 'admin', 'admin', ['serializationType' => PhpOrient::SERIALIZATION_SERIAL_BIN]);
 }