From b3768a12bb33b46b3fce22bf77cc99c2a99e6397 Mon Sep 17 00:00:00 2001 From: jsteemann Date: Thu, 6 Nov 2014 15:53:47 +0100 Subject: [PATCH 01/19] updated README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 32bb75a7..3b6870e6 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # ArangoDB-PHP - A PHP client for ArangoDB [![Build Status](https://travis-ci.org/triAGENS/ArangoDB-PHP.png?branch=master)](https://travis-ci.org/triAGENS/ArangoDB-PHP) -**Branch: Master (v2.0.0)** +**Branch: Master (v2.2.0)** [![Build Status](https://travis-ci.org/triAGENS/ArangoDB-PHP.png?branch=devel)](https://travis-ci.org/triAGENS/ArangoDB-PHP) **Branch: devel** From d47296b7ce24de0d34bac49a2a043257554b9718 Mon Sep 17 00:00:00 2001 From: jsteemann Date: Thu, 6 Nov 2014 16:05:24 +0100 Subject: [PATCH 02/19] ignore certificate --- tests/travis/setup_arangodb.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/travis/setup_arangodb.sh b/tests/travis/setup_arangodb.sh index 73d8292b..ad0f6c1b 100644 --- a/tests/travis/setup_arangodb.sh +++ b/tests/travis/setup_arangodb.sh @@ -8,8 +8,8 @@ NAME=ArangoDB-$VERSION if [ ! -d "$DIR/$NAME" ]; then # download ArangoDB - echo "wget http://www.arangodb.com/repositories/travisCI/$NAME.tar.gz" - wget http://www.arangodb.com/repositories/travisCI/$NAME.tar.gz + echo "wget --no-check-certificate http://www.arangodb.com/repositories/travisCI/$NAME.tar.gz" + wget --no-check-certificate http://www.arangodb.com/repositories/travisCI/$NAME.tar.gz echo "tar zxf $NAME.tar.gz" tar zvxf $NAME.tar.gz fi From 4d9ed20aebda7ddecedafec7c19ef14989d1fe90 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Mon, 10 Nov 2014 11:53:14 +0100 Subject: [PATCH 03/19] Make samples work cut'n'pasteable --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3b6870e6..311d2bce 100644 --- a/README.md +++ b/README.md @@ -269,11 +269,11 @@ So, after we get the settings, we can start with creating a collection. We will The below code will first set up the collection locally in a variable name $user, and then push it to the server and return the collection id created by the server: ```php -$collectionHandler = new CollectionHandler($connection); +$collectionHandler = new triagens\ArangoDb\CollectionHandler($connection); // create a new document -$userCollection = new ArangoCollection(); -$userCollection->setName('user'); +$userCollection = new triagens\ArangoDb\Collection(); +$userCollection->setName('users'); $id = $collectionHandler->add($userCollection); // print the collection id created by the server From 751c768be04f7158904ba10d93fc01cc106ef80f Mon Sep 17 00:00:00 2001 From: jsteemann Date: Mon, 10 Nov 2014 20:33:33 +0100 Subject: [PATCH 04/19] fixed examples --- README.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 311d2bce..c59ccf87 100644 --- a/README.md +++ b/README.md @@ -206,6 +206,8 @@ In order to use ArangoDB, you need to specify the connection options. We do so b require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'ArangoDB-PHP' . DIRECTORY_SEPARATOR . 'autoload.php'; // set up some aliases for less typing later +use triagens\ArangoDb\Collection as ArangoCollection; +use triagens\ArangoDb\CollectionHandler as ArangoCollectionHandler; use triagens\ArangoDb\Connection as ArangoConnection; use triagens\ArangoDb\ConnectionOptions as ArangoConnectionOptions; use triagens\ArangoDb\DocumentHandler as ArangoDocumentHandler; @@ -269,10 +271,10 @@ So, after we get the settings, we can start with creating a collection. We will The below code will first set up the collection locally in a variable name $user, and then push it to the server and return the collection id created by the server: ```php -$collectionHandler = new triagens\ArangoDb\CollectionHandler($connection); +$collectionHandler = new ArangoCollectionHandler($connection); // create a new document -$userCollection = new triagens\ArangoDb\Collection(); +$userCollection = new ArangoCollection(); $userCollection->setName('users'); $id = $collectionHandler->add($userCollection); @@ -470,11 +472,14 @@ Here's the full code that combines all the pieces outlined above: ```php // use the following line when using packagist/composer -//require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . '.composer' . DIRECTORY_SEPARATOR . 'autoload.php'; +// require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . '.composer' . DIRECTORY_SEPARATOR . 'autoload.php'; + // use the following line when using git require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'ArangoDB-PHP' . DIRECTORY_SEPARATOR . 'autoload.php'; // set up some aliases for less typing later +use triagens\ArangoDb\Collection as ArangoCollection; +use triagens\ArangoDb\CollectionHandler as ArangoCollectionHandler; use triagens\ArangoDb\Connection as ArangoConnection; use triagens\ArangoDb\ConnectionOptions as ArangoConnectionOptions; use triagens\ArangoDb\DocumentHandler as ArangoDocumentHandler; @@ -487,6 +492,7 @@ use triagens\ArangoDb\UpdatePolicy as ArangoUpdatePolicy; // set up some basic connection options $connectionOptions = array( + // server endpoint to connect to ArangoConnectionOptions::OPTION_ENDPOINT => 'tcp://127.0.0.1:8529', // authorization type to use (currently supported: 'Basic') ArangoConnectionOptions::OPTION_AUTH_TYPE => 'Basic', @@ -508,18 +514,18 @@ try { $connection = new ArangoConnection($connectionOptions); - $collectionHandler = new CollectionHandler($connection); + $collectionHandler = new ArangoCollectionHandler($connection); // create a new collection $userCollection = new ArangoCollection(); - $userCollection->setName('user'); + $userCollection->setName('users'); $id = $collectionHandler->add($userCollection); // print the collection id created by the server var_dump($id); // check if the collection exists - $result = $collectionHandler->has('user'); + $result = $collectionHandler->has('users'); var_dump($result); $handler = new ArangoDocumentHandler($connection); From 5589c977032860e19b0dd094374d945ad99d6234 Mon Sep 17 00:00:00 2001 From: jsteemann Date: Mon, 10 Nov 2014 20:36:35 +0100 Subject: [PATCH 05/19] fixed examples --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c59ccf87..3d26d772 100644 --- a/README.md +++ b/README.md @@ -461,7 +461,7 @@ To delete an existing collection on the server, use the drop() method of the Col ```php // delete a collection on the server, using it's name, -$result = $handler->drop('users'); +$result = $collectionHandler->drop('users'); var_dump($result); ``` @@ -580,7 +580,7 @@ try { // delete a collection on the server, using it's name, - $result = $handler->drop('users'); + $result = $collectionHandler->drop('users'); var_dump($result); } catch (ArangoConnectException $e) { From 8c9e64693b3c2b38967b5d4313305a5d2632f0a4 Mon Sep 17 00:00:00 2001 From: jsteemann Date: Wed, 12 Nov 2014 12:27:02 +0100 Subject: [PATCH 06/19] updated examples --- examples/document.php | 18 +++++-- examples/edge.php | 77 ++++++++++++++++++++++++++++ examples/graph.php | 13 ++++- lib/triagens/ArangoDb/Collection.php | 7 ++- 4 files changed, 108 insertions(+), 7 deletions(-) create mode 100644 examples/edge.php diff --git a/examples/document.php b/examples/document.php index fc434a1e..fd9c9b05 100644 --- a/examples/document.php +++ b/examples/document.php @@ -6,15 +6,25 @@ try { - $connection = new Connection($connectionOptions); - $handler = new DocumentHandler($connection); + $connection = new Connection($connectionOptions); + $collectionHandler = new CollectionHandler($connection); + $handler = new DocumentHandler($connection); + + // set up a document collection "users" + $collection = new Collection("users"); + try { + $collectionHandler->add($collection); + } + catch (\Exception $e) { + // collection may already exist - ignore this error for now + } // create a new document $user = new Document(); $user->set("name", "John"); $user->age = 19; - $id = $handler->add("users", $user); + $id = $handler->save("users", $user); // get documents by example $cursor = $handler->getByExample("users", array("name" => "John", "age" => 19)); @@ -30,7 +40,7 @@ $user->level = 1; $user->vists = array(1, 2, 3); - $id = $handler->add("users", $user); + $id = $handler->save("users", $user); var_dump("CREATED A NEW DOCUMENT WITH ID: ", $id); // get this document from the server diff --git a/examples/edge.php b/examples/edge.php new file mode 100644 index 00000000..60dd3038 --- /dev/null +++ b/examples/edge.php @@ -0,0 +1,77 @@ +add($collection); + } + catch (\Exception $e) { + // collection may already exist - ignore this error for now + } + + $collection = new Collection("departments"); + try { + $collectionHandler->add($collection); + } + catch (\Exception $e) { + // collection may already exist - ignore this error for now + } + + // set up an edge collection to link the two previous collections + $collection = new Collection("worksFor"); + $collection->setType(3); + + try { + $collectionHandler->add($collection); + } + catch (\Exception $e) { + // collection may already exist - ignore this error for now + } + + // create a new department + $marketing = Document::createFromArray(array("name" => "Marketing")); + $documentHandler->save("departments", $marketing); + + // create another department + $finance = Document::createFromArray(array("name" => "Finance")); + $documentHandler->save("departments", $finance); + + // create a new employee + $john = Document::createFromArray(array("name" => "John")); + $documentHandler->save("employees", $john); + + // create another employee + $jane = Document::createFromArray(array("name" => "Jane")); + $documentHandler->save("employees", $jane); + + // now insert a link between Marketing and Jane + $worksFor = Edge::createFromArray(array("startDate" => "2009-06-23", "endDate" => "2014-11-12")); + $edgeHandler->saveEdge("worksFor", $marketing->getHandle(), $jane->getHandle(), $worksFor); + + // now insert a link between Finance and Jane + $worksFor = Edge::createFromArray(array("startDate" => "2014-11-12")); + $edgeHandler->saveEdge("worksFor", $finance->getHandle(), $jane->getHandle(), $worksFor); + + // now insert a link between Finance and John + $worksFor = Edge::createFromArray(array("startDate" => "2012-04-01")); + $edgeHandler->saveEdge("worksFor", $finance->getHandle(), $john->getHandle(), $worksFor); + + +} catch (ConnectException $e) { + print $e . PHP_EOL; +} catch (ServerException $e) { + print $e . PHP_EOL; +} catch (ClientException $e) { + print $e . PHP_EOL; +} diff --git a/examples/graph.php b/examples/graph.php index 78197f60..1f2d65bf 100644 --- a/examples/graph.php +++ b/examples/graph.php @@ -13,6 +13,14 @@ $graph->set('_key', 'Graph'); $graph->setVerticesCollection('VertexCollection'); $graph->setEdgesCollection('EdgeCollection'); + + try { + $graphHandler->dropGraph($graph); + } + catch (\Exception $e) { + // graph may not yet exist. ignore this error for now + } + $graphHandler->createGraph($graph); // Define some arrays to build the content of the vertices and edges @@ -46,7 +54,7 @@ var_dump($graphHandler->hasVertex('Graph', 'vertex1')); // Save the connecting edge - $saveEdgeResult1 = $graphHandler->saveEdge('Graph', 'vertex1', 'vertex2', 'somelabelValue', $edge1); + $saveEdgeResult1 = $graphHandler->saveEdge('Graph', $vertex1->getHandle(), $vertex2->getHandle(), 'somelabelValue', $edge1); // check if edge exists var_dump($graphHandler->hasEdge('Graph', 'edge1')); @@ -57,7 +65,8 @@ // Remove vertices and edges $result1 = $graphHandler->removeVertex('Graph', 'vertex1'); $result1 = $graphHandler->removeVertex('Graph', 'vertex2'); - $result1 = $graphHandler->removeEdge('Graph', 'edge1'); + + // the connecting edge will be deleted automatically } catch (ConnectException $e) { print $e . PHP_EOL; } catch (ServerException $e) { diff --git a/lib/triagens/ArangoDb/Collection.php b/lib/triagens/ArangoDb/Collection.php index f3b1ad50..cd869b02 100644 --- a/lib/triagens/ArangoDb/Collection.php +++ b/lib/triagens/ArangoDb/Collection.php @@ -195,10 +195,15 @@ class Collection /** * Constructs an empty collection * + * @param string $name - name for the collection + * * @return Collection */ - public function __construct() + public function __construct($name = null) { + if ($name !== null) { + $this->setName($name); + } } /** From 8142a33dfe376c2f84629adce7db26f8229ed059 Mon Sep 17 00:00:00 2001 From: jsteemann Date: Thu, 13 Nov 2014 09:32:05 +0100 Subject: [PATCH 07/19] issue #173 --- examples/document.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/document.php b/examples/document.php index fd9c9b05..d2eda311 100644 --- a/examples/document.php +++ b/examples/document.php @@ -27,7 +27,7 @@ $id = $handler->save("users", $user); // get documents by example - $cursor = $handler->getByExample("users", array("name" => "John", "age" => 19)); + $cursor = $collectionHandler->byExample("users", array("name" => "John", "age" => 19)); var_dump($cursor->getAll()); // get the ids of all documents in the collection From b8bd9348ec0925cb927fc0a95fa97ddd6bab23ba Mon Sep 17 00:00:00 2001 From: jsteemann Date: Tue, 18 Nov 2014 11:19:41 +0100 Subject: [PATCH 08/19] make test repeatable --- tests/DatabaseTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/DatabaseTest.php b/tests/DatabaseTest.php index 6127f5c3..e45705fe 100644 --- a/tests/DatabaseTest.php +++ b/tests/DatabaseTest.php @@ -42,6 +42,13 @@ public function testCreateDatabaseDeleteIt() { $database = 'ArangoTestSuiteDatabaseTest01'; + + try { + $e = null; + Database::delete($this->connection, $database); + } catch (\Exception $e) { + // don't bother us... just give us the $e + } $response = Database::create($this->connection, $database); @@ -162,6 +169,13 @@ public function testCreateDatabaseSwitchToItAndCreateAnotherOne() $database = 'ArangoTestSuiteDatabaseTest01'; $database2 = 'ArangoTestSuiteDatabaseTest02'; + + try { + $e = null; + Database::delete($this->connection, $database); + } catch (\Exception $e) { + // don't bother us... + } $response = Database::create($this->connection, $database); From 3576ff605b33b8877efcc4c98d67d59c968b968a Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Wed, 7 Jan 2015 09:15:04 +0100 Subject: [PATCH 09/19] updated version in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3d26d772..bf32d256 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # ArangoDB-PHP - A PHP client for ArangoDB [![Build Status](https://travis-ci.org/triAGENS/ArangoDB-PHP.png?branch=master)](https://travis-ci.org/triAGENS/ArangoDB-PHP) -**Branch: Master (v2.2.0)** +**Branch: Master (v2.3)** [![Build Status](https://travis-ci.org/triAGENS/ArangoDB-PHP.png?branch=devel)](https://travis-ci.org/triAGENS/ArangoDB-PHP) **Branch: devel** From 74d4ae39d2e3d6a467564dc39c1a5d7f90d4cf08 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Wed, 7 Jan 2015 09:24:26 +0100 Subject: [PATCH 10/19] updated version number --- tests/travis/setup_arangodb.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/travis/setup_arangodb.sh b/tests/travis/setup_arangodb.sh index ad0f6c1b..187da027 100644 --- a/tests/travis/setup_arangodb.sh +++ b/tests/travis/setup_arangodb.sh @@ -3,7 +3,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd $DIR -VERSION=2.2.6 +VERSION=2.3.4 NAME=ArangoDB-$VERSION if [ ! -d "$DIR/$NAME" ]; then From 7ddd919c10a47d25c84cad1a3e8b3d5de3ae35ad Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Wed, 7 Jan 2015 09:25:00 +0100 Subject: [PATCH 11/19] updated version --- tests/travis/setup_arangodb.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/travis/setup_arangodb.sh b/tests/travis/setup_arangodb.sh index ad0f6c1b..187da027 100644 --- a/tests/travis/setup_arangodb.sh +++ b/tests/travis/setup_arangodb.sh @@ -3,7 +3,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd $DIR -VERSION=2.2.6 +VERSION=2.3.4 NAME=ArangoDB-$VERSION if [ ! -d "$DIR/$NAME" ]; then From 91da0ce823354ada231ee1ff32aabc57fee5a8f3 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Tue, 13 Jan 2015 17:52:16 +0100 Subject: [PATCH 12/19] issue #176: bug; Invalid bind parameter value on "file" value --- lib/triagens/ArangoDb/ValueValidator.php | 9 +++-- tests/StatementTest.php | 49 ++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/lib/triagens/ArangoDb/ValueValidator.php b/lib/triagens/ArangoDb/ValueValidator.php index ae9f39af..f7ef8aa0 100644 --- a/lib/triagens/ArangoDb/ValueValidator.php +++ b/lib/triagens/ArangoDb/ValueValidator.php @@ -33,6 +33,11 @@ class ValueValidator */ public static function validate($value) { + if (is_string($value) || is_int($value) || is_double($value) || is_bool($value) || is_null($value)) { + // type is allowed + return; + } + if (is_array($value)) { // must check all elements contained foreach ($value as $subValue) { @@ -41,10 +46,6 @@ public static function validate($value) return; } - else if (! is_object($value) && ! is_resource($value) && ! is_callable($value)) { - // type is allowed - return; - } // type is invalid throw new ClientException('Invalid bind parameter value'); diff --git a/tests/StatementTest.php b/tests/StatementTest.php index c90d7027..5270ed07 100644 --- a/tests/StatementTest.php +++ b/tests/StatementTest.php @@ -242,6 +242,55 @@ public function testStatementWithFullCount() $this->assertEquals(3, $cursor->getFullCount(), "The fullCount should be 3"); } + + public function testBindReservedValue() + { + $connection = $this->connection; + $collection = $this->collection; + + $documentHandler = new DocumentHandler($connection); + + $document = new Document(); + $document->file = 'testFooBar'; + $documentHandler->add($collection->getId(), $document); + + $statement = new Statement($connection, array( + "query" => 'FOR a IN `ArangoDB_PHP_TestSuite_TestCollection_01` FILTER a.file == @file RETURN a.file', + "bindVars" => array("file" => "testFooBar"), + "_sanitize" => true + )); + + $cursor = $statement->execute(); + + $rows = $cursor->getAll(); + $this->assertEquals("testFooBar", $rows[0]); + } + + + public function testBindReservedName() + { + $connection = $this->connection; + $collection = $this->collection; + + $documentHandler = new DocumentHandler($connection); + + $document = new Document(); + $document->test = 'file'; + $documentHandler->add($collection->getId(), $document); + + $statement = new Statement($connection, array( + "query" => 'FOR a IN `ArangoDB_PHP_TestSuite_TestCollection_01` FILTER a.test == @test RETURN a.test', + "bindVars" => array("test" => "file"), + "_sanitize" => true + )); + + $cursor = $statement->execute(); + + $rows = $cursor->getAll(); + $this->assertEquals("file", $rows[0]); + } + + public function tearDown() { try { From 932d5c20c00a2ed57020972d2ff45583356e9b8b Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Thu, 29 Jan 2015 17:47:31 +0100 Subject: [PATCH 13/19] changed URL --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bf32d256..cab07bc1 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ The autoloader will care about loading additionally required classes on the fly. The ArangoDB PHP client is an API that allows you to send and retrieve documents from ArangoDB from out of your PHP application. The client library itself is written in PHP and has no further dependencies but just plain PHP 5.3 (or higher). -The client library provides document and collection classes you can use to work with documents and collections in an OO fashion. When exchanging document data with the server, the library internally will use the [HTTP REST interface of ArangoDB](https://github.com/triAGENS/ArangoDB/wiki/OTWP). The library user does not have to care about this fact as all the details of the REST interface are abstracted by the client library. +The client library provides document and collection classes you can use to work with documents and collections in an OO fashion. When exchanging document data with the server, the library internally will use the [HTTP REST interface of ArangoDB](https://docs.arangodb.com/HttpApi/README.html). The library user does not have to care about this fact as all the details of the REST interface are abstracted by the client library.
From c0b9dc1bbf10279ddefbbc3e6fc9a560a6dc5aa6 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Thu, 29 Jan 2015 18:12:51 +0100 Subject: [PATCH 14/19] updated URLs --- CHANGELOG.md | 14 +++++++------- CONTRIBUTING.md | 2 +- README.md | 14 +++++++------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6ddcd9d..c8b44035 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -70,7 +70,7 @@ v1.3.0 (2013-05-13) ======================= -* Changed PhpDocs @package content to triagens\ArangoDb, closes issue (see https://github.com/triAGENS/ArangoDB-PHP/issues/123) +* Changed PhpDocs @package content to triagens\ArangoDb, closes issue (see https://github.com/arangodb/ArangoDB-PHP/issues/123) * [Breaking change] Removed getServerStatus() in favor of getServerStatistics() This breaks intentionally, because of the different data and data structure returned by the server in version 1.3 @@ -82,13 +82,13 @@ v1.3.0 (2013-05-13) * PSR-2 reformatting * Made some things more IDE Friendly (in regards to code-completion) and fixed some errors in the PHPDocs -* Initial AQL user functions implementation (see https://github.com/triAGENS/ArangoDB-PHP/pull/116) +* Initial AQL user functions implementation (see https://github.com/arangodb/ArangoDB-PHP/pull/116) -* Implemented support for ArangoDB's transactions (see https://github.com/triAGENS/ArangoDB-PHP/issues/71) +* Implemented support for ArangoDB's transactions (see https://github.com/arangodb/ArangoDB-PHP/issues/71) -* Re-implemented statistics according to new implementation in ArangoDB 1.3 (see https://github.com/triAGENS/ArangoDB-PHP/issues/113) +* Re-implemented statistics according to new implementation in ArangoDB 1.3 (see https://github.com/arangodb/ArangoDB-PHP/issues/113) -* Fixed precondition failed errors (see https://github.com/triAGENS/ArangoDB-PHP/issues/95) +* Fixed precondition failed errors (see https://github.com/arangodb/ArangoDB-PHP/issues/95) * Minor fixes in tests @@ -171,7 +171,7 @@ v1.2.0-BETA2 (2013-02-23) * Bumped travis ArangoDB version to 1.2.beta3 -* Modified CollectionHandler.php to also accept a name and options instead of only a collection object (see https://github.com/triAGENS/ArangoDB-PHP/issues/44). Options can also be set when using an object. Also did some code-style fixing. +* Modified CollectionHandler.php to also accept a name and options instead of only a collection object (see https://github.com/arangodb/ArangoDB-PHP/issues/44). Options can also be set when using an object. Also did some code-style fixing. * Modified GraphHandler->saveVertex() and GraphHandler->saveEdge() so that an array can be passed instead of an object. @@ -179,7 +179,7 @@ v1.2.0-BETA2 (2013-02-23) * Modified DocumentHandler->save() so that an array can be passed instead of a document object. -* Implemented CollectionHandler->updateByExample() & CollectionHandler->replaceByExample(), (see https://github.com/triAGENS/ArangoDB-PHP/issues/40) +* Implemented CollectionHandler->updateByExample() & CollectionHandler->replaceByExample(), (see https://github.com/arangodb/ArangoDB-PHP/issues/40) * Corrected HTTP response codes assertions in some cases, after ArangoDB is now correctly returning 404 in those cases diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 42761cca..4b646d80 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,7 +15,7 @@ Please follow these guidelines if you want to contribute to ArangoDB-PHP: * Clone the fork to your development box and pull the latest changes from the ArangoDB-PHP repository. Please make sure to use the appropriate branch: * the "devel" branch is normally used for new features * bug fixes should be done in the "devel" first, before being applied to master or other branches -* Make sure the ArangoDB version is the correct one to use with your client version. The client version follows the ArangoDB version. [More info on this, here.](https://github.com/triAGENS/ArangoDB-PHP/wiki/Important-versioning-information-on-ArangoDB-PHP) +* Make sure the ArangoDB version is the correct one to use with your client version. The client version follows the ArangoDB version. [More info on this, here.](https://github.com/arangodb/ArangoDB-PHP/wiki/Important-versioning-information-on-ArangoDB-PHP) * Make sure the unmodified clone works locally before making any code changes. You can do so by running the included test suite (phpunit --testsuite ArangoDB-PHP) * If you intend to do documentation changes, you also must install PHPDocumentor in the most recent version (Currently version 2). diff --git a/README.md b/README.md index cab07bc1..05307b9d 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,10 @@ # ArangoDB-PHP - A PHP client for ArangoDB -[![Build Status](https://travis-ci.org/triAGENS/ArangoDB-PHP.png?branch=master)](https://travis-ci.org/triAGENS/ArangoDB-PHP) +[![Build Status](https://travis-ci.org/arangodb/ArangoDB-PHP.png?branch=master)](https://travis-ci.org/arangodb/ArangoDB-PHP) **Branch: Master (v2.3)** -[![Build Status](https://travis-ci.org/triAGENS/ArangoDB-PHP.png?branch=devel)](https://travis-ci.org/triAGENS/ArangoDB-PHP) +[![Build Status](https://travis-ci.org/arangodb/ArangoDB-PHP.png?branch=devel)](https://travis-ci.org/arangodb/ArangoDB-PHP) **Branch: devel** @@ -35,9 +35,9 @@
-Please take a look [here](https://github.com/triAGENS/ArangoDB-PHP/wiki/Important-versioning-information-on-ArangoDB-PHP#arangodb-php-client-to-arangodb-server-interoperability-matrix) for the **ArangoDB-PHP Client** / **ArangoDB Server** interoperability matrix. +Please take a look [here](https://github.com/arangodb/ArangoDB-PHP/wiki/Important-versioning-information-on-ArangoDB-PHP#arangodb-php-client-to-arangodb-server-interoperability-matrix) for the **ArangoDB-PHP Client** / **ArangoDB Server** interoperability matrix. -**[Important versioning information on ArangoDB-PHP](https://github.com/triAGENS/ArangoDB-PHP/wiki/Important-versioning-information-on-ArangoDB-PHP)** +**[Important versioning information on ArangoDB-PHP](https://github.com/arangodb/ArangoDB-PHP/wiki/Important-versioning-information-on-ArangoDB-PHP)**
@@ -64,7 +64,7 @@ The client library provides document and collection classes you can use to work # Requirements -* ArangoDB database server version 1.4 or higher (detailed info [here](https://github.com/triAGENS/ArangoDB-PHP/wiki/Important-versioning-information-on-ArangoDB-PHP#arangodb-php-client-to-arangodb-server-interoperability-matrix)) +* ArangoDB database server version 1.4 or higher (detailed info [here](https://github.com/arangodb/ArangoDB-PHP/wiki/Important-versioning-information-on-ArangoDB-PHP#arangodb-php-client-to-arangodb-server-interoperability-matrix)) * PHP version 5.3 or higher (Travis-tested with 5.4, 5.5, 5.6 and hhvm) @@ -165,7 +165,7 @@ require 'vendor/.composer/autoload.php'; When preferring this alternative, you need to have a git client installed. To clone the ArangoDB PHP client repository from github, execute the following command in your project directory: - git clone "https://github.com/triAGENS/ArangoDB-PHP.git" + git clone "https://github.com/arangodb/ArangoDB-PHP.git" This will create a subdirectory ArangoDB-PHP in your current directory. It contains all the files of the client library. It also includes a dedicated autoloader that you can use for autoloading the client libraries class files. @@ -607,4 +607,4 @@ catch (ArangoServerException $e) { * [Follow us on Twitter @arangodbphp to receive updates on the php driver](https://twitter.com/arangodbphp) -* Check the ArangoDB PHP client on github.com regularly for new releases and updates: [https://github.com/triAGENS/ArangoDB-PHP](https://github.com/triAGENS/ArangoDB-PHP) +* Check the ArangoDB PHP client on github.com regularly for new releases and updates: [https://github.com/arangodb/ArangoDB-PHP](https://github.com/arangodb/ArangoDB-PHP) From 10152f8740e25ca66c5d9a68c2ce7ea07f52033c Mon Sep 17 00:00:00 2001 From: jsteemann Date: Thu, 29 Jan 2015 23:28:08 +0100 Subject: [PATCH 15/19] added mechanism for error logging --- README.md | 44 ++++++++++++++++++++++++-- lib/triagens/ArangoDb/BindVars.php | 2 +- lib/triagens/ArangoDb/Connection.php | 4 +-- lib/triagens/ArangoDb/Exception.php | 30 ++++++++++++++++++ lib/triagens/ArangoDb/HttpHelper.php | 14 ++++++-- lib/triagens/ArangoDb/HttpResponse.php | 6 ++-- 6 files changed, 89 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 05307b9d..29c8e17f 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ - [Updating a document](#updating_document) - [Deleting a document](#deleting_document) - [Dropping a collection](#dropping_collection) + - [Logging exceptions](#logging_exceptions) - [Putting it all together](#alltogether) - [More information](#more_info) @@ -465,6 +466,33 @@ $result = $collectionHandler->drop('users'); var_dump($result); ``` + + +## Logging exceptions + + +The driver provides a simple logging mechanism that is turned off by default. If it is turned on, the driver +will log all its exceptions using PHP's standard `error_log` mechanism. It will call PHP's `error_log()` +function for this. It depends on the PHP configuration if and where exceptions will be logged. Please consult +your php.ini settings for further details. + +To turn on exception logging in the driver, set a flag on the driver's Exception base class, from which all +driver exceptions are subclassed: + +```php +use triagens\ArangoDb\Exception as ArangoException; + +ArangoException::enableLogging(); +``` + +To turn logging off, call its `disableLogging` method: + +```php +use triagens\ArangoDb\Exception as ArangoException; + +ArangoException::disableLogging(); +``` + ## Putting it all together @@ -510,16 +538,26 @@ $connectionOptions = array( ArangoConnectionOptions::OPTION_UPDATE_POLICY => ArangoUpdatePolicy::LAST, ); + +// turn on exception logging (logs to whatever PHP is configured) +ArangoException::enableLogging(); + try { $connection = new ArangoConnection($connectionOptions); - $collectionHandler = new ArangoCollectionHandler($connection); + // clean up first + try { + $collectionHandler->drop('users'); + } + catch (\Exception $e) { + // ignore here... + } + // create a new collection $userCollection = new ArangoCollection(); $userCollection->setName('users'); - $id = $collectionHandler->add($userCollection); // print the collection id created by the server var_dump($id); @@ -590,7 +628,7 @@ catch (ArangoClientException $e) { print 'Client error: ' . $e->getMessage() . PHP_EOL; } catch (ArangoServerException $e) { - print 'Server error: ' . $e->getServerCode() . ':' . $e->getServerMessage() . ' ' . $e->getMessage() . PHP_EOL; + print 'Server error: ' . $e->getServerCode() . ': ' . $e->getServerMessage() . ' - ' . $e->getMessage() . PHP_EOL; } ``` diff --git a/lib/triagens/ArangoDb/BindVars.php b/lib/triagens/ArangoDb/BindVars.php index a527630f..4478227b 100644 --- a/lib/triagens/ArangoDb/BindVars.php +++ b/lib/triagens/ArangoDb/BindVars.php @@ -92,7 +92,7 @@ public function set($name, $value = null) $this->_values[(string) $name] = $value; ValueValidator::validate($value); } else { - throw new ClientException('Bind variable name should be string, int or array'); + throw new ClientException('Bind variable name should be string or int'); } } } diff --git a/lib/triagens/ArangoDb/Connection.php b/lib/triagens/ArangoDb/Connection.php index a33f15ec..c3281ecc 100644 --- a/lib/triagens/ArangoDb/Connection.php +++ b/lib/triagens/ArangoDb/Connection.php @@ -367,7 +367,7 @@ private function executeRequest($method, $url, $data, $customerHeader = array()) if ($traceFunc) { // call tracer func if ($this->_options[ConnectionOptions::OPTION_ENHANCED_TRACE]) { - list($header) = HttpHelper::parseHttpMessage($request); + list($header) = HttpHelper::parseHttpMessage($request, $url, $method); $headers = HttpHelper::parseHeaders($header); $traceFunc(new TraceRequest($headers[2], $method, $url, $data)); } else { @@ -405,7 +405,7 @@ private function executeRequest($method, $url, $data, $customerHeader = array()) throw new ClientException('Got a timeout when waiting on the server\'s response'); } */ - $response = new HttpResponse($result); + $response = new HttpResponse($result, $url, $method); if ($traceFunc) { // call tracer func diff --git a/lib/triagens/ArangoDb/Exception.php b/lib/triagens/ArangoDb/Exception.php index cd44806f..9db18bfa 100644 --- a/lib/triagens/ArangoDb/Exception.php +++ b/lib/triagens/ArangoDb/Exception.php @@ -21,4 +21,34 @@ class Exception extends \Exception { + public function __construct($message = null, $code = 0, \Exception $previous = null) + { + if (is_string($message) && self::$enableLogging) { + @error_log(get_class($this) . ': ' . $message); + @error_log('Stack trace:'); + foreach (explode(PHP_EOL, $this->getTraceAsString()) as $i => $line) { + @error_log(' ' . $line); + } + } + + parent::__construct($message, $code, $previous); + } + + /** + * Turn on exception logging + */ + public static function enableLogging () + { + self::$enableLogging = true; + } + + /** + * Turn off exception logging + */ + public static function disableLogging () + { + self::$enableLogging = false; + } + + private static $enableLogging = false; } diff --git a/lib/triagens/ArangoDb/HttpHelper.php b/lib/triagens/ArangoDb/HttpHelper.php index 761c4d67..f68d2f09 100644 --- a/lib/triagens/ArangoDb/HttpHelper.php +++ b/lib/triagens/ArangoDb/HttpHelper.php @@ -92,7 +92,7 @@ public static function validateMethod($method) return true; } - throw new ClientException('Invalid request method'); + throw new ClientException('Invalid request method \'' . $method . '\''); } /** @@ -253,7 +253,8 @@ public static function createConnection(ConnectionOptions $options) $options[ConnectionOptions::OPTION_TIMEOUT] ); if (!$fp) { - throw new ConnectException($message, $number); + throw new ConnectException('cannot connect to endpoint \'' . + $options[ConnectionOptions::OPTION_ENDPOINT] . '\': ' . $message, $number); } stream_set_timeout($fp, $options[ConnectionOptions::OPTION_TIMEOUT]); @@ -265,11 +266,13 @@ public static function createConnection(ConnectionOptions $options) * Splits a http message into its header and body. * * @param string $httpMessage The http message string. + * @param string $originUrl The original URL the response is coming from + * @param string $originMethod The HTTP method that was used when sending data to the origin URL * * @throws ClientException * @return array */ - public static function parseHttpMessage($httpMessage) + public static function parseHttpMessage($httpMessage, $originUrl = null, $originMethod = null) { assert(is_string($httpMessage)); @@ -282,6 +285,11 @@ public static function parseHttpMessage($httpMessage) } if (!isset($parts[1]) or $parts[1] === null) { + if ($originUrl !== null && $originMethod !== null) { + throw new ClientException('Got an invalid response from the server after request to ' + . $originMethod . ' ' . $originUrl); + } + throw new ClientException('Got an invalid response from the server'); } diff --git a/lib/triagens/ArangoDb/HttpResponse.php b/lib/triagens/ArangoDb/HttpResponse.php index ac28bdff..d9096e4c 100644 --- a/lib/triagens/ArangoDb/HttpResponse.php +++ b/lib/triagens/ArangoDb/HttpResponse.php @@ -66,10 +66,12 @@ class HttpResponse * @throws ClientException * * @param string $responseString - the complete HTTP response as supplied by the server + * @param string $originUrl The original URL the response is coming from + * @param string $originMethod The HTTP method that was used when sending data to the origin URL */ - public function __construct($responseString) + public function __construct($responseString, $originUrl = null, $originMethod = null) { - list($this->_header, $this->_body) = HttpHelper::parseHttpMessage($responseString); + list($this->_header, $this->_body) = HttpHelper::parseHttpMessage($responseString, $originUrl, $originMethod); list($this->_httpCode, $this->_result, $this->_headers) = HttpHelper::parseHeaders($this->_header); } From 5cc4c8ed3a538e145a83b6d3e1073335abe0d3e7 Mon Sep 17 00:00:00 2001 From: jsteemann Date: Thu, 29 Jan 2015 23:28:30 +0100 Subject: [PATCH 16/19] less notices --- lib/triagens/ArangoDb/Connection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/triagens/ArangoDb/Connection.php b/lib/triagens/ArangoDb/Connection.php index c3281ecc..919bc60a 100644 --- a/lib/triagens/ArangoDb/Connection.php +++ b/lib/triagens/ArangoDb/Connection.php @@ -293,8 +293,8 @@ public function parseResponse(HttpResponse $response) if ($body != '') { // check if we can find details in the response body $details = json_decode($body, true); - if (is_array($details)) { - // yes, we got details + if (is_array($details) && isset($details["errorMessage"])) { + // yes, we got details $exception = new ServerException($details["errorMessage"], $details["code"]); $exception->setDetails($details); throw $exception; From 1dfc8de224652c613d64f46afad2d4801a7c8157 Mon Sep 17 00:00:00 2001 From: jsteemann Date: Thu, 29 Jan 2015 23:37:06 +0100 Subject: [PATCH 17/19] updated URLs --- README.md | 24 ++++++++++++------------ composer.json | 12 ++++++------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 29c8e17f..a04af98c 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,10 @@ # ArangoDB-PHP - A PHP client for ArangoDB -[![Build Status](https://travis-ci.org/arangodb/ArangoDB-PHP.png?branch=master)](https://travis-ci.org/arangodb/ArangoDB-PHP) +[![Build Status](https://travis-ci.org/arangodb/arangodb-php.png?branch=master)](https://travis-ci.org/arangodb/arangodb-php) **Branch: Master (v2.3)** -[![Build Status](https://travis-ci.org/arangodb/ArangoDB-PHP.png?branch=devel)](https://travis-ci.org/arangodb/ArangoDB-PHP) +[![Build Status](https://travis-ci.org/arangodb/arangodb-php.png?branch=devel)](https://travis-ci.org/arangodb/arangodb-php) **Branch: devel** @@ -36,9 +36,9 @@
-Please take a look [here](https://github.com/arangodb/ArangoDB-PHP/wiki/Important-versioning-information-on-ArangoDB-PHP#arangodb-php-client-to-arangodb-server-interoperability-matrix) for the **ArangoDB-PHP Client** / **ArangoDB Server** interoperability matrix. +Please take a look [here](https://github.com/arangodb/arangodb-php/wiki/Important-versioning-information-on-ArangoDB-PHP#arangodb-php-client-to-arangodb-server-interoperability-matrix) for the **ArangoDB-PHP Client** / **ArangoDB Server** interoperability matrix. -**[Important versioning information on ArangoDB-PHP](https://github.com/arangodb/ArangoDB-PHP/wiki/Important-versioning-information-on-ArangoDB-PHP)** +**[Important versioning information on ArangoDB-PHP](https://github.com/arangodb/arangodb-php/wiki/Important-versioning-information-on-ArangoDB-PHP)**
@@ -65,7 +65,7 @@ The client library provides document and collection classes you can use to work # Requirements -* ArangoDB database server version 1.4 or higher (detailed info [here](https://github.com/arangodb/ArangoDB-PHP/wiki/Important-versioning-information-on-ArangoDB-PHP#arangodb-php-client-to-arangodb-server-interoperability-matrix)) +* ArangoDB database server version 1.4 or higher (detailed info [here](https://github.com/arangodb/arangodb-php/wiki/Important-versioning-information-on-ArangoDB-PHP#arangodb-php-client-to-arangodb-server-interoperability-matrix)) * PHP version 5.3 or higher (Travis-tested with 5.4, 5.5, 5.6 and hhvm) @@ -166,14 +166,14 @@ require 'vendor/.composer/autoload.php'; When preferring this alternative, you need to have a git client installed. To clone the ArangoDB PHP client repository from github, execute the following command in your project directory: - git clone "https://github.com/arangodb/ArangoDB-PHP.git" + git clone "https://github.com/arangodb/arangodb-php.git" -This will create a subdirectory ArangoDB-PHP in your current directory. It contains all the files of the client library. It also includes a dedicated autoloader that you can use for autoloading the client libraries class files. +This will create a subdirectory arangodb-php in your current directory. It contains all the files of the client library. It also includes a dedicated autoloader that you can use for autoloading the client libraries class files. To invoke this autoloader, add the following line to your PHP files that will use the library: ```php -require 'ArangoDB-PHP/autoload.php'; +require 'arangodb-php/autoload.php'; ``` @@ -185,7 +185,7 @@ The ArangoDB PHP client's autoloader will only care about its own class files an If you do not wish to include autoload.php to load and setup the autoloader, you can invoke the autoloader directly: ```php -require 'ArangoDB-PHP/lib/triagens/ArangoDb/autoloader.php'; +require 'arangodb-php/lib/triagens/ArangoDb/autoloader.php'; \triagens\ArangoDb\Autoloader::init(); ``` @@ -204,7 +204,7 @@ In order to use ArangoDB, you need to specify the connection options. We do so b // require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . '.composer' . DIRECTORY_SEPARATOR . 'autoload.php'; // use the following line when using git -require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'ArangoDB-PHP' . DIRECTORY_SEPARATOR . 'autoload.php'; +require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'arangodb-php' . DIRECTORY_SEPARATOR . 'autoload.php'; // set up some aliases for less typing later use triagens\ArangoDb\Collection as ArangoCollection; @@ -503,7 +503,7 @@ Here's the full code that combines all the pieces outlined above: // require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . '.composer' . DIRECTORY_SEPARATOR . 'autoload.php'; // use the following line when using git -require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'ArangoDB-PHP' . DIRECTORY_SEPARATOR . 'autoload.php'; +require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'arangodb-php' . DIRECTORY_SEPARATOR . 'autoload.php'; // set up some aliases for less typing later use triagens\ArangoDb\Collection as ArangoCollection; @@ -645,4 +645,4 @@ catch (ArangoServerException $e) { * [Follow us on Twitter @arangodbphp to receive updates on the php driver](https://twitter.com/arangodbphp) -* Check the ArangoDB PHP client on github.com regularly for new releases and updates: [https://github.com/arangodb/ArangoDB-PHP](https://github.com/arangodb/ArangoDB-PHP) +* Check the ArangoDB PHP client on github.com regularly for new releases and updates: [https://github.com/arangodb/arangodb-php](https://github.com/arangodb/arangodb-php) diff --git a/composer.json b/composer.json index 9e638210..e5ecccfb 100644 --- a/composer.json +++ b/composer.json @@ -1,24 +1,24 @@ { "name": "triagens/ArangoDb", "type": "library", - "description": "ArangodDb PHP client", + "description": "ArangoDb PHP client", "keywords": ["database","ArangoDb","Arango","document store","NoSQL"], - "homepage": "https://github.com/triAGENS/ArangoDB-PHP", + "homepage": "https://github.com/arangodb/arangodb-php", "license": "Apache2", "authors": [ { "name": "Jan Steemann", - "homepage": "https://github.com/triAGENS/ArangoDB-PHP", + "homepage": "https://github.com/arangodb/arangodb-php", "role": "Developer" }, { "name": "Frank Mayer", - "homepage": "https://github.com/triAGENS/ArangoDB-PHP", + "homepage": "https://github.com/arangodb/arangodb-php", "role": "Developer" }, { "name": "Contributors", - "homepage": "https://github.com/triAGENS/ArangoDB-PHP/graphs/contributors" + "homepage": "https://github.com/arangodb/arangodb-php/graphs/contributors" } ], "require": { @@ -32,7 +32,7 @@ "repositories": [ { "type": "vcs", - "url": "https://github.com/triAGENS/ArangoDB-PHP" + "url": "https://github.com/arangodb/arangodb-php" } ] } From 1d6ae858211b04731c0ad4fb460ea5472a4ddc5e Mon Sep 17 00:00:00 2001 From: jsteemann Date: Thu, 29 Jan 2015 23:47:59 +0100 Subject: [PATCH 18/19] changed URL --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e5ecccfb..8b85d754 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "triagens/ArangoDb", + "name": "arangodb/arangodb", "type": "library", "description": "ArangoDb PHP client", "keywords": ["database","ArangoDb","Arango","document store","NoSQL"], From af4081b8df3ce2c7bf0238d17a91bb5e5dd73b87 Mon Sep 17 00:00:00 2001 From: Thomas Schmidts Date: Mon, 16 Feb 2015 15:27:05 +0100 Subject: [PATCH 19/19] Updated LICENSE --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index d6456956..9de9747f 100644 --- a/LICENSE +++ b/LICENSE @@ -187,7 +187,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] + Copyright 2015 ArangoDB GmbH Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.