Skip to content

Commit b6326d7

Browse files
author
diabl0
committed
Merge branch 'devel' of github.com:arangodb/arangodb-php into DocumentClass
2 parents 7e41087 + add7a10 commit b6326d7

39 files changed

+855
-480
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ matrix:
66
- php: '7.0'
77
- php: '7.1'
88
- php: hhvm
9+
fast_finish: true
910

1011
before_script:
1112
- chmod 777 ./tests/travis/setup_arangodb.sh
1213
- ./tests/travis/setup_arangodb.sh
1314

1415
script:
15-
- phpunit --configuration ./tests/phpunit-connection-close.xml
16-
- phpunit --configuration ./tests/phpunit-connection-keep-alive.xml
16+
- ./phpunit --configuration ./tests/phpunit-connection-close.xml
17+
- ./phpunit --configuration ./tests/phpunit-connection-keep-alive.xml
1718

1819
after_script:
1920
- ./tests/travis/teardown_arangodb.sh

CHANGELOG renamed to CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
Release notes for the ArangoDB-PHP driver 3.2.0 (currently in development)
22
==========================================================================
3+
- Document ID's are now handled correctly. This is a necessary and ___backwards incompatible change___, in order to be consistent with ArangoDB's API.
4+
5+
Why: It was necessary to fix the document ids to correctly use ArangoDB's _ids instead of only the _key.
6+
7+
__Important incompatible changes related to this:__
8+
- Document::getId(): Will return the correct id (CollectionName/DocumentID) instead of the key (DocumentID).
9+
- UrlHelper::getDocumentIdFromLocation(): Will now return a "real" _id instead of what was essentially the `_key`
10+
11+
__Other changes related to this:__
12+
- DocumentHandler::getById(): Will work as before, but it will also accept a "real" document ID in addition to the key.
13+
If a real document ID is given, the collection data will be extracted from that string. That means that the first parameter `$collection` does not need to have a valid value, in that case.
314

415
- The namespace `\triagens\ArangoDb` was replaced with `\ArangoDBClient`.
516
For each class in the old namespace there is now a class alias that points

examples/bulk.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,29 @@
77
try {
88
$connection = new Connection($connectionOptions);
99
$handler = new CollectionHandler($connection);
10-
10+
1111
if ($handler->has('example')) {
1212
$handler->drop('example');
1313
}
14-
14+
1515
$col = new Collection();
1616
$col->setName('example');
1717
$handler->create($col);
1818

1919
// create a statement to insert 100 example documents
2020
$statement = new Statement($connection, [
21-
'query' => 'FOR i IN 1..100 INSERT { _key: CONCAT("example", i) } IN example'
22-
]
21+
'query' => 'FOR i IN 1..100 INSERT { _key: CONCAT("example", i) } IN example'
22+
]
2323
);
2424
$statement->execute();
25-
25+
2626
// print number of documents
2727
var_dump($handler->count('example'));
2828

2929
// later on, we can assemble a list of document keys
3030
$keys = [];
3131
for ($i = 1; $i <= 100; ++$i) {
32-
$keys[] = 'example' . $i;
32+
$keys[] = 'example' . $i;
3333
}
3434
// and fetch all the documents at once by their keys
3535
$documents = $handler->lookupByKeys('example', $keys);
@@ -40,7 +40,7 @@
4040
$result = $handler->removeByKeys('example', $keys);
4141

4242
var_dump($result);
43-
43+
4444
// print number of documents after bulk removal
4545
var_dump($handler->count('example'));
4646

examples/customDocumentClass.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,13 @@ public function onUpdate()
7171

7272
/**
7373
* Specify data which should be serialized to JSON
74+
*
7475
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
7576
* @return mixed data which can be serialized by <b>json_encode</b>,
76-
* which is a value of any type other than a resource.
77-
* @since 5.4.0
77+
* which is a value of any type other than a resource.
78+
* @since 3.2
7879
*/
79-
function jsonSerialize()
80+
public function jsonSerialize()
8081
{
8182
return $this->getAll();
8283
}
@@ -100,6 +101,7 @@ abstract class AbstractCollection extends CollectionHandler
100101
* {@inheritdoc}
101102
*
102103
* @param Connection $connection
104+
*
103105
* @throws \Exception
104106
*/
105107
public function __construct(Connection $connection)
@@ -130,7 +132,7 @@ public function getCollectionNameString()
130132
*
131133
* @throws Exception
132134
*
133-
* @param mixed $document - the example document as a Document object or an array
135+
* @param mixed $document - the example document as a Document object or an array
134136
* @param bool|array $options - optional, prior to v1.0.0 this was a boolean value for sanitize, since v1.0.0 it's an array of options.
135137
* <p>Options are :<br>
136138
* <li>'_sanitize' - True to remove _id and _rev attributes from result documents. Defaults to false.</li>
@@ -159,6 +161,7 @@ public function findByExample($document, $options = [])
159161
* Find all documents for given keys
160162
*
161163
* @param array $ids - array of document keys
164+
*
162165
* @return array of matching entities
163166
*/
164167
public function findByIds($ids)
@@ -191,6 +194,7 @@ public function findOneByExample($example)
191194
* Gets one document by given ID
192195
*
193196
* @param string|int $id
197+
*
194198
* @return AbstractEntity|null
195199
* @throws ServerException
196200
*/
@@ -223,6 +227,7 @@ public function getInternalCollectionName()
223227
* {@inheritDoc}
224228
*
225229
* @param AbstractEntity $document
230+
*
226231
* @return mixed
227232
*/
228233
public function store($document)
@@ -236,11 +241,13 @@ public function store($document)
236241
if (method_exists($document, 'onCreate')) {
237242
$document->onCreate();
238243
}
244+
239245
return $this->_documentHandler->save($this->_collectionName, $document);
240246
} else {
241247
if (method_exists($document, 'onUpdate')) {
242248
$document->onUpdate();
243249
}
250+
244251
return $this->_documentHandler->replace($document);
245252
}
246253
}
@@ -249,7 +256,8 @@ public function store($document)
249256
* Removes specified document from collection
250257
*
251258
* @param AbstractEntity $document
252-
* @param $options
259+
* @param $options
260+
*
253261
* @return array - an array containing an attribute 'removed' with the number of documents that were deleted, an an array 'ignored' with the number of not removed keys/documents
254262
*/
255263
public function removeDocument(AbstractEntity $document, $options = [])
@@ -275,7 +283,7 @@ public function setName($value)
275283

276284
public function setAge($value)
277285
{
278-
$this->set('age', (int)$value);
286+
$this->set('age', (int) $value);
279287
}
280288

281289
public function onCreate()
@@ -296,7 +304,7 @@ public function onUpdate()
296304
class Users extends AbstractCollection
297305
{
298306

299-
protected $_documentClass = '\ArangoDBClient\User';
307+
protected $_documentClass = '\ArangoDBClient\User';
300308
protected $_collectionName = 'users';
301309

302310
public function getByAge($value)

examples/document.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
$connection = new Connection($connectionOptions);
99
$collectionHandler = new CollectionHandler($connection);
1010
$handler = new DocumentHandler($connection);
11-
11+
1212
// set up a document collection "users"
13-
$collection = new Collection('users');
13+
$collection = new Collection('users');
1414
try {
1515
$collectionHandler->create($collection);
16-
}
17-
catch (\Exception $e) {
16+
} catch (\Exception $e) {
1817
// collection may already exist - ignore this error for now
1918
}
2019

examples/edge.php

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,34 @@
1111
$edgeHandler = new EdgeHandler($connection);
1212

1313
// set up two document collections
14-
$collection = new Collection('employees');
14+
$collection = new Collection('employees');
1515
try {
1616
$collectionHandler->create($collection);
17-
}
18-
catch (\Exception $e) {
17+
} catch (\Exception $e) {
1918
// collection may already exist - ignore this error for now
2019
}
21-
22-
$collection = new Collection('departments');
20+
21+
$collection = new Collection('departments');
2322
try {
2423
$collectionHandler->create($collection);
25-
}
26-
catch (\Exception $e) {
24+
} catch (\Exception $e) {
2725
// collection may already exist - ignore this error for now
2826
}
29-
27+
3028
// set up an edge collection to link the two previous collections
31-
$collection = new Collection('worksFor');
29+
$collection = new Collection('worksFor');
3230
$collection->setType(3);
33-
31+
3432
try {
3533
$collectionHandler->create($collection);
36-
}
37-
catch (\Exception $e) {
34+
} catch (\Exception $e) {
3835
// collection may already exist - ignore this error for now
3936
}
40-
37+
4138
// create a new department
4239
$marketing = Document::createFromArray(['name' => 'Marketing']);
4340
$documentHandler->save('departments', $marketing);
44-
41+
4542
// create another department
4643
$finance = Document::createFromArray(['name' => 'Finance']);
4744
$documentHandler->save('departments', $finance);
@@ -57,11 +54,11 @@
5754
// now insert a link between Marketing and Jane
5855
$worksFor = Edge::createFromArray(['startDate' => '2009-06-23', 'endDate' => '2014-11-12']);
5956
$edgeHandler->saveEdge('worksFor', $marketing->getHandle(), $jane->getHandle(), $worksFor);
60-
57+
6158
// now insert a link between Finance and Jane
6259
$worksFor = Edge::createFromArray(['startDate' => '2014-11-12']);
6360
$edgeHandler->saveEdge('worksFor', $finance->getHandle(), $jane->getHandle(), $worksFor);
64-
61+
6562
// now insert a link between Finance and John
6663
$worksFor = Edge::createFromArray(['startDate' => '2012-04-01']);
6764
$edgeHandler->saveEdge('worksFor', $finance->getHandle(), $john->getHandle(), $worksFor);

examples/export.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
// creates an export object for collection 'users'
1111
$export = new Export($connection, 'users', [
12-
'batchSize' => 5000,
13-
'_flat' => true,
14-
'flush' => true,
15-
'restrict' => [
16-
'type' => 'include',
17-
'fields' => ['_key', '_rev']
18-
]
19-
]
12+
'batchSize' => 5000,
13+
'_flat' => true,
14+
'flush' => true,
15+
'restrict' => [
16+
'type' => 'include',
17+
'fields' => ['_key', '_rev']
18+
]
19+
]
2020
);
2121

2222
// execute the export. this will return a special, forward-only cursor

examples/graph.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
try {
1818
$graphHandler->dropGraph($graph);
19-
}
20-
catch (\Exception $e) {
19+
} catch (\Exception $e) {
2120
// graph may not yet exist. ignore this error for now
2221
}
2322

@@ -45,7 +44,7 @@
4544
// Save the vertices
4645
$graphHandler->saveVertex('Graph', $vertex1);
4746
$graphHandler->saveVertex('Graph', $vertex2);
48-
47+
4948
// Get the vertices
5049
$graphHandler->getVertex('Graph', 'vertex1');
5150
$graphHandler->getVertex('Graph', 'vertex2');
@@ -65,7 +64,7 @@
6564
// Remove vertices and edges
6665
$graphHandler->removeVertex('Graph', 'vertex1');
6766
$graphHandler->removeVertex('Graph', 'vertex2');
68-
67+
6968
// the connecting edge will be deleted automatically
7069
} catch (ConnectException $e) {
7170
print $e . PHP_EOL;

examples/http-test.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@
1313
$connection = new Connection($connectionOptions);
1414
$collectionHandler = new CollectionHandler($connection);
1515
$handler = new DocumentHandler($connection);
16-
16+
1717
// set up a document collection "test"
1818
// first try to remove it if it already exists
1919
try {
2020
$collectionHandler->drop('test');
21-
}
22-
catch (\Exception $e) {
21+
} catch (\Exception $e) {
2322
// collection may not exist. we don't care here
2423
}
25-
24+
2625
// now create the collection
2726
$collection = new Collection('test');
2827
$collectionHandler->create($collection);
@@ -34,9 +33,9 @@
3433
// this issues lots of HTTP requests to the server so we
3534
// can test the HTTP layer
3635
for ($i = 0; $i < $n; ++$i) {
37-
$document = new Document(['value' => 'test' . $i]);
36+
$document = new Document(['value' => 'test' . $i]);
3837

39-
$handler->save('test', $document);
38+
$handler->save('test', $document);
4039
}
4140

4241
echo 'creating documents took ' . (microtime(true) - $time) . ' s' . PHP_EOL;

0 commit comments

Comments
 (0)