Skip to content

Commit 4985ebb

Browse files
committed
Implemented edges support
Tests written and pass on ArangoDB 1.0 & 1.1 Signed-off-by: Frank Mayer <frank@frankmayer.net>
1 parent 44f211d commit 4985ebb

File tree

9 files changed

+402
-49
lines changed

9 files changed

+402
-49
lines changed

lib/triagens/ArangoDb/Collection.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ class Collection {
2828
*/
2929
private $_name = NULL;
3030

31+
/**
32+
* The collection type (might be NULL for new collections)
33+
* @var int - collection type
34+
*/
35+
private $_type = NULL;
36+
3137
/**
3238
* The collection waitForSync value (might be NULL for new collections)
3339
* @var bool - waitForSync value
@@ -44,6 +50,11 @@ class Collection {
4450
*/
4551
const ENTRY_NAME = 'name';
4652

53+
/**
54+
* Collection type index
55+
*/
56+
const ENTRY_TYPE = 'type';
57+
4758
/**
4859
* Collection 'waitForSync' index
4960
*/
@@ -129,6 +140,7 @@ public function getAll() {
129140
self::ENTRY_ID => $this->_id,
130141
self::ENTRY_NAME => $this->_name,
131142
self::ENTRY_WAIT_SYNC => $this->_waitForSync,
143+
self::ENTRY_TYPE => $this->_type,
132144
);
133145
}
134146

@@ -163,6 +175,10 @@ public function set($key, $value) {
163175
$this->setWaitForSync($value);
164176
return;
165177
}
178+
if ($key === self::ENTRY_TYPE) {
179+
$this->setType($value);
180+
return;
181+
}
166182

167183
// unknown attribute, will be ignored
168184
}
@@ -220,6 +236,32 @@ public function getName() {
220236
return $this->_name;
221237
}
222238

239+
/**
240+
* Set the collection type
241+
*
242+
* @throws ClientException
243+
* @param string $type - type
244+
* @return void
245+
*/
246+
public function setType($type) {
247+
assert(is_int($type));
248+
249+
if ($this->_type !== NULL && $this->$type != $type) {
250+
throw new ClientException('Should not update the type of an existing collection');
251+
}
252+
253+
$this->_type = $type;
254+
}
255+
256+
/**
257+
* Get the collection type (if already known)
258+
*
259+
* @return string - name
260+
*/
261+
public function getType() {
262+
return $this->_type;
263+
}
264+
223265
/**
224266
* Set the waitForSync value
225267
*

lib/triagens/ArangoDb/CollectionHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ public function create(Collection $collection) {
165165
if ($collection->getWaitForSync() === NULL) {
166166
$collection->setWaitForSync($this->getConnection()->getOption(ConnectionOptions::OPTION_WAIT_SYNC));
167167
}
168-
169-
$params = array(Collection::ENTRY_NAME => $collection->getName(), Collection::ENTRY_WAIT_SYNC => $collection->getWaitForSync());
168+
$type = $collection->getType()? $collection->getType(): 2;
169+
$params = array(Collection::ENTRY_NAME => $collection->getName(), Collection::ENTRY_TYPE => $type, Collection::ENTRY_WAIT_SYNC => $collection->getWaitForSync());
170170
$response = $this->getConnection()->post(Urls::URL_COLLECTION, json_encode($params));
171171

172172
$location = $response->getLocationHeader();

lib/triagens/ArangoDb/Document.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,25 @@ class Document {
2020
* The document id (might be NULL for new documents)
2121
* @var string - document id
2222
*/
23-
private $_id = NULL;
23+
protected $_id = NULL;
2424

2525
/**
2626
* The document revision (might be NULL for new documents)
2727
* @var mixed
2828
*/
29-
private $_rev = NULL;
29+
protected $_rev = NULL;
3030

3131
/**
3232
* The document attributes (names/values)
3333
* @var array
3434
*/
35-
private $_values = array();
35+
protected $_values = array();
3636

3737
/**
3838
* Flag to indicate whether document was changed locally
3939
* @var bool
4040
*/
41-
private $_changed;
41+
protected $_changed;
4242

4343
/**
4444
* Document id index
@@ -260,6 +260,17 @@ public function getInternalId() {
260260
return $this->_id;
261261
}
262262

263+
/**
264+
* Convenience function to get the document handle (if already known) - is an alias to getInternalId()
265+
* Document handles are generated on the server only. Document handles consist of collection id and
266+
* document id, in the format collectionid/documentid
267+
*
268+
* @return string - internal document id, might be NULL if document does not yet have an id
269+
*/
270+
public function getHandle() {
271+
return $this->getInternalId();
272+
}
273+
263274
/**
264275
* Get the document id (if already known)
265276
* Document ids are generated on the server only. Document ids are numeric but might be

lib/triagens/ArangoDb/DocumentHandler.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ public function save($collectionId, Document $document, $create = NULL) {
133133
if ($create === NULL) {
134134
$create = $this->getConnection()->getOption(ConnectionOptions::OPTION_CREATE);
135135
}
136-
137136
$data = $document->getAll();
138137
$params = array(self::OPTION_COLLECTION => $collectionId, ConnectionOptions::OPTION_CREATE => UrlHelper::getBoolString($create));
139138
$url = UrlHelper::appendParamsUrl(Urls::URL_DOCUMENT, $params);

lib/triagens/ArangoDb/Edge.php

Lines changed: 58 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,39 @@
1616
* @package ArangoDbPhpClient
1717
*/
1818
class Edge extends Document {
19+
// /**
20+
// * The document id (might be NULL for new documents)
21+
// * @var string - document id
22+
// */
23+
// private $_id = NULL;
24+
//
25+
// /**
26+
// * The document revision (might be NULL for new documents)
27+
// * @var mixed
28+
// */
29+
// private $_rev = NULL;
30+
//
1931
/**
20-
* The document id (might be NULL for new documents)
21-
* @var string - document id
22-
*/
23-
private $_id = NULL;
24-
25-
/**
26-
* The document revision (might be NULL for new documents)
32+
* The edge's from (might be NULL for new documents)
2733
* @var mixed
2834
*/
29-
private $_rev = NULL;
35+
protected $_from = NULL;
3036

3137
/**
32-
* The document attributes (names/values)
33-
* @var array
34-
*/
35-
private $_values = array();
36-
37-
/**
38-
* Flag to indicate whether document was changed locally
39-
* @var bool
40-
*/
41-
private $_changed;
42-
43-
/**
44-
* Document _id index
38+
* The edge's to (might be NULL for new documents)
39+
* @var mixed
4540
*/
46-
const ENTRY_ID = '_id';
41+
protected $_to = NULL;
4742

48-
/**
49-
* Revision _rev index
50-
*/
51-
const ENTRY_REV = '_rev';
43+
// /**
44+
// * Document _id index
45+
// */
46+
// const ENTRY_ID = '_id';
47+
//
48+
// /**
49+
// * Revision _rev index
50+
// */
51+
// const ENTRY_REV = '_rev';
5252

5353
/**
5454
* Document _from index
@@ -71,8 +71,8 @@ class Edge extends Document {
7171
public function __clone() {
7272
$this->_id = NULL;
7373
$this->_rev = NULL;
74-
$this->_to = NULL;
75-
$this->_from = NULL;
74+
// $this->_to = NULL;
75+
// $this->_from = NULL;
7676

7777
// do not change the _changed flag here
7878
}
@@ -109,12 +109,12 @@ public function set($key, $value) {
109109
}
110110

111111
if ($key === self::ENTRY_FROM) {
112-
$this->setInternalId($value);
112+
$this->setFrom($value);
113113
return;
114114
}
115115

116116
if ($key === self::ENTRY_TO) {
117-
$this->setRevision($value);
117+
$this->setTo($value);
118118
return;
119119
}
120120

@@ -129,22 +129,45 @@ public function set($key, $value) {
129129
$this->_values[$key] = $value;
130130
}
131131

132-
132+
133133
/**
134-
* Get the document revision (if already known)
134+
* Get the 'from' vertex document-handler (if already known)
135135
*
136-
* @return mixed - revision id, might be NULL if document does not yet have an id
136+
* @return mixed - document-handler
137137
*/
138138
public function getFrom() {
139139
return $this->_from;
140140
}
141+
141142
/**
142-
* Get the document revision (if already known)
143+
* Get the 'to' vertex document-handler (if already known)
143144
*
144-
* @return mixed - revision id, might be NULL if document does not yet have an id
145+
* @return mixed - document-handler
145146
*/
146147
public function getTo() {
147148
return $this->_to;
148149
}
150+
151+
/**
152+
* Set the 'from' vertex document-handler
153+
*
154+
* @param mixed $from - from vertex
155+
* @return Edge - edge object
156+
*/
157+
public function setFrom($from) {
158+
$this->_from=$from;
159+
return $this;
160+
}
161+
162+
/**
163+
* Set the 'to' vertex document-handler
164+
*
165+
* @param mixed $to - to vertex
166+
* @return Edge - edge object
167+
*/
168+
public function setTo($to) {
169+
$this->_to=$to;
170+
return $this;
171+
}
149172

150173
}

0 commit comments

Comments
 (0)