From 7e41087ca33f88fe8f177e952f6c689e4c47d10c Mon Sep 17 00:00:00 2001 From: diabl0 Date: Fri, 10 Mar 2017 10:45:59 +0100 Subject: [PATCH 1/4] SetDocumentClass fluid interface --- lib/ArangoDBClient/Batch.php | 2 ++ lib/ArangoDBClient/BatchPart.php | 2 ++ lib/ArangoDBClient/Cursor.php | 2 ++ lib/ArangoDBClient/Export.php | 2 ++ lib/ArangoDBClient/ExportCursor.php | 2 ++ lib/ArangoDBClient/Handler.php | 2 ++ lib/ArangoDBClient/Statement.php | 2 ++ 7 files changed, 14 insertions(+) diff --git a/lib/ArangoDBClient/Batch.php b/lib/ArangoDBClient/Batch.php index 3e77e01e..bfedd169 100644 --- a/lib/ArangoDBClient/Batch.php +++ b/lib/ArangoDBClient/Batch.php @@ -569,10 +569,12 @@ public function getConnection() * Sets the document class to use * * @param string $class Document class to use + * @return Batch */ public function setDocumentClass($class) { $this->_documentClass = $class; + return $this; } } diff --git a/lib/ArangoDBClient/BatchPart.php b/lib/ArangoDBClient/BatchPart.php index 94b8cc5c..0e0d373f 100644 --- a/lib/ArangoDBClient/BatchPart.php +++ b/lib/ArangoDBClient/BatchPart.php @@ -318,10 +318,12 @@ private function getCursorOptions() * Sets the document class to use * * @param string $class Document class to use + * @return BatchPart */ public function setDocumentClass($class) { $this->_documentClass = $class; + return $this; } } diff --git a/lib/ArangoDBClient/Cursor.php b/lib/ArangoDBClient/Cursor.php index f1a4c3b1..5e13caec 100644 --- a/lib/ArangoDBClient/Cursor.php +++ b/lib/ArangoDBClient/Cursor.php @@ -836,10 +836,12 @@ public function getId() * Sets the document class to use * * @param string $class Document class to use + * @return Cursor */ public function setDocumentClass($class) { $this->_documentClass = $class; + return $this; } } diff --git a/lib/ArangoDBClient/Export.php b/lib/ArangoDBClient/Export.php index b2984c35..a33dea92 100644 --- a/lib/ArangoDBClient/Export.php +++ b/lib/ArangoDBClient/Export.php @@ -274,10 +274,12 @@ private function getCursorOptions() * Sets the document class to use * * @param string $class Document class to use + * @return Export */ public function setDocumentClass($class) { $this->_documentClass = $class; + return $this; } } diff --git a/lib/ArangoDBClient/ExportCursor.php b/lib/ArangoDBClient/ExportCursor.php index c5dd02fe..d6bf0275 100644 --- a/lib/ArangoDBClient/ExportCursor.php +++ b/lib/ArangoDBClient/ExportCursor.php @@ -290,10 +290,12 @@ public function getId() * Sets the document class to use * * @param string $class Document class to use + * @return ExportCursor */ public function setDocumentClass($class) { $this->_documentClass = $class; + return $this; } } diff --git a/lib/ArangoDBClient/Handler.php b/lib/ArangoDBClient/Handler.php index 3d094d8b..88e44a56 100644 --- a/lib/ArangoDBClient/Handler.php +++ b/lib/ArangoDBClient/Handler.php @@ -166,10 +166,12 @@ protected function makeCollection($value) * Sets the document class to use * * @param string $class Document class to use + * @return Handler */ public function setDocumentClass($class) { $this->_documentClass = $class; + return $this; } } diff --git a/lib/ArangoDBClient/Statement.php b/lib/ArangoDBClient/Statement.php index 928e6f72..066fa896 100644 --- a/lib/ArangoDBClient/Statement.php +++ b/lib/ArangoDBClient/Statement.php @@ -558,10 +558,12 @@ private function getCursorOptions() * Sets the document class to use * * @param string $class Document class to use + * @return Statement */ public function setDocumentClass($class) { $this->_documentClass = $class; + return $this; } } From ffccb117fe543694b4ee6f4a3069812cd99e790a Mon Sep 17 00:00:00 2001 From: diabl0 Date: Fri, 10 Mar 2017 17:40:40 +0100 Subject: [PATCH 2/4] timeline cv and piwik parsers --- lib/ArangoDBClient/ConnectionOptions.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/ArangoDBClient/ConnectionOptions.php b/lib/ArangoDBClient/ConnectionOptions.php index 7f6c00e3..fcfd2c18 100644 --- a/lib/ArangoDBClient/ConnectionOptions.php +++ b/lib/ArangoDBClient/ConnectionOptions.php @@ -368,16 +368,12 @@ private function validate() throw new ClientException('port should be an integer'); } - // can use either endpoint or host/port - if (isset($this->_values[self::OPTION_HOST], $this->_values[self::OPTION_ENDPOINT])) { - throw new ClientException('must not specify both host and endpoint'); - } else { - if (isset($this->_values[self::OPTION_HOST]) && !isset($this->_values[self::OPTION_ENDPOINT])) { - // upgrade host/port to an endpoint - $this->_values[self::OPTION_ENDPOINT] = 'tcp://' . $this->_values[self::OPTION_HOST] . ':' . $this->_values[self::OPTION_PORT]; - } + if (isset($this->_values[self::OPTION_HOST]) && !isset($this->_values[self::OPTION_ENDPOINT])) { + // upgrade host/port to an endpoint + $this->_values[self::OPTION_ENDPOINT] = 'tcp://' . $this->_values[self::OPTION_HOST] . ':' . $this->_values[self::OPTION_PORT]; } + // set up a new endpoint, this will also validate it $this->getEndpoint(); From c1bb3a752789b521c54579f86eb0cadcf5830e5b Mon Sep 17 00:00:00 2001 From: diabl0 Date: Fri, 10 Mar 2017 17:54:13 +0100 Subject: [PATCH 3/4] Fixed issue when multiple calls to validate method triggers "must not specify both host and endpoint" exception --- lib/ArangoDBClient/ConnectionOptions.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/ArangoDBClient/ConnectionOptions.php b/lib/ArangoDBClient/ConnectionOptions.php index fcfd2c18..feb454e5 100644 --- a/lib/ArangoDBClient/ConnectionOptions.php +++ b/lib/ArangoDBClient/ConnectionOptions.php @@ -368,12 +368,17 @@ private function validate() throw new ClientException('port should be an integer'); } - if (isset($this->_values[self::OPTION_HOST]) && !isset($this->_values[self::OPTION_ENDPOINT])) { - // upgrade host/port to an endpoint - $this->_values[self::OPTION_ENDPOINT] = 'tcp://' . $this->_values[self::OPTION_HOST] . ':' . $this->_values[self::OPTION_PORT]; + // can use either endpoint or host/port + if (isset($this->_values[self::OPTION_HOST], $this->_values[self::OPTION_ENDPOINT])) { + throw new ClientException('must not specify both host and endpoint'); + } else { + if (isset($this->_values[self::OPTION_HOST]) && !isset($this->_values[self::OPTION_ENDPOINT])) { + // upgrade host/port to an endpoint + $this->_values[self::OPTION_ENDPOINT] = 'tcp://' . $this->_values[self::OPTION_HOST] . ':' . $this->_values[self::OPTION_PORT]; + unset($this->_values[self::OPTION_HOST]); + } } - // set up a new endpoint, this will also validate it $this->getEndpoint(); From bc333c9494451e3cfc974710395de00e6394924c Mon Sep 17 00:00:00 2001 From: diabl0 Date: Thu, 6 Apr 2017 17:05:32 +0200 Subject: [PATCH 4/4] Arango connection errors --- lib/ArangoDBClient/ClientException.php | 56 ++++++++++++++++++++++++++ lib/ArangoDBClient/Connection.php | 4 +- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/lib/ArangoDBClient/ClientException.php b/lib/ArangoDBClient/ClientException.php index 1311c927..eb1ea150 100644 --- a/lib/ArangoDBClient/ClientException.php +++ b/lib/ArangoDBClient/ClientException.php @@ -33,6 +33,62 @@ public function __toString() { return __CLASS__ . ': ' . $this->getMessage(); } + + protected $method, $url, $data; + + /** + * @return mixed + */ + public function getMethod() + { + return $this->method; + } + + /** + * @param mixed $method + * @return ClientException + */ + public function setMethod($method) + { + $this->method = $method; + return $this; + } + + /** + * @return mixed + */ + public function getUrl() + { + return $this->url; + } + + /** + * @param mixed $url + * @return ClientException + */ + public function setUrl($url) + { + $this->url = $url; + return $this; + } + + /** + * @return mixed + */ + public function getData() + { + return $this->data; + } + + /** + * @param mixed $data + * @return ClientException + */ + public function setData($data) + { + $this->data = $data; + return $this; + } } class_alias(ClientException::class, '\triagens\ArangoDb\ClientException'); diff --git a/lib/ArangoDBClient/Connection.php b/lib/ArangoDBClient/Connection.php index 5966ac8e..374dbd05 100644 --- a/lib/ArangoDBClient/Connection.php +++ b/lib/ArangoDBClient/Connection.php @@ -467,7 +467,9 @@ private function executeRequest($method, $url, $data, array $customHeaders = []) $status = socket_get_status($handle); if ($status['timed_out']) { - throw new ClientException('Got a timeout while waiting for the server\'s response', 408); + $exception = new ClientException('Got a timeout while waiting for the server\'s response', 408); + $exception->setUrl($url)->setMethod($method)->setData($data); + throw $exception; } if (!$this->_useKeepAlive) {