Skip to content

Commit 44f211d

Browse files
committed
Added edge related files with initial code.
Theres more to be done Signed-off-by: Frank Mayer <frank@frankmayer.net>
1 parent ad20905 commit 44f211d

File tree

2 files changed

+197
-0
lines changed

2 files changed

+197
-0
lines changed

lib/triagens/ArangoDb/Edge.php

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<?php
2+
3+
/**
4+
* ArangoDB PHP client: single document
5+
*
6+
* @package ArangoDbPhpClient
7+
* @author Jan Steemann
8+
* @copyright Copyright 2012, triagens GmbH, Cologne, Germany
9+
*/
10+
11+
namespace triagens\ArangoDb;
12+
13+
/**
14+
* Value object representing a single collection-based document
15+
*
16+
* @package ArangoDbPhpClient
17+
*/
18+
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+
31+
/**
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
45+
*/
46+
const ENTRY_ID = '_id';
47+
48+
/**
49+
* Revision _rev index
50+
*/
51+
const ENTRY_REV = '_rev';
52+
53+
/**
54+
* Document _from index
55+
*/
56+
57+
const ENTRY_FROM = '_from';
58+
59+
/**
60+
* Revision _to index
61+
*/
62+
const ENTRY_TO = '_to';
63+
64+
65+
/**
66+
* Clone a document
67+
* Returns the clone
68+
*
69+
* @return void
70+
*/
71+
public function __clone() {
72+
$this->_id = NULL;
73+
$this->_rev = NULL;
74+
$this->_to = NULL;
75+
$this->_from = NULL;
76+
77+
// do not change the _changed flag here
78+
}
79+
80+
81+
/**
82+
* Set a document attribute
83+
*
84+
* The key (attribute name) must be a string.
85+
* This will validate the value of the attribute and might throw an
86+
* exception if the value is invalid.
87+
*
88+
* @throws ClientException
89+
* @param string $key - attribute name
90+
* @param mixed $value - value for attribute
91+
* @return void
92+
*/
93+
public function set($key, $value) {
94+
if (!is_string($key)) {
95+
throw new ClientException('Invalid document attribute key');
96+
}
97+
98+
// validate the value passed
99+
ValueValidator::validate($value);
100+
101+
if ($key === self::ENTRY_ID) {
102+
$this->setInternalId($value);
103+
return;
104+
}
105+
106+
if ($key === self::ENTRY_REV) {
107+
$this->setRevision($value);
108+
return;
109+
}
110+
111+
if ($key === self::ENTRY_FROM) {
112+
$this->setInternalId($value);
113+
return;
114+
}
115+
116+
if ($key === self::ENTRY_TO) {
117+
$this->setRevision($value);
118+
return;
119+
}
120+
121+
if (!$this->_changed) {
122+
if (!isset($this->_values[$key]) || $this->_values[$key] !== $value) {
123+
// set changed flag
124+
$this->_changed = true;
125+
}
126+
}
127+
128+
// and store the value
129+
$this->_values[$key] = $value;
130+
}
131+
132+
133+
/**
134+
* Get the document revision (if already known)
135+
*
136+
* @return mixed - revision id, might be NULL if document does not yet have an id
137+
*/
138+
public function getFrom() {
139+
return $this->_from;
140+
}
141+
/**
142+
* Get the document revision (if already known)
143+
*
144+
* @return mixed - revision id, might be NULL if document does not yet have an id
145+
*/
146+
public function getTo() {
147+
return $this->_to;
148+
}
149+
150+
}

lib/triagens/ArangoDb/EdgeHandler.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/**
4+
* ArangoDB PHP client: document handler
5+
*
6+
* @package ArangoDbPhpClient
7+
* @author Jan Steemann
8+
* @author Frank Mayer
9+
* @copyright Copyright 2012, triagens GmbH, Cologne, Germany
10+
*/
11+
12+
namespace triagens\ArangoDb;
13+
14+
/**
15+
* A document handler that fetches documents from the server and
16+
* persists them on the server. It does so by issueing the
17+
* appropriate HTTP requests to the server.
18+
*
19+
* @package ArangoDbPhpClient
20+
*/
21+
class EdgeHandler extends DocumentHandler {
22+
/**
23+
* documents array index
24+
*/
25+
const ENTRY_DOCUMENTS = 'edges';
26+
27+
/**
28+
* collection parameter
29+
*/
30+
const OPTION_COLLECTION = 'collection';
31+
32+
/**
33+
* example parameter
34+
*/
35+
const OPTION_EXAMPLE = 'example';
36+
37+
/**
38+
* Get a single document from a collection
39+
* Alias method for getById()
40+
*
41+
* @throws Exception
42+
* @param mixed $collectionId - collection id as a string or number
43+
* @param mixed $documentId - document identifier
44+
* @return Document - the document fetched from the server
45+
*/
46+
47+
}

0 commit comments

Comments
 (0)