Skip to content

Commit d387cbe

Browse files
committed
Merge branch 'devel' into 1.3
2 parents bee19ec + 8b61478 commit d387cbe

17 files changed

+406
-277
lines changed

lib/triagens/ArangoDb/AqlUserFunction.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,12 @@ public function register($name = null, $code = null)
120120
$attributes = $this->attributes;
121121

122122

123-
if (is_null($name)) {
124-
$attributes['name'] = $this->getName();
123+
if ($name) {
124+
$attributes['name'] = $name;
125125
}
126-
if (is_null($code)) {
127-
$attributes['code'] = $this->getCode();
126+
127+
if ($code) {
128+
$attributes['code'] = $code;
128129
}
129130

130131
$response = $this->_connection->post(
@@ -144,18 +145,24 @@ public function register($name = null, $code = null)
144145
*
145146
* If $name is passed, it will override the object's property with the passed one
146147
*
147-
* @param null $name
148+
* @param string $name
149+
* @param boolean $namespace
148150
*
149151
* @throws Exception throw exception if the request fails
150152
*
151153
* @return mixed true if successful without a return value or the return value if one was set in the action
152154
*/
153-
public function unregister($name = null)
155+
public function unregister($name = null, $namespace = false)
154156
{
155157
if (is_null($name)) {
156158
$name = $this->getName();
157159
}
158-
$url = UrlHelper::buildUrl(Urls::URL_AQL_USER_FUNCTION, $name);
160+
161+
$url = UrlHelper::buildUrl(Urls::URL_AQL_USER_FUNCTION, array($name));
162+
163+
if($namespace){
164+
$url = UrlHelper::appendParamsUrl($url, array('group' => true));
165+
}
159166

160167
$response = $this->_connection->delete($url);
161168
$responseArray = $response->getJson();
@@ -177,8 +184,8 @@ public function unregister($name = null)
177184
*/
178185
public function getRegisteredUserFunctions($namespace = null)
179186
{
180-
$url = UrlHelper::buildUrl(Urls::URL_AQL_USER_FUNCTION);
181-
if (is_null($namespace)) {
187+
$url = UrlHelper::buildUrl(Urls::URL_AQL_USER_FUNCTION, array());
188+
if (!is_null($namespace)) {
182189
$url = UrlHelper::appendParamsUrl($url, array('namespace' => $namespace));
183190
}
184191
$response = $this->_connection->get($url);

lib/triagens/ArangoDb/CollectionHandler.php

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class CollectionHandler extends
215215
*/
216216
public function get($collectionId)
217217
{
218-
$url = UrlHelper::buildUrl(Urls::URL_COLLECTION, $collectionId);
218+
$url = UrlHelper::buildUrl(Urls::URL_COLLECTION, array($collectionId));
219219
$response = $this->getConnection()->get($url);
220220

221221
$data = $response->getJson();
@@ -237,7 +237,7 @@ public function get($collectionId)
237237
*/
238238
public function getProperties($collectionId)
239239
{
240-
$url = UrlHelper::buildUrl(Urls::URL_COLLECTION, $collectionId, self::OPTION_PROPERTIES);
240+
$url = UrlHelper::buildUrl(Urls::URL_COLLECTION, array($collectionId, self::OPTION_PROPERTIES));
241241
$response = $this->getConnection()->get($url);
242242

243243
$data = $response->getJson();
@@ -278,7 +278,7 @@ public function getCount($collectionId)
278278
*/
279279
public function count($collectionId)
280280
{
281-
$url = UrlHelper::buildUrl(Urls::URL_COLLECTION, $collectionId, self::OPTION_COUNT);
281+
$url = UrlHelper::buildUrl(Urls::URL_COLLECTION, array($collectionId, self::OPTION_COUNT));
282282
$response = $this->getConnection()->get($url);
283283

284284
$data = $response->getJson();
@@ -320,7 +320,7 @@ public function getFigures($collectionId)
320320
*/
321321
public function figures($collectionId)
322322
{
323-
$url = UrlHelper::buildUrl(Urls::URL_COLLECTION, $collectionId, self::OPTION_FIGURES);
323+
$url = UrlHelper::buildUrl(Urls::URL_COLLECTION, array($collectionId, self::OPTION_FIGURES));
324324
$response = $this->getConnection()->get($url);
325325

326326
$data = $response->getJson();
@@ -605,7 +605,7 @@ public function index($collectionId, $type = "", $attributes = array(), $unique
605605
*/
606606
public function getIndex($collection, $indexId)
607607
{
608-
$url = UrlHelper::buildUrl(Urls::URL_INDEX, $collection, $indexId);
608+
$url = UrlHelper::buildUrl(Urls::URL_INDEX, array($collection, $indexId));
609609
$response = $this->getConnection()->get($url);
610610

611611
$data = $response->getJson();
@@ -648,7 +648,7 @@ public function getIndexes($collectionId)
648648
public function dropIndex($indexHandle)
649649
{
650650
$handle = explode("/", $indexHandle);
651-
$this->getConnection()->delete(UrlHelper::buildUrl(Urls::URL_INDEX, $handle[0], $handle[1]));
651+
$this->getConnection()->delete(UrlHelper::buildUrl(Urls::URL_INDEX, array($handle[0], $handle[1])));
652652

653653
return true;
654654
}
@@ -688,7 +688,7 @@ public function drop($collection)
688688
throw new ClientException('Cannot alter a collection without a collection id');
689689
}
690690

691-
$this->getConnection()->delete(UrlHelper::buildUrl(Urls::URL_COLLECTION, $collectionName));
691+
$this->getConnection()->delete(UrlHelper::buildUrl(Urls::URL_COLLECTION, array($collectionName)));
692692

693693
return true;
694694
}
@@ -713,7 +713,7 @@ public function rename($collection, $name)
713713

714714
$params = array(Collection::ENTRY_NAME => $name);
715715
$this->getConnection()->put(
716-
UrlHelper::buildUrl(Urls::URL_COLLECTION, $collectionId, self::OPTION_RENAME),
716+
UrlHelper::buildUrl(Urls::URL_COLLECTION, array($collectionId, self::OPTION_RENAME)),
717717
$this->json_encode_wrapper($params)
718718
);
719719

@@ -740,7 +740,7 @@ public function load($collection)
740740
}
741741

742742
$result = $this->getConnection()->put(
743-
UrlHelper::buildUrl(Urls::URL_COLLECTION, $collectionId, self::OPTION_LOAD),
743+
UrlHelper::buildUrl(Urls::URL_COLLECTION, array($collectionId, self::OPTION_LOAD)),
744744
''
745745
);
746746

@@ -768,7 +768,7 @@ public function unload($collection)
768768
}
769769

770770
$result = $this->getConnection()->put(
771-
UrlHelper::buildUrl(Urls::URL_COLLECTION, $collectionId, self::OPTION_UNLOAD),
771+
UrlHelper::buildUrl(Urls::URL_COLLECTION, array($collectionId, self::OPTION_UNLOAD)),
772772
''
773773
);
774774

@@ -796,7 +796,7 @@ public function truncate($collection)
796796
}
797797

798798
$this->getConnection()->put(
799-
UrlHelper::buildUrl(Urls::URL_COLLECTION, $collectionId, self::OPTION_TRUNCATE),
799+
UrlHelper::buildUrl(Urls::URL_COLLECTION, array($collectionId, self::OPTION_TRUNCATE)),
800800
''
801801
);
802802

@@ -1012,7 +1012,7 @@ public function updateByExample($collectionId, $example, $newValue, $options = a
10121012
)
10131013
);
10141014

1015-
#$url = UrlHelper::buildUrl(Urls::URL_DOCUMENT, $collectionId);
1015+
#$url = UrlHelper::buildUrl(Urls::URL_DOCUMENT, array($collectionId));
10161016
#$result = $this->getConnection()->patch($url, $this->json_encode_wrapper($body));
10171017

10181018
$response = $this->getConnection()->put(Urls::URL_UPDATE_BY_EXAMPLE, $this->json_encode_wrapper($body));
@@ -1075,7 +1075,7 @@ public function replaceByExample($collectionId, $example, $newValue, $options =
10751075
)
10761076
);
10771077

1078-
#$url = UrlHelper::buildUrl(Urls::URL_DOCUMENT, $collectionId);
1078+
#$url = UrlHelper::buildUrl(Urls::URL_DOCUMENT, array($collectionId));
10791079
#$result = $this->getConnection()->patch($url, $this->json_encode_wrapper($body));
10801080

10811081
$response = $this->getConnection()->put(Urls::URL_REPLACE_BY_EXAMPLE, $this->json_encode_wrapper($body));
@@ -1211,6 +1211,52 @@ public function range($collectionId, $attribute, $left, $right, $options = array
12111211
return new Cursor($this->getConnection(), $response->getJson(), $options);
12121212
}
12131213

1214+
/**
1215+
* Returns all documents of a collection
1216+
*
1217+
* @param mixed $collectionId - collection id as string or number
1218+
* @param array $options - optional array of options.
1219+
* <p>Options are :<br>
1220+
* <li>'_sanitize' - True to remove _id and _rev attributes from result documents. Defaults to false.</li>
1221+
* <li>'sanitize' - Deprecated, please use '_sanitize'.</li>
1222+
* <li>'_hiddenAttributes' - Set an array of hidden attributes for created documents.
1223+
* <li>'hiddenAttributes' - Deprecated, please use '_hiddenAttributes'.</li>
1224+
* <p>
1225+
* This is actually the same as setting hidden attributes using setHiddenAttributes() on a document.<br>
1226+
* The difference is, that if you're returning a resultset of documents, the getAll() is already called<br>
1227+
* and the hidden attributes would not be applied to the attributes.<br>
1228+
* </p>
1229+
*
1230+
* <li>'batchSize' - can optionally be used to tell the server to limit the number of results to be transferred in one batch</li>
1231+
* <li>'skip' - Optional, The number of documents to skip in the query.</li>
1232+
* <li>'limit' - Optional, The maximal amount of documents to return. 'skip' is applied before the limit restriction.</li>
1233+
* </li>
1234+
* </p>
1235+
*
1236+
* @return Cursor - documents
1237+
*/
1238+
public function all($collectionId, $options = array())
1239+
{
1240+
$options = array_merge($options, $this->getCursorOptions($options));
1241+
1242+
$body = array(
1243+
self::OPTION_COLLECTION => $collectionId,
1244+
);
1245+
1246+
$body = $this->includeOptionsInBody(
1247+
$options,
1248+
$body,
1249+
array(
1250+
self::OPTION_LIMIT => null,
1251+
self::OPTION_SKIP => null,
1252+
)
1253+
);
1254+
1255+
$response = $this->getConnection()->put(Urls::URL_ALL, $this->json_encode_wrapper($body));
1256+
1257+
return new Cursor($this->getConnection(), $response->getJson(), $options);
1258+
}
1259+
12141260

12151261
/**
12161262
* Get document(s) by specifying near
@@ -1393,7 +1439,7 @@ public function getAllCollections($options = array())
13931439
$params[self::OPTION_EXCLUDE_SYSTEM] = true;
13941440
}
13951441
$url = UrlHelper::appendParamsUrl(Urls::URL_COLLECTION, $params);
1396-
$response = $this->getConnection()->get(UrlHelper::buildUrl($url));
1442+
$response = $this->getConnection()->get(UrlHelper::buildUrl($url, array()));
13971443
$response = $response->getJson();
13981444
if (isset($options["keys"]) && isset($response[$options["keys"]])) {
13991445
return $response[$options["keys"]];

lib/triagens/ArangoDb/Connection.php

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ private function getHandle()
219219
$handle = $this->_handle;
220220

221221
// check if connection is still valid
222-
if (!feof($handle)) {
222+
if (! feof($handle)) {
223223
// connection still valid
224224
return $handle;
225225
}
@@ -279,14 +279,13 @@ public function parseResponse(HttpResponse $response)
279279

280280
return $response;
281281
}
282-
282+
283283
/**
284284
* Execute an HTTP request and return the results
285285
*
286286
* This function will throw if no connection to the server can be established or if
287287
* there is a problem during data exchange with the server.
288288
*
289-
* The function might temporarily alter the value of the php.ini value 'default_socket_timeout' but
290289
* will restore it.
291290
*
292291
* @throws Exception
@@ -311,9 +310,12 @@ private function executeRequest($method, $url, $data)
311310
} else {
312311
$request = HttpHelper::buildRequest($this->_options, $method, $url, $data);
313312
}
314-
$batchPart = $this->doBatch($method, $request);
315-
if (!is_null($batchPart)) {
316-
return $batchPart;
313+
314+
if ($this->_captureBatch === true) {
315+
$batchPart = $this->doBatch($method, $request);
316+
if (! is_null($batchPart)) {
317+
return $batchPart;
318+
}
317319
}
318320
} else {
319321
$this->_batchRequest = false;
@@ -327,51 +329,53 @@ private function executeRequest($method, $url, $data)
327329

328330
$traceFunc = $this->_options[ConnectionOptions::OPTION_TRACE];
329331
if ($traceFunc) {
330-
331332
// call tracer func
332333
if ($this->_options[ConnectionOptions::OPTION_ENHANCED_TRACE]) {
333-
$parsed = HttpHelper::parseHttpMessage($request);
334-
$traceFunc(new TraceRequest(HttpHelper::parseHeaders($parsed['header']), $method, $url, $data));
334+
list($header) = HttpHelper::parseHttpMessage($request);
335+
$headers = HttpHelper::parseHeaders($header);
336+
$traceFunc(new TraceRequest($headers[2], $method, $url, $data));
335337
} else {
336338
$traceFunc('send', $request);
337339
}
338340
}
339341

340-
// set socket timeout for this scope
341-
$getFunc = function () {
342-
return ini_get('default_socket_timeout');
343-
};
344-
$setFunc = function ($value) {
345-
ini_set('default_socket_timeout', $value);
346-
};
347-
$scope = new Scope($getFunc, $setFunc);
348-
$setFunc($this->_options[ConnectionOptions::OPTION_TIMEOUT]);
342+
349343
// open the socket. note: this might throw if the connection cannot be established
350344
$handle = $this->getHandle();
345+
351346
if ($handle) {
352347
// send data and get response back
348+
349+
if ($traceFunc) {
350+
// only issue syscall if we need it
351+
$startTime = microtime(true);
352+
}
353+
353354
$result = HttpHelper::transfer($handle, $request);
354355

355-
$status = socket_get_status($handle);
356+
if ($traceFunc) {
357+
// only issue syscall if we need it
358+
$timeTaken = microtime(true) - $startTime;
359+
}
356360

357-
if (!$this->_useKeepAlive) {
361+
if (! $this->_useKeepAlive) {
358362
// must close the connection
359363
fclose($handle);
360364
}
361365

362-
$scope->leave();
363-
366+
/*
367+
$status = socket_get_status($handle);
364368
if ($status['timed_out']) {
365369
throw new ClientException('Got a timeout when waiting on the server\'s response');
366370
}
367-
371+
*/
368372
$response = new HttpResponse($result);
369373

370374
if ($traceFunc) {
371375
// call tracer func
372376
if ($this->_options[ConnectionOptions::OPTION_ENHANCED_TRACE]) {
373377
$traceFunc(
374-
new TraceResponse($response->getHeaders(), $response->getHttpCode(), $response->getBody())
378+
new TraceResponse($response->getHeaders(), $response->getHttpCode(), $response->getBody(), $timeTaken)
375379
);
376380
} else {
377381
$traceFunc('receive', $result);
@@ -381,7 +385,6 @@ private function executeRequest($method, $url, $data)
381385
return $response;
382386
}
383387

384-
$scope->leave();
385388
throw new ClientException('Whoops, this should never happen');
386389
}
387390

lib/triagens/ArangoDb/DocumentHandler.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function get($collectionId, $documentId, array $options = array())
8484
*/
8585
public function getById($collectionId, $documentId, array $options = array())
8686
{
87-
$url = UrlHelper::buildUrl(Urls::URL_DOCUMENT, $collectionId, $documentId);
87+
$url = UrlHelper::buildUrl(Urls::URL_DOCUMENT, array($collectionId, $documentId));
8888
$response = $this->getConnection()->get($url);
8989

9090
$data = $response->getJson();
@@ -392,7 +392,7 @@ public function updateById($collectionId, $documentId, Document $document, $opti
392392
$params[ConnectionOptions::OPTION_REVISION] = $revision;
393393
}
394394

395-
$url = UrlHelper::buildUrl(Urls::URL_DOCUMENT, $collectionId, $documentId);
395+
$url = UrlHelper::buildUrl(Urls::URL_DOCUMENT, array($collectionId, $documentId));
396396
$url = UrlHelper::appendParamsUrl($url, $params);
397397
$result = $this->getConnection()->patch($url, $this->json_encode_wrapper($document->getAll()));
398398
$json = $result->getJson();
@@ -478,7 +478,7 @@ public function replaceById($collectionId, $documentId, Document $document, $opt
478478
}
479479

480480
$data = $document->getAll();
481-
$url = UrlHelper::buildUrl(Urls::URL_DOCUMENT, $collectionId, $documentId);
481+
$url = UrlHelper::buildUrl(Urls::URL_DOCUMENT, array($collectionId, $documentId));
482482
$url = UrlHelper::appendParamsUrl($url, $params);
483483
$result = $this->getConnection()->put($url, $this->json_encode_wrapper($data));
484484
$json = $result->getJson();
@@ -597,7 +597,7 @@ public function removeById($collectionId, $documentId, $revision = null, $option
597597
$params[ConnectionOptions::OPTION_REVISION] = $revision;
598598
}
599599

600-
$url = UrlHelper::buildUrl(Urls::URL_DOCUMENT, $collectionId, $documentId);
600+
$url = UrlHelper::buildUrl(Urls::URL_DOCUMENT, array($collectionId, $documentId));
601601
$url = UrlHelper::appendParamsUrl($url, $params);
602602
$this->getConnection()->delete($url);
603603

0 commit comments

Comments
 (0)