repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
arangodb/arangodb-php | lib/ArangoDBClient/Batch.php | Batch.append | public function append($method, $request)
{
preg_match('%/_api/simple/(?P<simple>\w*)|/_api/(?P<direct>\w*)%ix', $request, $regs);
if (!isset($regs['direct'])) {
$regs['direct'] = '';
}
$type = $regs['direct'] !== '' ? $regs['direct'] : $regs['simple'];
if ($method === 'GET' && $type === $regs['direct']) {
$type = 'get' . $type;
}
if (null === $this->_nextBatchPartId) {
if (is_a($this->_batchParts, \SplFixedArray::class)) {
$nextNumeric = $this->_nextId;
$this->_nextId++;
} else {
$nextNumeric = count($this->_batchParts);
}
$batchPartId = $nextNumeric;
} else {
$batchPartId = $this->_nextBatchPartId;
$this->_nextBatchPartId = null;
}
$eol = HttpHelper::EOL;
$result = 'HTTP/1.1 202 Accepted' . $eol;
$result .= 'location: /_db/_system/_api/document/0/0' . $eol;
$result .= 'content-type: application/json; charset=utf-8' . $eol;
$result .= 'etag: "0"' . $eol;
$result .= 'connection: Close' . $eol . $eol;
$result .= '{"error":false,"_id":"0/0","id":"0","_rev":0,"hasMore":1, "result":[{}], "documents":[{}]}' . $eol . $eol;
$response = new HttpResponse($result);
$batchPart = new BatchPart($this, $batchPartId, $type, $request, $response, [
'cursorOptions' => $this->_batchPartCursorOptions,
'_documentClass' => $this->_documentClass,
]);
$this->_batchParts[$batchPartId] = $batchPart;
$response->setBatchPart($batchPart);
return $response;
} | php | public function append($method, $request)
{
preg_match('%/_api/simple/(?P<simple>\w*)|/_api/(?P<direct>\w*)%ix', $request, $regs);
if (!isset($regs['direct'])) {
$regs['direct'] = '';
}
$type = $regs['direct'] !== '' ? $regs['direct'] : $regs['simple'];
if ($method === 'GET' && $type === $regs['direct']) {
$type = 'get' . $type;
}
if (null === $this->_nextBatchPartId) {
if (is_a($this->_batchParts, \SplFixedArray::class)) {
$nextNumeric = $this->_nextId;
$this->_nextId++;
} else {
$nextNumeric = count($this->_batchParts);
}
$batchPartId = $nextNumeric;
} else {
$batchPartId = $this->_nextBatchPartId;
$this->_nextBatchPartId = null;
}
$eol = HttpHelper::EOL;
$result = 'HTTP/1.1 202 Accepted' . $eol;
$result .= 'location: /_db/_system/_api/document/0/0' . $eol;
$result .= 'content-type: application/json; charset=utf-8' . $eol;
$result .= 'etag: "0"' . $eol;
$result .= 'connection: Close' . $eol . $eol;
$result .= '{"error":false,"_id":"0/0","id":"0","_rev":0,"hasMore":1, "result":[{}], "documents":[{}]}' . $eol . $eol;
$response = new HttpResponse($result);
$batchPart = new BatchPart($this, $batchPartId, $type, $request, $response, [
'cursorOptions' => $this->_batchPartCursorOptions,
'_documentClass' => $this->_documentClass,
]);
$this->_batchParts[$batchPartId] = $batchPart;
$response->setBatchPart($batchPart);
return $response;
} | [
"public",
"function",
"append",
"(",
"$",
"method",
",",
"$",
"request",
")",
"{",
"preg_match",
"(",
"'%/_api/simple/(?P<simple>\\w*)|/_api/(?P<direct>\\w*)%ix'",
",",
"$",
"request",
",",
"$",
"regs",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"regs",
"[... | Append the request to the batch-part
@param mixed $method - The method of the request (GET, POST...)
@param mixed $request - The request that will get appended to the batch
@return HttpResponse
@throws \ArangoDBClient\ClientException | [
"Append",
"the",
"request",
"to",
"the",
"batch",
"-",
"part"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Batch.php#L331-L377 |
arangodb/arangodb-php | lib/ArangoDBClient/Batch.php | Batch.splitWithContentIdKey | public function splitWithContentIdKey($pattern, $string)
{
$array = [];
$exploded = explode($pattern, $string);
foreach ($exploded as $key => $value) {
$response = new HttpResponse($value);
$contentId = $response->getHeader('Content-Id');
if (null !== $contentId) {
$array[$contentId] = $value;
} else {
$array[$key] = $value;
}
}
return $array;
} | php | public function splitWithContentIdKey($pattern, $string)
{
$array = [];
$exploded = explode($pattern, $string);
foreach ($exploded as $key => $value) {
$response = new HttpResponse($value);
$contentId = $response->getHeader('Content-Id');
if (null !== $contentId) {
$array[$contentId] = $value;
} else {
$array[$key] = $value;
}
}
return $array;
} | [
"public",
"function",
"splitWithContentIdKey",
"(",
"$",
"pattern",
",",
"$",
"string",
")",
"{",
"$",
"array",
"=",
"[",
"]",
";",
"$",
"exploded",
"=",
"explode",
"(",
"$",
"pattern",
",",
"$",
"string",
")",
";",
"foreach",
"(",
"$",
"exploded",
"... | Split batch request and use ContentId as array key
@param mixed $pattern
@param mixed $string
@return array $array - Array of batch-parts
@throws \ArangoDBClient\ClientException | [
"Split",
"batch",
"request",
"and",
"use",
"ContentId",
"as",
"array",
"key"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Batch.php#L390-L406 |
arangodb/arangodb-php | lib/ArangoDBClient/Batch.php | Batch.process | public function process()
{
if ($this->isCapturing()) {
$this->stopCapture();
}
$this->setBatchRequest(true);
$data = '';
$batchParts = $this->getBatchParts();
if (count($batchParts) === 0) {
throw new ClientException('Can\'t process empty batch.');
}
$combinedDataHeader = '--' . HttpHelper::MIME_BOUNDARY . HttpHelper::EOL;
$combinedDataHeader .= 'Content-Type: application/x-arango-batchpart' . HttpHelper::EOL;
/** @var $partValue BatchPart */
foreach ($batchParts as $partValue) {
if (null !== $partValue) {
$data .= $combinedDataHeader;
if (null !== $partValueId = $partValue->getId()) {
$data .= 'Content-Id: ' . (string) $partValueId . HttpHelper::SEPARATOR;
} else {
$data .= HttpHelper::EOL;
}
$data .= (string) $partValue->getRequest() . HttpHelper::EOL;
}
}
$data .= '--' . HttpHelper::MIME_BOUNDARY . '--' . HttpHelper::SEPARATOR;
$params = [];
$url = UrlHelper::appendParamsUrl(Urls::URL_BATCH, $params);
$this->_batchResponse = $this->_connection->post($url, $data);
if ($this->_batchResponse->getHttpCode() !== 200) {
return $this->_batchResponse;
}
$body = $this->_batchResponse->getBody();
$body = trim($body, '--' . HttpHelper::MIME_BOUNDARY . '--');
$batchParts = $this->splitWithContentIdKey('--' . HttpHelper::MIME_BOUNDARY . HttpHelper::EOL, $body);
foreach ($batchParts as $partKey => $partValue) {
$response = new HttpResponse($partValue);
$body = $response->getBody();
$response = new HttpResponse($body);
$batchPartResponses[$partKey] = $response;
$this->getPart($partKey)->setResponse($batchPartResponses[$partKey]);
}
return $this;
} | php | public function process()
{
if ($this->isCapturing()) {
$this->stopCapture();
}
$this->setBatchRequest(true);
$data = '';
$batchParts = $this->getBatchParts();
if (count($batchParts) === 0) {
throw new ClientException('Can\'t process empty batch.');
}
$combinedDataHeader = '--' . HttpHelper::MIME_BOUNDARY . HttpHelper::EOL;
$combinedDataHeader .= 'Content-Type: application/x-arango-batchpart' . HttpHelper::EOL;
/** @var $partValue BatchPart */
foreach ($batchParts as $partValue) {
if (null !== $partValue) {
$data .= $combinedDataHeader;
if (null !== $partValueId = $partValue->getId()) {
$data .= 'Content-Id: ' . (string) $partValueId . HttpHelper::SEPARATOR;
} else {
$data .= HttpHelper::EOL;
}
$data .= (string) $partValue->getRequest() . HttpHelper::EOL;
}
}
$data .= '--' . HttpHelper::MIME_BOUNDARY . '--' . HttpHelper::SEPARATOR;
$params = [];
$url = UrlHelper::appendParamsUrl(Urls::URL_BATCH, $params);
$this->_batchResponse = $this->_connection->post($url, $data);
if ($this->_batchResponse->getHttpCode() !== 200) {
return $this->_batchResponse;
}
$body = $this->_batchResponse->getBody();
$body = trim($body, '--' . HttpHelper::MIME_BOUNDARY . '--');
$batchParts = $this->splitWithContentIdKey('--' . HttpHelper::MIME_BOUNDARY . HttpHelper::EOL, $body);
foreach ($batchParts as $partKey => $partValue) {
$response = new HttpResponse($partValue);
$body = $response->getBody();
$response = new HttpResponse($body);
$batchPartResponses[$partKey] = $response;
$this->getPart($partKey)->setResponse($batchPartResponses[$partKey]);
}
return $this;
} | [
"public",
"function",
"process",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isCapturing",
"(",
")",
")",
"{",
"$",
"this",
"->",
"stopCapture",
"(",
")",
";",
"}",
"$",
"this",
"->",
"setBatchRequest",
"(",
"true",
")",
";",
"$",
"data",
"=",
... | Processes this batch. This sends the captured requests to the server as one batch.
@return HttpResponse|Batch - Batch if processing of the batch was successful or the HttpResponse object in case of a failure. A successful process just means that tha parts were processed. Each part has it's own response though and should be checked on its own.
@throws ClientException
@throws \ArangoDBClient\Exception | [
"Processes",
"this",
"batch",
".",
"This",
"sends",
"the",
"captured",
"requests",
"to",
"the",
"server",
"as",
"one",
"batch",
"."
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Batch.php#L417-L471 |
arangodb/arangodb-php | lib/ArangoDBClient/Batch.php | Batch.getPart | public function getPart($partId)
{
if (!isset($this->_batchParts[$partId])) {
throw new ClientException('Request batch part does not exist.');
}
return $this->_batchParts[$partId];
} | php | public function getPart($partId)
{
if (!isset($this->_batchParts[$partId])) {
throw new ClientException('Request batch part does not exist.');
}
return $this->_batchParts[$partId];
} | [
"public",
"function",
"getPart",
"(",
"$",
"partId",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_batchParts",
"[",
"$",
"partId",
"]",
")",
")",
"{",
"throw",
"new",
"ClientException",
"(",
"'Request batch part does not exist.'",
")",
";",... | Get the batch part identified by the array key (0...n) or its id (if it was set with nextBatchPartId($id) )
@param mixed $partId the batch part id. Either it's numeric key or a given name.
@return mixed $batchPart
@throws ClientException | [
"Get",
"the",
"batch",
"part",
"identified",
"by",
"the",
"array",
"key",
"(",
"0",
"...",
"n",
")",
"or",
"its",
"id",
"(",
"if",
"it",
"was",
"set",
"with",
"nextBatchPartId",
"(",
"$id",
")",
")"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Batch.php#L494-L501 |
arangodb/arangodb-php | lib/ArangoDBClient/ValueValidator.php | ValueValidator.validate | public static function validate($value)
{
if (is_string($value) || is_int($value) || is_float($value) || is_bool($value) || null === $value) {
// type is allowed
return;
}
if (is_array($value)) {
// must check all elements contained
foreach ($value as $subValue) {
self::validate($subValue);
}
return;
}
// type is invalid
throw new ClientException('Invalid bind parameter value');
} | php | public static function validate($value)
{
if (is_string($value) || is_int($value) || is_float($value) || is_bool($value) || null === $value) {
// type is allowed
return;
}
if (is_array($value)) {
// must check all elements contained
foreach ($value as $subValue) {
self::validate($subValue);
}
return;
}
// type is invalid
throw new ClientException('Invalid bind parameter value');
} | [
"public",
"static",
"function",
"validate",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
"||",
"is_int",
"(",
"$",
"value",
")",
"||",
"is_float",
"(",
"$",
"value",
")",
"||",
"is_bool",
"(",
"$",
"value",
")",
"||"... | Validate the value of a variable
Allowed value types are string, integer, double and boolean. Arrays are also allowed if they contain only one of the former types.
@throws ClientException
@param mixed $value - value to validate
@return void - will throw if an invalid value type is passed | [
"Validate",
"the",
"value",
"of",
"a",
"variable"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/ValueValidator.php#L32-L50 |
arangodb/arangodb-php | lib/ArangoDBClient/ConnectionOptions.php | ConnectionOptions.offsetGet | public function offsetGet($offset)
{
if (!array_key_exists($offset, $this->_values)) {
throw new ClientException('Invalid option ' . $offset);
}
return $this->_values[$offset];
} | php | public function offsetGet($offset)
{
if (!array_key_exists($offset, $this->_values)) {
throw new ClientException('Invalid option ' . $offset);
}
return $this->_values[$offset];
} | [
"public",
"function",
"offsetGet",
"(",
"$",
"offset",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"offset",
",",
"$",
"this",
"->",
"_values",
")",
")",
"{",
"throw",
"new",
"ClientException",
"(",
"'Invalid option '",
".",
"$",
"offset",
")... | Get a specific option, necessary for ArrayAccess
@throws ClientException
@param string $offset - name of option
@return mixed - value of option, will throw if option is not set | [
"Get",
"a",
"specific",
"option",
"necessary",
"for",
"ArrayAccess"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/ConnectionOptions.php#L335-L342 |
arangodb/arangodb-php | lib/ArangoDBClient/ConnectionOptions.php | ConnectionOptions.getCurrentEndpoint | public function getCurrentEndpoint()
{
assert(is_array($this->_values[self::OPTION_ENDPOINT]));
return $this->_values[self::OPTION_ENDPOINT][$this->_currentEndpointIndex];
} | php | public function getCurrentEndpoint()
{
assert(is_array($this->_values[self::OPTION_ENDPOINT]));
return $this->_values[self::OPTION_ENDPOINT][$this->_currentEndpointIndex];
} | [
"public",
"function",
"getCurrentEndpoint",
"(",
")",
"{",
"assert",
"(",
"is_array",
"(",
"$",
"this",
"->",
"_values",
"[",
"self",
"::",
"OPTION_ENDPOINT",
"]",
")",
")",
";",
"return",
"$",
"this",
"->",
"_values",
"[",
"self",
"::",
"OPTION_ENDPOINT",... | Get the current endpoint to use
@return string - Endpoint string to connect to | [
"Get",
"the",
"current",
"endpoint",
"to",
"use"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/ConnectionOptions.php#L349-L353 |
arangodb/arangodb-php | lib/ArangoDBClient/ConnectionOptions.php | ConnectionOptions.haveMultipleEndpoints | public function haveMultipleEndpoints()
{
assert(is_array($this->_values[self::OPTION_ENDPOINT]));
return count($this->_values[self::OPTION_ENDPOINT]) > 1;
} | php | public function haveMultipleEndpoints()
{
assert(is_array($this->_values[self::OPTION_ENDPOINT]));
return count($this->_values[self::OPTION_ENDPOINT]) > 1;
} | [
"public",
"function",
"haveMultipleEndpoints",
"(",
")",
"{",
"assert",
"(",
"is_array",
"(",
"$",
"this",
"->",
"_values",
"[",
"self",
"::",
"OPTION_ENDPOINT",
"]",
")",
")",
";",
"return",
"count",
"(",
"$",
"this",
"->",
"_values",
"[",
"self",
"::",... | Whether or not we have multiple endpoints to connect to
@return bool - true if we have more than one endpoint to connect to | [
"Whether",
"or",
"not",
"we",
"have",
"multiple",
"endpoints",
"to",
"connect",
"to"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/ConnectionOptions.php#L360-L364 |
arangodb/arangodb-php | lib/ArangoDBClient/ConnectionOptions.php | ConnectionOptions.addEndpoint | public function addEndpoint($endpoint)
{
if (!is_string($endpoint) || !Endpoint::isValid($endpoint)) {
throw new ClientException(sprintf("invalid endpoint specification '%s'", $endpoint));
}
$endpoint = Endpoint::normalize($endpoint);
$normalized = Endpoint::normalizeHostname($endpoint);
assert(is_array($this->_values[self::OPTION_ENDPOINT]));
$found = false;
foreach ($this->_values[self::OPTION_ENDPOINT] as $key => $value) {
if ($normalized === Endpoint::normalizeHostname($value)) {
$this->_currentEndpointIndex = $key;
$found = true;
break;
}
}
if ($found === false) {
// a new endpoint we have not seen before
$this->_values[self::OPTION_ENDPOINT][] = $endpoint;
$this->_currentEndpointIndex = count($this->_values[self::OPTION_ENDPOINT]) - 1;
}
$this->storeOptionsInCache();
} | php | public function addEndpoint($endpoint)
{
if (!is_string($endpoint) || !Endpoint::isValid($endpoint)) {
throw new ClientException(sprintf("invalid endpoint specification '%s'", $endpoint));
}
$endpoint = Endpoint::normalize($endpoint);
$normalized = Endpoint::normalizeHostname($endpoint);
assert(is_array($this->_values[self::OPTION_ENDPOINT]));
$found = false;
foreach ($this->_values[self::OPTION_ENDPOINT] as $key => $value) {
if ($normalized === Endpoint::normalizeHostname($value)) {
$this->_currentEndpointIndex = $key;
$found = true;
break;
}
}
if ($found === false) {
// a new endpoint we have not seen before
$this->_values[self::OPTION_ENDPOINT][] = $endpoint;
$this->_currentEndpointIndex = count($this->_values[self::OPTION_ENDPOINT]) - 1;
}
$this->storeOptionsInCache();
} | [
"public",
"function",
"addEndpoint",
"(",
"$",
"endpoint",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"endpoint",
")",
"||",
"!",
"Endpoint",
"::",
"isValid",
"(",
"$",
"endpoint",
")",
")",
"{",
"throw",
"new",
"ClientException",
"(",
"sprintf",
... | Add a new endpoint to the list of endpoints
if the endpoint is already in the list, it will not be added again
as a side-effect, this method will modify _currentEndpointIndex
@param string $endpoint - the endpoint to add
@return void | [
"Add",
"a",
"new",
"endpoint",
"to",
"the",
"list",
"of",
"endpoints",
"if",
"the",
"endpoint",
"is",
"already",
"in",
"the",
"list",
"it",
"will",
"not",
"be",
"added",
"again",
"as",
"a",
"side",
"-",
"effect",
"this",
"method",
"will",
"modify",
"_c... | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/ConnectionOptions.php#L375-L400 |
arangodb/arangodb-php | lib/ArangoDBClient/ConnectionOptions.php | ConnectionOptions.nextEndpoint | public function nextEndpoint()
{
assert(is_array($this->_values[self::OPTION_ENDPOINT]));
$endpoints = $this->_values[self::OPTION_ENDPOINT];
$numberOfEndpoints = count($endpoints);
$this->_currentEndpointIndex++;
if ($this->_currentEndpointIndex >= $numberOfEndpoints) {
$this->_currentEndpointIndex = 0;
}
$endpoint = $endpoints[$this->_currentEndpointIndex];
if ($numberOfEndpoints > 1) {
$this->storeOptionsInCache();
}
return $endpoint;
} | php | public function nextEndpoint()
{
assert(is_array($this->_values[self::OPTION_ENDPOINT]));
$endpoints = $this->_values[self::OPTION_ENDPOINT];
$numberOfEndpoints = count($endpoints);
$this->_currentEndpointIndex++;
if ($this->_currentEndpointIndex >= $numberOfEndpoints) {
$this->_currentEndpointIndex = 0;
}
$endpoint = $endpoints[$this->_currentEndpointIndex];
if ($numberOfEndpoints > 1) {
$this->storeOptionsInCache();
}
return $endpoint;
} | [
"public",
"function",
"nextEndpoint",
"(",
")",
"{",
"assert",
"(",
"is_array",
"(",
"$",
"this",
"->",
"_values",
"[",
"self",
"::",
"OPTION_ENDPOINT",
"]",
")",
")",
";",
"$",
"endpoints",
"=",
"$",
"this",
"->",
"_values",
"[",
"self",
"::",
"OPTION... | Return the next endpoint from the list of endpoints
As a side-effect this function switches to a new endpoint
@return string - the next endpoint | [
"Return",
"the",
"next",
"endpoint",
"from",
"the",
"list",
"of",
"endpoints",
"As",
"a",
"side",
"-",
"effect",
"this",
"function",
"switches",
"to",
"a",
"new",
"endpoint"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/ConnectionOptions.php#L408-L427 |
arangodb/arangodb-php | lib/ArangoDBClient/ConnectionOptions.php | ConnectionOptions.getDefaults | private static function getDefaults()
{
return [
self::OPTION_ENDPOINT => [ ],
self::OPTION_HOST => null,
self::OPTION_PORT => DefaultValues::DEFAULT_PORT,
self::OPTION_FAILOVER_TRIES => DefaultValues::DEFAULT_FAILOVER_TRIES,
self::OPTION_FAILOVER_TIMEOUT => DefaultValues::DEFAULT_FAILOVER_TIMEOUT,
self::OPTION_TIMEOUT => DefaultValues::DEFAULT_TIMEOUT,
self::OPTION_MEMCACHED_PERSISTENT_ID => 'arangodb-php-pool',
self::OPTION_MEMCACHED_OPTIONS => [ ],
self::OPTION_MEMCACHED_ENDPOINTS_KEY => 'arangodb-php-endpoints',
self::OPTION_MEMCACHED_TTL => 600,
self::OPTION_CREATE => DefaultValues::DEFAULT_CREATE,
self::OPTION_UPDATE_POLICY => DefaultValues::DEFAULT_UPDATE_POLICY,
self::OPTION_REPLACE_POLICY => DefaultValues::DEFAULT_REPLACE_POLICY,
self::OPTION_DELETE_POLICY => DefaultValues::DEFAULT_DELETE_POLICY,
self::OPTION_REVISION => null,
self::OPTION_WAIT_SYNC => DefaultValues::DEFAULT_WAIT_SYNC,
self::OPTION_BATCHSIZE => null,
self::OPTION_JOURNAL_SIZE => DefaultValues::DEFAULT_JOURNAL_SIZE,
self::OPTION_IS_SYSTEM => false,
self::OPTION_IS_VOLATILE => DefaultValues::DEFAULT_IS_VOLATILE,
self::OPTION_CONNECTION => DefaultValues::DEFAULT_CONNECTION,
self::OPTION_TRACE => null,
self::OPTION_ENHANCED_TRACE => false,
self::OPTION_VERIFY_CERT => DefaultValues::DEFAULT_VERIFY_CERT,
self::OPTION_VERIFY_CERT_NAME => DefaultValues::DEFAULT_VERIFY_CERT_NAME,
self::OPTION_ALLOW_SELF_SIGNED => DefaultValues::DEFAULT_ALLOW_SELF_SIGNED,
self::OPTION_CIPHERS => DefaultValues::DEFAULT_CIPHERS,
self::OPTION_AUTH_USER => null,
self::OPTION_AUTH_PASSWD => null,
self::OPTION_AUTH_TYPE => DefaultValues::DEFAULT_AUTH_TYPE,
self::OPTION_RECONNECT => false,
self::OPTION_BATCH => false,
self::OPTION_BATCHPART => false,
self::OPTION_DATABASE => '_system',
self::OPTION_CHECK_UTF8_CONFORM => DefaultValues::DEFAULT_CHECK_UTF8_CONFORM,
self::OPTION_NOTIFY_CALLBACK => function ($message) {}
];
} | php | private static function getDefaults()
{
return [
self::OPTION_ENDPOINT => [ ],
self::OPTION_HOST => null,
self::OPTION_PORT => DefaultValues::DEFAULT_PORT,
self::OPTION_FAILOVER_TRIES => DefaultValues::DEFAULT_FAILOVER_TRIES,
self::OPTION_FAILOVER_TIMEOUT => DefaultValues::DEFAULT_FAILOVER_TIMEOUT,
self::OPTION_TIMEOUT => DefaultValues::DEFAULT_TIMEOUT,
self::OPTION_MEMCACHED_PERSISTENT_ID => 'arangodb-php-pool',
self::OPTION_MEMCACHED_OPTIONS => [ ],
self::OPTION_MEMCACHED_ENDPOINTS_KEY => 'arangodb-php-endpoints',
self::OPTION_MEMCACHED_TTL => 600,
self::OPTION_CREATE => DefaultValues::DEFAULT_CREATE,
self::OPTION_UPDATE_POLICY => DefaultValues::DEFAULT_UPDATE_POLICY,
self::OPTION_REPLACE_POLICY => DefaultValues::DEFAULT_REPLACE_POLICY,
self::OPTION_DELETE_POLICY => DefaultValues::DEFAULT_DELETE_POLICY,
self::OPTION_REVISION => null,
self::OPTION_WAIT_SYNC => DefaultValues::DEFAULT_WAIT_SYNC,
self::OPTION_BATCHSIZE => null,
self::OPTION_JOURNAL_SIZE => DefaultValues::DEFAULT_JOURNAL_SIZE,
self::OPTION_IS_SYSTEM => false,
self::OPTION_IS_VOLATILE => DefaultValues::DEFAULT_IS_VOLATILE,
self::OPTION_CONNECTION => DefaultValues::DEFAULT_CONNECTION,
self::OPTION_TRACE => null,
self::OPTION_ENHANCED_TRACE => false,
self::OPTION_VERIFY_CERT => DefaultValues::DEFAULT_VERIFY_CERT,
self::OPTION_VERIFY_CERT_NAME => DefaultValues::DEFAULT_VERIFY_CERT_NAME,
self::OPTION_ALLOW_SELF_SIGNED => DefaultValues::DEFAULT_ALLOW_SELF_SIGNED,
self::OPTION_CIPHERS => DefaultValues::DEFAULT_CIPHERS,
self::OPTION_AUTH_USER => null,
self::OPTION_AUTH_PASSWD => null,
self::OPTION_AUTH_TYPE => DefaultValues::DEFAULT_AUTH_TYPE,
self::OPTION_RECONNECT => false,
self::OPTION_BATCH => false,
self::OPTION_BATCHPART => false,
self::OPTION_DATABASE => '_system',
self::OPTION_CHECK_UTF8_CONFORM => DefaultValues::DEFAULT_CHECK_UTF8_CONFORM,
self::OPTION_NOTIFY_CALLBACK => function ($message) {}
];
} | [
"private",
"static",
"function",
"getDefaults",
"(",
")",
"{",
"return",
"[",
"self",
"::",
"OPTION_ENDPOINT",
"=>",
"[",
"]",
",",
"self",
"::",
"OPTION_HOST",
"=>",
"null",
",",
"self",
"::",
"OPTION_PORT",
"=>",
"DefaultValues",
"::",
"DEFAULT_PORT",
",",... | Get the default values for the options
@return array - array of default connection options | [
"Get",
"the",
"default",
"values",
"for",
"the",
"options"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/ConnectionOptions.php#L434-L474 |
arangodb/arangodb-php | lib/ArangoDBClient/ConnectionOptions.php | ConnectionOptions.validate | private function validate()
{
if (isset($this->_values[self::OPTION_HOST]) && !is_string($this->_values[self::OPTION_HOST])) {
throw new ClientException('host should be a string');
}
if (isset($this->_values[self::OPTION_PORT]) && !is_int($this->_values[self::OPTION_PORT])) {
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');
}
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]);
}
if (!is_array($this->_values[self::OPTION_ENDPOINT])) {
// make sure that we always have an array of endpoints
$this->_values[self::OPTION_ENDPOINT] = [ $this->_values[self::OPTION_ENDPOINT] ];
}
assert(is_array($this->_values[self::OPTION_ENDPOINT]));
foreach ($this->_values[self::OPTION_ENDPOINT] as $key => $value) {
$this->_values[self::OPTION_ENDPOINT][$key] = Endpoint::normalize($value);
}
if (count($this->_values[self::OPTION_ENDPOINT]) > 1) {
// when we have more than a single endpoint, we must always use the reconnect option
$this->_values[ConnectionOptions::OPTION_RECONNECT] = true;
}
// validate endpoint
$ep = $this->getCurrentEndpoint();
if (!Endpoint::isValid($ep)) {
throw new ClientException(sprintf("invalid endpoint specification '%s'", $ep));
}
$type = Endpoint::getType($ep);
if ($type === Endpoint::TYPE_UNIX) {
// must set port to 0 for UNIX domain sockets
$this->_values[self::OPTION_PORT] = 0;
} elseif ($type === Endpoint::TYPE_SSL) {
// must set port to 0 for SSL connections
$this->_values[self::OPTION_PORT] = 0;
} else {
if (preg_match("/:(\d+)$/", $ep, $match)) {
// get port number from endpoint, to not confuse developers when dumping
// connection details
$this->_values[self::OPTION_PORT] = (int) $match[1];
}
}
if (isset($this->_values[self::OPTION_AUTH_TYPE]) && !in_array(
$this->_values[self::OPTION_AUTH_TYPE],
self::getSupportedAuthTypes(), true
)
) {
throw new ClientException('unsupported authorization method');
}
if (isset($this->_values[self::OPTION_CONNECTION]) && !in_array(
$this->_values[self::OPTION_CONNECTION],
self::getSupportedConnectionTypes(), true
)
) {
throw new ClientException(
sprintf(
"unsupported connection value '%s'",
$this->_values[self::OPTION_CONNECTION]
)
);
}
UpdatePolicy::validate($this->_values[self::OPTION_UPDATE_POLICY]);
UpdatePolicy::validate($this->_values[self::OPTION_REPLACE_POLICY]);
UpdatePolicy::validate($this->_values[self::OPTION_DELETE_POLICY]);
} | php | private function validate()
{
if (isset($this->_values[self::OPTION_HOST]) && !is_string($this->_values[self::OPTION_HOST])) {
throw new ClientException('host should be a string');
}
if (isset($this->_values[self::OPTION_PORT]) && !is_int($this->_values[self::OPTION_PORT])) {
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');
}
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]);
}
if (!is_array($this->_values[self::OPTION_ENDPOINT])) {
// make sure that we always have an array of endpoints
$this->_values[self::OPTION_ENDPOINT] = [ $this->_values[self::OPTION_ENDPOINT] ];
}
assert(is_array($this->_values[self::OPTION_ENDPOINT]));
foreach ($this->_values[self::OPTION_ENDPOINT] as $key => $value) {
$this->_values[self::OPTION_ENDPOINT][$key] = Endpoint::normalize($value);
}
if (count($this->_values[self::OPTION_ENDPOINT]) > 1) {
// when we have more than a single endpoint, we must always use the reconnect option
$this->_values[ConnectionOptions::OPTION_RECONNECT] = true;
}
// validate endpoint
$ep = $this->getCurrentEndpoint();
if (!Endpoint::isValid($ep)) {
throw new ClientException(sprintf("invalid endpoint specification '%s'", $ep));
}
$type = Endpoint::getType($ep);
if ($type === Endpoint::TYPE_UNIX) {
// must set port to 0 for UNIX domain sockets
$this->_values[self::OPTION_PORT] = 0;
} elseif ($type === Endpoint::TYPE_SSL) {
// must set port to 0 for SSL connections
$this->_values[self::OPTION_PORT] = 0;
} else {
if (preg_match("/:(\d+)$/", $ep, $match)) {
// get port number from endpoint, to not confuse developers when dumping
// connection details
$this->_values[self::OPTION_PORT] = (int) $match[1];
}
}
if (isset($this->_values[self::OPTION_AUTH_TYPE]) && !in_array(
$this->_values[self::OPTION_AUTH_TYPE],
self::getSupportedAuthTypes(), true
)
) {
throw new ClientException('unsupported authorization method');
}
if (isset($this->_values[self::OPTION_CONNECTION]) && !in_array(
$this->_values[self::OPTION_CONNECTION],
self::getSupportedConnectionTypes(), true
)
) {
throw new ClientException(
sprintf(
"unsupported connection value '%s'",
$this->_values[self::OPTION_CONNECTION]
)
);
}
UpdatePolicy::validate($this->_values[self::OPTION_UPDATE_POLICY]);
UpdatePolicy::validate($this->_values[self::OPTION_REPLACE_POLICY]);
UpdatePolicy::validate($this->_values[self::OPTION_DELETE_POLICY]);
} | [
"private",
"function",
"validate",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_values",
"[",
"self",
"::",
"OPTION_HOST",
"]",
")",
"&&",
"!",
"is_string",
"(",
"$",
"this",
"->",
"_values",
"[",
"self",
"::",
"OPTION_HOST",
"]",
")"... | Validate the options
@throws ClientException
@return void - will throw if an invalid option value is found | [
"Validate",
"the",
"options"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/ConnectionOptions.php#L502-L583 |
arangodb/arangodb-php | lib/ArangoDBClient/ConnectionOptions.php | ConnectionOptions.loadOptionsFromCache | private function loadOptionsFromCache()
{
$cache = $this->getEndpointsCache();
if ($cache === null) {
return;
}
$endpoints = $cache->get($this->_values[self::OPTION_MEMCACHED_ENDPOINTS_KEY]);
if ($endpoints) {
$this->_values[self::OPTION_ENDPOINT] = $endpoints;
if (!is_array($this->_values[self::OPTION_ENDPOINT])) {
$this->_values[self::OPTION_ENDPOINT] = [ $this->_values[self::OPTION_ENDPOINT] ];
}
}
} | php | private function loadOptionsFromCache()
{
$cache = $this->getEndpointsCache();
if ($cache === null) {
return;
}
$endpoints = $cache->get($this->_values[self::OPTION_MEMCACHED_ENDPOINTS_KEY]);
if ($endpoints) {
$this->_values[self::OPTION_ENDPOINT] = $endpoints;
if (!is_array($this->_values[self::OPTION_ENDPOINT])) {
$this->_values[self::OPTION_ENDPOINT] = [ $this->_values[self::OPTION_ENDPOINT] ];
}
}
} | [
"private",
"function",
"loadOptionsFromCache",
"(",
")",
"{",
"$",
"cache",
"=",
"$",
"this",
"->",
"getEndpointsCache",
"(",
")",
";",
"if",
"(",
"$",
"cache",
"===",
"null",
")",
"{",
"return",
";",
"}",
"$",
"endpoints",
"=",
"$",
"cache",
"->",
"... | load and merge connection options from optional Memcached cache into
ihe current settings
@return void | [
"load",
"and",
"merge",
"connection",
"options",
"from",
"optional",
"Memcached",
"cache",
"into",
"ihe",
"current",
"settings"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/ConnectionOptions.php#L592-L607 |
arangodb/arangodb-php | lib/ArangoDBClient/ConnectionOptions.php | ConnectionOptions.storeOptionsInCache | private function storeOptionsInCache()
{
$endpoints = $this->_values[self::OPTION_ENDPOINT];
$numberOfEndpoints = count($endpoints);
if ($numberOfEndpoints <= 1) {
return;
}
// now try to store the updated values in the cache
$cache = $this->getEndpointsCache();
if ($cache === null) {
return;
}
$update = [ $endpoints[$this->_currentEndpointIndex] ];
for ($i = 0; $i < $numberOfEndpoints; ++$i) {
if ($i !== $this->_currentEndpointIndex) {
$update[] = $endpoints[$i];
}
}
$ttl = (int) $this->_values[self::OPTION_MEMCACHED_TTL];
$cache->set($this->_values[self::OPTION_MEMCACHED_ENDPOINTS_KEY], $update, $ttl);
} | php | private function storeOptionsInCache()
{
$endpoints = $this->_values[self::OPTION_ENDPOINT];
$numberOfEndpoints = count($endpoints);
if ($numberOfEndpoints <= 1) {
return;
}
// now try to store the updated values in the cache
$cache = $this->getEndpointsCache();
if ($cache === null) {
return;
}
$update = [ $endpoints[$this->_currentEndpointIndex] ];
for ($i = 0; $i < $numberOfEndpoints; ++$i) {
if ($i !== $this->_currentEndpointIndex) {
$update[] = $endpoints[$i];
}
}
$ttl = (int) $this->_values[self::OPTION_MEMCACHED_TTL];
$cache->set($this->_values[self::OPTION_MEMCACHED_ENDPOINTS_KEY], $update, $ttl);
} | [
"private",
"function",
"storeOptionsInCache",
"(",
")",
"{",
"$",
"endpoints",
"=",
"$",
"this",
"->",
"_values",
"[",
"self",
"::",
"OPTION_ENDPOINT",
"]",
";",
"$",
"numberOfEndpoints",
"=",
"count",
"(",
"$",
"endpoints",
")",
";",
"if",
"(",
"$",
"nu... | store the updated options in the optional Memcached cache
@return void | [
"store",
"the",
"updated",
"options",
"in",
"the",
"optional",
"Memcached",
"cache"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/ConnectionOptions.php#L614-L638 |
arangodb/arangodb-php | lib/ArangoDBClient/ConnectionOptions.php | ConnectionOptions.getEndpointsCache | private function getEndpointsCache()
{
if ($this->_cache === null) {
if (!isset($this->_values[self::OPTION_MEMCACHED_SERVERS])) {
return null;
}
if (!class_exists('Memcached', false)) {
return null;
}
$servers = $this->_values[self::OPTION_MEMCACHED_SERVERS];
if (!is_array($servers)) {
throw new ClientException('Invalid memcached servers list. should be an array of servers');
}
$cache = new \Memcached(self::OPTION_MEMCACHED_PERSISTENT_ID);
if (empty($cache->getServerList())) {
$cache->addServers($servers);
}
if (isset($this->_values[self::OPTION_MEMCACHED_OPTIONS])) {
$options = $this->_values[self::OPTION_MEMCACHED_OPTIONS];
if (!is_array($options)) {
throw new ClientException('Invalid memcached options list. should be an array of options');
}
$cache->setOptions($options);
}
$this->_cache = $cache;
}
return $this->_cache;
} | php | private function getEndpointsCache()
{
if ($this->_cache === null) {
if (!isset($this->_values[self::OPTION_MEMCACHED_SERVERS])) {
return null;
}
if (!class_exists('Memcached', false)) {
return null;
}
$servers = $this->_values[self::OPTION_MEMCACHED_SERVERS];
if (!is_array($servers)) {
throw new ClientException('Invalid memcached servers list. should be an array of servers');
}
$cache = new \Memcached(self::OPTION_MEMCACHED_PERSISTENT_ID);
if (empty($cache->getServerList())) {
$cache->addServers($servers);
}
if (isset($this->_values[self::OPTION_MEMCACHED_OPTIONS])) {
$options = $this->_values[self::OPTION_MEMCACHED_OPTIONS];
if (!is_array($options)) {
throw new ClientException('Invalid memcached options list. should be an array of options');
}
$cache->setOptions($options);
}
$this->_cache = $cache;
}
return $this->_cache;
} | [
"private",
"function",
"getEndpointsCache",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_cache",
"===",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_values",
"[",
"self",
"::",
"OPTION_MEMCACHED_SERVERS",
"]",
")",
")",
"{",
... | Initialize and return a memcached cache instance,
if option "memcachedServers" is set
@return Memcached - memcached server instance if configured or null if not | [
"Initialize",
"and",
"return",
"a",
"memcached",
"cache",
"instance",
"if",
"option",
"memcachedServers",
"is",
"set"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/ConnectionOptions.php#L646-L678 |
arangodb/arangodb-php | lib/ArangoDBClient/TraceResponse.php | TraceResponse.getHttpCodeDefinition | public function getHttpCodeDefinition()
{
if (!isset($this->_httpCodeDefinitions[$this->getHttpCode()])) {
throw new ClientException('Invalid http code provided.');
}
return $this->_httpCodeDefinitions[$this->getHttpCode()];
} | php | public function getHttpCodeDefinition()
{
if (!isset($this->_httpCodeDefinitions[$this->getHttpCode()])) {
throw new ClientException('Invalid http code provided.');
}
return $this->_httpCodeDefinitions[$this->getHttpCode()];
} | [
"public",
"function",
"getHttpCodeDefinition",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_httpCodeDefinitions",
"[",
"$",
"this",
"->",
"getHttpCode",
"(",
")",
"]",
")",
")",
"{",
"throw",
"new",
"ClientException",
"(",
"'Invalid ht... | Get the http code definition
@throws ClientException
@return string | [
"Get",
"the",
"http",
"code",
"definition"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/TraceResponse.php#L148-L155 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.create | public function create($collection, array $options = [])
{
if (is_string($collection)) {
$name = $collection;
$collection = new Collection();
$collection->setName($name);
foreach ($options as $key => $value) {
$collection->{'set' . ucfirst($key)}($value);
}
}
if ($collection->getWaitForSync() === null) {
$collection->setWaitForSync($this->getConnectionOption(ConnectionOptions::OPTION_WAIT_SYNC));
}
if ($collection->getJournalSize() === null) {
$collection->setJournalSize($this->getConnectionOption(ConnectionOptions::OPTION_JOURNAL_SIZE));
}
if ($collection->getIsSystem() === null) {
$collection->setIsSystem($this->getConnectionOption(ConnectionOptions::OPTION_IS_SYSTEM));
}
if ($collection->getIsVolatile() === null) {
$collection->setIsVolatile($this->getConnectionOption(ConnectionOptions::OPTION_IS_VOLATILE));
}
$type = $collection->getType() ?: Collection::getDefaultType();
$params = [
Collection::ENTRY_NAME => $collection->getName(),
Collection::ENTRY_TYPE => $type,
Collection::ENTRY_WAIT_SYNC => $collection->getWaitForSync(),
Collection::ENTRY_JOURNAL_SIZE => $collection->getJournalSize(),
Collection::ENTRY_IS_SYSTEM => $collection->getIsSystem(),
Collection::ENTRY_IS_VOLATILE => $collection->getIsVolatile(),
Collection::ENTRY_KEY_OPTIONS => $collection->getKeyOptions(),
];
// set extra cluster attributes
if ($collection->getNumberOfShards() !== null) {
$params[Collection::ENTRY_NUMBER_OF_SHARDS] = $collection->getNumberOfShards();
}
if ($collection->getReplicationFactor() !== null) {
$params[Collection::ENTRY_REPLICATION_FACTOR] = $collection->getReplicationFactor();
}
if ($collection->getShardingStrategy() !== null) {
$params[Collection::ENTRY_SHARDING_STRATEGY] = $collection->getShardingStrategy();
}
if (is_array($collection->getShardKeys())) {
$params[Collection::ENTRY_SHARD_KEYS] = $collection->getShardKeys();
}
$response = $this->getConnection()->post(Urls::URL_COLLECTION, $this->json_encode_wrapper($params));
// $location = $response->getLocationHeader();
// if (!$location) {
// throw new ClientException('Did not find location header in server response');
// }
$jsonResponse = $response->getJson();
$id = $jsonResponse['id'];
$collection->setId($id);
return $id;
} | php | public function create($collection, array $options = [])
{
if (is_string($collection)) {
$name = $collection;
$collection = new Collection();
$collection->setName($name);
foreach ($options as $key => $value) {
$collection->{'set' . ucfirst($key)}($value);
}
}
if ($collection->getWaitForSync() === null) {
$collection->setWaitForSync($this->getConnectionOption(ConnectionOptions::OPTION_WAIT_SYNC));
}
if ($collection->getJournalSize() === null) {
$collection->setJournalSize($this->getConnectionOption(ConnectionOptions::OPTION_JOURNAL_SIZE));
}
if ($collection->getIsSystem() === null) {
$collection->setIsSystem($this->getConnectionOption(ConnectionOptions::OPTION_IS_SYSTEM));
}
if ($collection->getIsVolatile() === null) {
$collection->setIsVolatile($this->getConnectionOption(ConnectionOptions::OPTION_IS_VOLATILE));
}
$type = $collection->getType() ?: Collection::getDefaultType();
$params = [
Collection::ENTRY_NAME => $collection->getName(),
Collection::ENTRY_TYPE => $type,
Collection::ENTRY_WAIT_SYNC => $collection->getWaitForSync(),
Collection::ENTRY_JOURNAL_SIZE => $collection->getJournalSize(),
Collection::ENTRY_IS_SYSTEM => $collection->getIsSystem(),
Collection::ENTRY_IS_VOLATILE => $collection->getIsVolatile(),
Collection::ENTRY_KEY_OPTIONS => $collection->getKeyOptions(),
];
// set extra cluster attributes
if ($collection->getNumberOfShards() !== null) {
$params[Collection::ENTRY_NUMBER_OF_SHARDS] = $collection->getNumberOfShards();
}
if ($collection->getReplicationFactor() !== null) {
$params[Collection::ENTRY_REPLICATION_FACTOR] = $collection->getReplicationFactor();
}
if ($collection->getShardingStrategy() !== null) {
$params[Collection::ENTRY_SHARDING_STRATEGY] = $collection->getShardingStrategy();
}
if (is_array($collection->getShardKeys())) {
$params[Collection::ENTRY_SHARD_KEYS] = $collection->getShardKeys();
}
$response = $this->getConnection()->post(Urls::URL_COLLECTION, $this->json_encode_wrapper($params));
// $location = $response->getLocationHeader();
// if (!$location) {
// throw new ClientException('Did not find location header in server response');
// }
$jsonResponse = $response->getJson();
$id = $jsonResponse['id'];
$collection->setId($id);
return $id;
} | [
"public",
"function",
"create",
"(",
"$",
"collection",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"collection",
")",
")",
"{",
"$",
"name",
"=",
"$",
"collection",
";",
"$",
"collection",
"=",
"new",
"... | Creates a new collection on the server
This will add the collection on the server and return its id
The id is mainly returned for backwards compatibility, but you should use the collection name for any reference to the collection. *
This will throw if the collection cannot be created
@throws Exception
@param mixed $collection - collection object to be created on the server or a string with the name
@param array $options - an array of options.
<p>Options are :<br>
<li>'type' - 2 -> normal collection, 3 -> edge-collection</li>
<li>'waitForSync' - if set to true, then all removal operations will instantly be synchronised to disk / If this is not specified, then the collection's default sync behavior will be applied.</li>
<li>'journalSize' - journalSize value.</li>
<li>'isSystem' - false->user collection(default), true->system collection .</li>
<li>'isVolatile' - false->persistent collection(default), true->volatile (in-memory) collection .</li>
<li>'keyOptions' - key options to use.</li>
<li>'numberOfShards' - number of shards for the collection.</li>
<li>'shardKeys' - array of shard key attributes.</li>
<li>'replicationFactor' - number of replicas to keep (default: 1).</li>
<li>'shardingStrategy' - sharding strategy to use in cluster.</li>
</p>
@return mixed - id of collection created | [
"Creates",
"a",
"new",
"collection",
"on",
"the",
"server"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L231-L296 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.has | public function has($collection)
{
$collection = $this->makeCollection($collection);
try {
// will throw ServerException if entry could not be retrieved
$this->get($collection);
return true;
} catch (ServerException $e) {
// we are expecting a 404 to return boolean false
if ($e->getCode() === 404) {
return false;
}
// just rethrow
throw $e;
}
} | php | public function has($collection)
{
$collection = $this->makeCollection($collection);
try {
// will throw ServerException if entry could not be retrieved
$this->get($collection);
return true;
} catch (ServerException $e) {
// we are expecting a 404 to return boolean false
if ($e->getCode() === 404) {
return false;
}
// just rethrow
throw $e;
}
} | [
"public",
"function",
"has",
"(",
"$",
"collection",
")",
"{",
"$",
"collection",
"=",
"$",
"this",
"->",
"makeCollection",
"(",
"$",
"collection",
")",
";",
"try",
"{",
"// will throw ServerException if entry could not be retrieved",
"$",
"this",
"->",
"get",
"... | Check if a collection exists
This will call self::get() internally and checks if there
was an exception thrown which represents an 404 request.
@throws Exception When any other error than a 404 occurs
@param mixed $collection - collection id as a string or number
@return boolean | [
"Check",
"if",
"a",
"collection",
"exists"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L332-L350 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.count | public function count($collection)
{
$collection = $this->makeCollection($collection);
$url = UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collection, self::OPTION_COUNT]);
$response = $this->getConnection()->get($url);
$data = $response->getJson();
$count = $data[self::OPTION_COUNT];
return (int) $count;
} | php | public function count($collection)
{
$collection = $this->makeCollection($collection);
$url = UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collection, self::OPTION_COUNT]);
$response = $this->getConnection()->get($url);
$data = $response->getJson();
$count = $data[self::OPTION_COUNT];
return (int) $count;
} | [
"public",
"function",
"count",
"(",
"$",
"collection",
")",
"{",
"$",
"collection",
"=",
"$",
"this",
"->",
"makeCollection",
"(",
"$",
"collection",
")",
";",
"$",
"url",
"=",
"UrlHelper",
"::",
"buildUrl",
"(",
"Urls",
"::",
"URL_COLLECTION",
",",
"[",... | Get the number of documents in a collection
This will throw if the collection cannot be fetched from the server
@throws Exception
@param mixed $collection - collection id as a string or number
@return int - the number of documents in the collection | [
"Get",
"the",
"number",
"of",
"documents",
"in",
"a",
"collection"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L364-L374 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.get | public function get($collection)
{
$collection = $this->makeCollection($collection);
$url = UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collection]);
$response = $this->getConnection()->get($url);
$data = $response->getJson();
return Collection::createFromArray($data);
} | php | public function get($collection)
{
$collection = $this->makeCollection($collection);
$url = UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collection]);
$response = $this->getConnection()->get($url);
$data = $response->getJson();
return Collection::createFromArray($data);
} | [
"public",
"function",
"get",
"(",
"$",
"collection",
")",
"{",
"$",
"collection",
"=",
"$",
"this",
"->",
"makeCollection",
"(",
"$",
"collection",
")",
";",
"$",
"url",
"=",
"UrlHelper",
"::",
"buildUrl",
"(",
"Urls",
"::",
"URL_COLLECTION",
",",
"[",
... | Get information about a collection
This will throw if the collection cannot be fetched from the server
@throws Exception
@param mixed $collection - collection id as a string or number
@return Collection - the collection fetched from the server | [
"Get",
"information",
"about",
"a",
"collection"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L388-L398 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.figures | public function figures($collection)
{
$collection = $this->makeCollection($collection);
$url = UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collection, self::OPTION_FIGURES]);
$response = $this->getConnection()->get($url);
$data = $response->getJson();
return $data[self::OPTION_FIGURES];
} | php | public function figures($collection)
{
$collection = $this->makeCollection($collection);
$url = UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collection, self::OPTION_FIGURES]);
$response = $this->getConnection()->get($url);
$data = $response->getJson();
return $data[self::OPTION_FIGURES];
} | [
"public",
"function",
"figures",
"(",
"$",
"collection",
")",
"{",
"$",
"collection",
"=",
"$",
"this",
"->",
"makeCollection",
"(",
"$",
"collection",
")",
";",
"$",
"url",
"=",
"UrlHelper",
"::",
"buildUrl",
"(",
"Urls",
"::",
"URL_COLLECTION",
",",
"[... | Get figures for a collection
This will throw if the collection cannot be fetched from the server
@throws Exception
@param mixed $collection - collection id as a string or number
@return array - the figures for the collection | [
"Get",
"figures",
"for",
"a",
"collection"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L435-L444 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.getChecksum | public function getChecksum($collectionId, $withRevisions = false, $withData = false)
{
$url = UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collectionId, self::OPTION_CHECKSUM]);
$url = UrlHelper::appendParamsUrl($url, ['withRevisions' => $withRevisions, 'withData' => $withData]);
$response = $this->getConnection()->get($url);
return $response->getJson();
} | php | public function getChecksum($collectionId, $withRevisions = false, $withData = false)
{
$url = UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collectionId, self::OPTION_CHECKSUM]);
$url = UrlHelper::appendParamsUrl($url, ['withRevisions' => $withRevisions, 'withData' => $withData]);
$response = $this->getConnection()->get($url);
return $response->getJson();
} | [
"public",
"function",
"getChecksum",
"(",
"$",
"collectionId",
",",
"$",
"withRevisions",
"=",
"false",
",",
"$",
"withData",
"=",
"false",
")",
"{",
"$",
"url",
"=",
"UrlHelper",
"::",
"buildUrl",
"(",
"Urls",
"::",
"URL_COLLECTION",
",",
"[",
"$",
"col... | Calculate a checksum of the collection.
Will calculate a checksum of the meta-data (keys and optionally revision ids)
and optionally the document data in the collection.
@throws Exception
@param mixed $collectionId - collection id as a string or number
@param boolean $withRevisions - optional boolean whether or not to include document revision ids
in the checksum calculation.
@param boolean $withData - optional boolean whether or not to include document body data in the
checksum calculation.
@return array - array containing keys "checksum" and "revision" | [
"Calculate",
"a",
"checksum",
"of",
"the",
"collection",
"."
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L463-L471 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.getRevision | public function getRevision($collectionId)
{
$url = UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collectionId, self::OPTION_REVISION]);
$response = $this->getConnection()->get($url);
return $response->getJson();
} | php | public function getRevision($collectionId)
{
$url = UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collectionId, self::OPTION_REVISION]);
$response = $this->getConnection()->get($url);
return $response->getJson();
} | [
"public",
"function",
"getRevision",
"(",
"$",
"collectionId",
")",
"{",
"$",
"url",
"=",
"UrlHelper",
"::",
"buildUrl",
"(",
"Urls",
"::",
"URL_COLLECTION",
",",
"[",
"$",
"collectionId",
",",
"self",
"::",
"OPTION_REVISION",
"]",
")",
";",
"$",
"response... | Returns the Collections revision ID
The revision id is a server-generated string that clients can use to check whether data in a collection has
changed since the last revision check.
@throws Exception
@param mixed $collectionId - collection id as a string or number
@return array - containing a key revision | [
"Returns",
"the",
"Collections",
"revision",
"ID"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L485-L492 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.rename | public function rename($collection, $name)
{
$collectionId = $this->getCollectionId($collection);
if ($this->isValidCollectionId($collectionId)) {
throw new ClientException('Cannot alter a collection without a collection id');
}
$params = [Collection::ENTRY_NAME => $name];
$this->getConnection()->put(
UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collectionId, self::OPTION_RENAME]),
$this->json_encode_wrapper($params)
);
return true;
} | php | public function rename($collection, $name)
{
$collectionId = $this->getCollectionId($collection);
if ($this->isValidCollectionId($collectionId)) {
throw new ClientException('Cannot alter a collection without a collection id');
}
$params = [Collection::ENTRY_NAME => $name];
$this->getConnection()->put(
UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collectionId, self::OPTION_RENAME]),
$this->json_encode_wrapper($params)
);
return true;
} | [
"public",
"function",
"rename",
"(",
"$",
"collection",
",",
"$",
"name",
")",
"{",
"$",
"collectionId",
"=",
"$",
"this",
"->",
"getCollectionId",
"(",
"$",
"collection",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isValidCollectionId",
"(",
"$",
"collecti... | Rename a collection
@throws Exception
@param mixed $collection - collection id as string or number or collection object
@param string $name - new name for collection
@return bool - always true, will throw if there is an error | [
"Rename",
"a",
"collection"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L504-L519 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.load | public function load($collection)
{
$collectionId = $this->getCollectionId($collection);
if ($this->isValidCollectionId($collectionId)) {
throw new ClientException('Cannot alter a collection without a collection id');
}
$result = $this->getConnection()->put(
UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collectionId, self::OPTION_LOAD]),
''
);
return $result;
} | php | public function load($collection)
{
$collectionId = $this->getCollectionId($collection);
if ($this->isValidCollectionId($collectionId)) {
throw new ClientException('Cannot alter a collection without a collection id');
}
$result = $this->getConnection()->put(
UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collectionId, self::OPTION_LOAD]),
''
);
return $result;
} | [
"public",
"function",
"load",
"(",
"$",
"collection",
")",
"{",
"$",
"collectionId",
"=",
"$",
"this",
"->",
"getCollectionId",
"(",
"$",
"collection",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isValidCollectionId",
"(",
"$",
"collectionId",
")",
")",
"{"... | Load a collection into the server's memory
This will load the given collection into the server's memory.
@throws Exception
@param mixed $collection - collection id as string or number or collection object
@return HttpResponse - HTTP response object | [
"Load",
"a",
"collection",
"into",
"the",
"server",
"s",
"memory"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L532-L546 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.unload | public function unload($collection)
{
$collectionId = $this->getCollectionId($collection);
if ($this->isValidCollectionId($collectionId)) {
throw new ClientException('Cannot alter a collection without a collection id');
}
$result = $this->getConnection()->put(
UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collectionId, self::OPTION_UNLOAD]),
''
);
return $result;
} | php | public function unload($collection)
{
$collectionId = $this->getCollectionId($collection);
if ($this->isValidCollectionId($collectionId)) {
throw new ClientException('Cannot alter a collection without a collection id');
}
$result = $this->getConnection()->put(
UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collectionId, self::OPTION_UNLOAD]),
''
);
return $result;
} | [
"public",
"function",
"unload",
"(",
"$",
"collection",
")",
"{",
"$",
"collectionId",
"=",
"$",
"this",
"->",
"getCollectionId",
"(",
"$",
"collection",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isValidCollectionId",
"(",
"$",
"collectionId",
")",
")",
"... | Unload a collection from the server's memory
This will unload the given collection from the server's memory.
@throws Exception
@param mixed $collection - collection id as string or number or collection object
@return HttpResponse - HTTP response object | [
"Unload",
"a",
"collection",
"from",
"the",
"server",
"s",
"memory"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L559-L573 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.truncate | public function truncate($collection)
{
$collectionId = $this->getCollectionId($collection);
if ($this->isValidCollectionId($collectionId)) {
throw new ClientException('Cannot alter a collection without a collection id');
}
$this->getConnection()->put(
UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collectionId, self::OPTION_TRUNCATE]),
''
);
return true;
} | php | public function truncate($collection)
{
$collectionId = $this->getCollectionId($collection);
if ($this->isValidCollectionId($collectionId)) {
throw new ClientException('Cannot alter a collection without a collection id');
}
$this->getConnection()->put(
UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collectionId, self::OPTION_TRUNCATE]),
''
);
return true;
} | [
"public",
"function",
"truncate",
"(",
"$",
"collection",
")",
"{",
"$",
"collectionId",
"=",
"$",
"this",
"->",
"getCollectionId",
"(",
"$",
"collection",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isValidCollectionId",
"(",
"$",
"collectionId",
")",
")",
... | Truncate a collection
This will remove all documents from the collection but will leave the metadata and indexes intact.
@throws Exception
@param mixed $collection - collection id as string or number or collection object
@return bool - always true, will throw if there is an error | [
"Truncate",
"a",
"collection"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L587-L601 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.drop | public function drop($collection, array $options = [])
{
$collectionName = $this->getCollectionName($collection);
if ($this->isValidCollectionId($collectionName)) {
throw new ClientException('Cannot alter a collection without a collection id');
}
$appendix = '';
if (is_array($options) && isset($options['isSystem'])) {
$appendix = '?isSystem=' . UrlHelper::getBoolString($options['isSystem']);
}
$this->getConnection()->delete(UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collectionName]) . $appendix);
return true;
} | php | public function drop($collection, array $options = [])
{
$collectionName = $this->getCollectionName($collection);
if ($this->isValidCollectionId($collectionName)) {
throw new ClientException('Cannot alter a collection without a collection id');
}
$appendix = '';
if (is_array($options) && isset($options['isSystem'])) {
$appendix = '?isSystem=' . UrlHelper::getBoolString($options['isSystem']);
}
$this->getConnection()->delete(UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collectionName]) . $appendix);
return true;
} | [
"public",
"function",
"drop",
"(",
"$",
"collection",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"collectionName",
"=",
"$",
"this",
"->",
"getCollectionName",
"(",
"$",
"collection",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isValidCol... | Drop a collection
@throws Exception
@param mixed $collection - collection id as string or number or collection object
@param array $options - an array of options for the drop operation
@return bool - always true, will throw if there is an error | [
"Drop",
"a",
"collection"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L614-L630 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.getAllCollections | public function getAllCollections(array $options = [])
{
$options = array_merge(['excludeSystem' => false, 'keys' => 'result'], $options);
$params = [];
if ($options['excludeSystem'] === true) {
$params[self::OPTION_EXCLUDE_SYSTEM] = true;
}
$url = UrlHelper::appendParamsUrl(Urls::URL_COLLECTION, $params);
$response = $this->getConnection()->get(UrlHelper::buildUrl($url, []));
$response = $response->getJson();
if (isset($response[$options['keys']])) {
$result = [];
foreach ($response[$options['keys']] as $collection) {
$result[$collection['name']] = $collection;
}
return $result;
}
return $response;
} | php | public function getAllCollections(array $options = [])
{
$options = array_merge(['excludeSystem' => false, 'keys' => 'result'], $options);
$params = [];
if ($options['excludeSystem'] === true) {
$params[self::OPTION_EXCLUDE_SYSTEM] = true;
}
$url = UrlHelper::appendParamsUrl(Urls::URL_COLLECTION, $params);
$response = $this->getConnection()->get(UrlHelper::buildUrl($url, []));
$response = $response->getJson();
if (isset($response[$options['keys']])) {
$result = [];
foreach ($response[$options['keys']] as $collection) {
$result[$collection['name']] = $collection;
}
return $result;
}
return $response;
} | [
"public",
"function",
"getAllCollections",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"array_merge",
"(",
"[",
"'excludeSystem'",
"=>",
"false",
",",
"'keys'",
"=>",
"'result'",
"]",
",",
"$",
"options",
")",
";",
"$",
... | Get list of all available collections per default with the collection names as index.
Returns empty array if none are available.
@param array $options - optional - an array of options.
<p>Options are :<br>
<li>'excludeSystem' - With a value of true, all system collections will be excluded from the response.</li>
<li>'keys' - With a value of "collections", the index of the resulting array is numerical,
With a value of "names", the index of the resulting array are the collection names.</li>
</p>
@return array
@throws \ArangoDBClient\Exception
@throws \ArangoDBClient\ClientException | [
"Get",
"list",
"of",
"all",
"available",
"collections",
"per",
"default",
"with",
"the",
"collection",
"names",
"as",
"index",
".",
"Returns",
"empty",
"array",
"if",
"none",
"are",
"available",
"."
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L660-L680 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.getCollectionId | public function getCollectionId($collection)
{
if ($collection instanceof Collection) {
$collectionId = $collection->getId();
return $collectionId;
}
$collectionId = $collection;
return $collectionId;
} | php | public function getCollectionId($collection)
{
if ($collection instanceof Collection) {
$collectionId = $collection->getId();
return $collectionId;
}
$collectionId = $collection;
return $collectionId;
} | [
"public",
"function",
"getCollectionId",
"(",
"$",
"collection",
")",
"{",
"if",
"(",
"$",
"collection",
"instanceof",
"Collection",
")",
"{",
"$",
"collectionId",
"=",
"$",
"collection",
"->",
"getId",
"(",
")",
";",
"return",
"$",
"collectionId",
";",
"}... | Gets the collectionId from the given collectionObject or string/integer
@param mixed $collection
@return mixed | [
"Gets",
"the",
"collectionId",
"from",
"the",
"given",
"collectionObject",
"or",
"string",
"/",
"integer"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L690-L701 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.getCollectionName | public function getCollectionName($collection)
{
if ($collection instanceof Collection) {
$collectionId = $collection->getName();
return $collectionId;
}
$collectionId = $collection;
return $collectionId;
} | php | public function getCollectionName($collection)
{
if ($collection instanceof Collection) {
$collectionId = $collection->getName();
return $collectionId;
}
$collectionId = $collection;
return $collectionId;
} | [
"public",
"function",
"getCollectionName",
"(",
"$",
"collection",
")",
"{",
"if",
"(",
"$",
"collection",
"instanceof",
"Collection",
")",
"{",
"$",
"collectionId",
"=",
"$",
"collection",
"->",
"getName",
"(",
")",
";",
"return",
"$",
"collectionId",
";",
... | Gets the collectionId from the given collectionObject or string/integer
@param mixed $collection
@return mixed | [
"Gets",
"the",
"collectionId",
"from",
"the",
"given",
"collectionObject",
"or",
"string",
"/",
"integer"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L711-L722 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.importFromFile | public function importFromFile(
$collectionId,
$importFileName,
array $options = []
)
{
$contents = file_get_contents($importFileName);
if ($contents === false) {
throw new ClientException('Input file "' . $importFileName . '" could not be found.');
}
return $this->import($collectionId, $contents, $options);
} | php | public function importFromFile(
$collectionId,
$importFileName,
array $options = []
)
{
$contents = file_get_contents($importFileName);
if ($contents === false) {
throw new ClientException('Input file "' . $importFileName . '" could not be found.');
}
return $this->import($collectionId, $contents, $options);
} | [
"public",
"function",
"importFromFile",
"(",
"$",
"collectionId",
",",
"$",
"importFileName",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"contents",
"=",
"file_get_contents",
"(",
"$",
"importFileName",
")",
";",
"if",
"(",
"$",
"contents"... | Import documents from a file
This will throw on all errors except insertion errors
@throws Exception
@param mixed $collectionId - collection id as string or number
@param mixed $importFileName - The filename that holds the import data.
@param array $options - optional - an array of options.
<p>Options are :<br>
'type' - if type is not set or it's set to '' or null, the Header-Value format must be provided in the import file.<br>
<p>
<li> if set to 'documents', then the file's content must have its documents line by line. Each line will be interpreted as a document.</li>
<li> if set to 'array' then the file's content must provide the documents as a list of documents instead of the above line by line.</li>
<br>
More info on how the import functionality works: <a href ="https://github.com/triAGENS/ArangoDB/wiki/HttpImport">https://github.com/triAGENS/ArangoDB/wiki/HttpImport</a>
</p>
<br>
</li>
<li>'createCollection' - If true, create the collection if it does not exist. Defaults to false </li>
</p>
@return array - returns an array with the server's response data from the import command | [
"Import",
"documents",
"from",
"a",
"file"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L750-L763 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.import | public function import(
$collection,
$importData,
array $options = []
)
{
$collection = $this->makeCollection($collection);
$tmpContent = '';
if (is_array($importData)) {
foreach ($importData as $document) {
/** @var $document Document */
$tmpContent .= $document->toJson() . "\r\n";
}
$importData = $tmpContent;
unset($tmpContent);
$options['type'] = 'documents';
}
$this->createCollectionIfOptions($collection, $options);
$params = array_merge(
[self::OPTION_COLLECTION => $collection],
$options
);
if (array_key_exists('type', $options)) {
switch ($options['type']) {
case 'documents':
$params[self::OPTION_TYPE] = 'documents';
break;
case 'array':
$params[self::OPTION_TYPE] = 'array';
break;
}
}
$url = UrlHelper::appendParamsUrl(Urls::URL_IMPORT, $params);
$response = $this->getConnection()->post($url, $importData);
return $response->getJson();
} | php | public function import(
$collection,
$importData,
array $options = []
)
{
$collection = $this->makeCollection($collection);
$tmpContent = '';
if (is_array($importData)) {
foreach ($importData as $document) {
/** @var $document Document */
$tmpContent .= $document->toJson() . "\r\n";
}
$importData = $tmpContent;
unset($tmpContent);
$options['type'] = 'documents';
}
$this->createCollectionIfOptions($collection, $options);
$params = array_merge(
[self::OPTION_COLLECTION => $collection],
$options
);
if (array_key_exists('type', $options)) {
switch ($options['type']) {
case 'documents':
$params[self::OPTION_TYPE] = 'documents';
break;
case 'array':
$params[self::OPTION_TYPE] = 'array';
break;
}
}
$url = UrlHelper::appendParamsUrl(Urls::URL_IMPORT, $params);
$response = $this->getConnection()->post($url, $importData);
return $response->getJson();
} | [
"public",
"function",
"import",
"(",
"$",
"collection",
",",
"$",
"importData",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"collection",
"=",
"$",
"this",
"->",
"makeCollection",
"(",
"$",
"collection",
")",
";",
"$",
"tmpContent",
"="... | Import documents into a collection
This will throw on all errors except insertion errors
@param $collection mixed $collection - collection id as string or number
@param string|array $importData - The data to import. This can be a string holding the data according to the type of import, or an array of documents
@param array $options - optional - an array of options.
<p>Options are :<br>
<li>
'type' - if type is not set or it's set to '' or null, the Header-Value format must be provided in the import file.<br>
<p>
<li> if set to 'documents', then the file's content must have its documents line by line. Each line will be interpreted as a document.</li>
<li> if set to 'array' then the file's content must provide the documents as a list of documents instead of the above line by line.</li>
<br>
More info on how the import functionality works: <a href ="https://github.com/triAGENS/ArangoDB/wiki/HttpImport">https://github.com/triAGENS/ArangoDB/wiki/HttpImport</a>
</p>
<br>
</li>
<li>'createCollection' - If true, create the collection if it does not exist. Defaults to false </li>
</p>
Other options as described in API Documentation*
@see https://docs.arangodb.com/3.1/HTTP/BulkImports/
@return array
@throws \ArangoDBClient\Exception
@throws \ArangoDBClient\ClientException | [
"Import",
"documents",
"into",
"a",
"collection"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L798-L840 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.createHashIndex | public function createHashIndex($collectionId, array $fields, $unique = null, $sparse = null)
{
$indexOptions = [];
if ($unique) {
$indexOptions[self::OPTION_UNIQUE] = (bool) $unique;
}
if ($sparse) {
$indexOptions[self::OPTION_SPARSE] = (bool) $sparse;
}
return $this->index($collectionId, self::OPTION_HASH_INDEX, $fields, null, $indexOptions);
} | php | public function createHashIndex($collectionId, array $fields, $unique = null, $sparse = null)
{
$indexOptions = [];
if ($unique) {
$indexOptions[self::OPTION_UNIQUE] = (bool) $unique;
}
if ($sparse) {
$indexOptions[self::OPTION_SPARSE] = (bool) $sparse;
}
return $this->index($collectionId, self::OPTION_HASH_INDEX, $fields, null, $indexOptions);
} | [
"public",
"function",
"createHashIndex",
"(",
"$",
"collectionId",
",",
"array",
"$",
"fields",
",",
"$",
"unique",
"=",
"null",
",",
"$",
"sparse",
"=",
"null",
")",
"{",
"$",
"indexOptions",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"unique",
")",
"{",
... | Create a hash index
@param string $collectionId - the collection id
@param array $fields - an array of fields
@param boolean $unique - whether the values in the index should be unique or not
@param boolean $sparse - whether the index should be sparse
@link https://docs.arangodb.com/HTTP/Indexes/Hash.html
@return array - server response of the created index
@throws \ArangoDBClient\Exception | [
"Create",
"a",
"hash",
"index"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L856-L868 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.createFulltextIndex | public function createFulltextIndex($collectionId, array $fields, $minLength = null)
{
$indexOptions = [];
if ($minLength) {
$indexOptions[self::OPTION_MIN_LENGTH] = $minLength;
}
return $this->index($collectionId, self::OPTION_FULLTEXT_INDEX, $fields, null, $indexOptions);
} | php | public function createFulltextIndex($collectionId, array $fields, $minLength = null)
{
$indexOptions = [];
if ($minLength) {
$indexOptions[self::OPTION_MIN_LENGTH] = $minLength;
}
return $this->index($collectionId, self::OPTION_FULLTEXT_INDEX, $fields, null, $indexOptions);
} | [
"public",
"function",
"createFulltextIndex",
"(",
"$",
"collectionId",
",",
"array",
"$",
"fields",
",",
"$",
"minLength",
"=",
"null",
")",
"{",
"$",
"indexOptions",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"minLength",
")",
"{",
"$",
"indexOptions",
"[",
... | Create a fulltext index
@param string $collectionId - the collection id
@param array $fields - an array of fields
@param int $minLength - the minimum length of words to index
@link https://docs.arangodb.com/HTTP/Indexes/Fulltext.html
@return array - server response of the created index
@throws \ArangoDBClient\Exception | [
"Create",
"a",
"fulltext",
"index"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L882-L891 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.createSkipListIndex | public function createSkipListIndex($collectionId, array $fields, $unique = null, $sparse = null)
{
$indexOptions = [];
if ($unique) {
$indexOptions[self::OPTION_UNIQUE] = (bool) $unique;
}
if ($sparse) {
$indexOptions[self::OPTION_SPARSE] = (bool) $sparse;
}
return $this->index($collectionId, self::OPTION_SKIPLIST_INDEX, $fields, null, $indexOptions);
} | php | public function createSkipListIndex($collectionId, array $fields, $unique = null, $sparse = null)
{
$indexOptions = [];
if ($unique) {
$indexOptions[self::OPTION_UNIQUE] = (bool) $unique;
}
if ($sparse) {
$indexOptions[self::OPTION_SPARSE] = (bool) $sparse;
}
return $this->index($collectionId, self::OPTION_SKIPLIST_INDEX, $fields, null, $indexOptions);
} | [
"public",
"function",
"createSkipListIndex",
"(",
"$",
"collectionId",
",",
"array",
"$",
"fields",
",",
"$",
"unique",
"=",
"null",
",",
"$",
"sparse",
"=",
"null",
")",
"{",
"$",
"indexOptions",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"unique",
")",
"{... | Create a skip-list index
@param string $collectionId - the collection id
@param array $fields - an array of fields
@param bool $unique - whether the index is unique or not
@param bool $sparse - whether the index should be sparse
@link https://docs.arangodb.com/HTTP/Indexes/Skiplist.html
@return array - server response of the created index
@throws \ArangoDBClient\Exception | [
"Create",
"a",
"skip",
"-",
"list",
"index"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L906-L918 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.createPersistentIndex | public function createPersistentIndex($collectionId, array $fields, $unique = null, $sparse = null)
{
$indexOptions = [];
if ($unique) {
$indexOptions[self::OPTION_UNIQUE] = (bool) $unique;
}
if ($sparse) {
$indexOptions[self::OPTION_SPARSE] = (bool) $sparse;
}
return $this->index($collectionId, self::OPTION_PERSISTENT_INDEX, $fields, null, $indexOptions);
} | php | public function createPersistentIndex($collectionId, array $fields, $unique = null, $sparse = null)
{
$indexOptions = [];
if ($unique) {
$indexOptions[self::OPTION_UNIQUE] = (bool) $unique;
}
if ($sparse) {
$indexOptions[self::OPTION_SPARSE] = (bool) $sparse;
}
return $this->index($collectionId, self::OPTION_PERSISTENT_INDEX, $fields, null, $indexOptions);
} | [
"public",
"function",
"createPersistentIndex",
"(",
"$",
"collectionId",
",",
"array",
"$",
"fields",
",",
"$",
"unique",
"=",
"null",
",",
"$",
"sparse",
"=",
"null",
")",
"{",
"$",
"indexOptions",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"unique",
")",
... | Create a persistent index
@param string $collectionId - the collection id
@param array $fields - an array of fields
@param bool $unique - whether the index is unique or not
@param bool $sparse - whether the index should be sparse
@link https://docs.arangodb.com/HTTP/Indexes/Persistent.html
@return array - server response of the created index
@throws \ArangoDBClient\Exception | [
"Create",
"a",
"persistent",
"index"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L933-L945 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.createGeoIndex | public function createGeoIndex($collectionId, array $fields, $geoJson = null)
{
$indexOptions = [];
if ($geoJson) {
$indexOptions[self::OPTION_GEOJSON] = (bool) $geoJson;
}
return $this->index($collectionId, self::OPTION_GEO_INDEX, $fields, null, $indexOptions);
} | php | public function createGeoIndex($collectionId, array $fields, $geoJson = null)
{
$indexOptions = [];
if ($geoJson) {
$indexOptions[self::OPTION_GEOJSON] = (bool) $geoJson;
}
return $this->index($collectionId, self::OPTION_GEO_INDEX, $fields, null, $indexOptions);
} | [
"public",
"function",
"createGeoIndex",
"(",
"$",
"collectionId",
",",
"array",
"$",
"fields",
",",
"$",
"geoJson",
"=",
"null",
")",
"{",
"$",
"indexOptions",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"geoJson",
")",
"{",
"$",
"indexOptions",
"[",
"self",
... | Create a geo index
@param string $collectionId - the collection id
@param array $fields - an array of fields
@param boolean $geoJson - whether to use geoJson or not
@link https://docs.arangodb.com/HTTP/Indexes/Geo.html
@return array - server response of the created index
@throws \ArangoDBClient\Exception | [
"Create",
"a",
"geo",
"index"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L959-L968 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.index | public function index($collectionId, $type, array $attributes = [], $unique = false, array $indexOptions = [])
{
$urlParams = [self::OPTION_COLLECTION => $collectionId];
$bodyParams = [
self::OPTION_TYPE => $type,
self::OPTION_FIELDS => $attributes,
];
if ($unique !== null) {
$bodyParams[self::OPTION_UNIQUE] = (bool) $unique;
}
$bodyParams = array_merge($bodyParams, $indexOptions);
$url = UrlHelper::appendParamsUrl(Urls::URL_INDEX, $urlParams);
$response = $this->getConnection()->post($url, $this->json_encode_wrapper($bodyParams));
$httpCode = $response->getHttpCode();
switch ($httpCode) {
case 404:
throw new ClientException('Collection-identifier is unknown');
break;
case 400:
throw new ClientException('cannot create unique index due to documents violating uniqueness');
break;
}
return $response->getJson();
} | php | public function index($collectionId, $type, array $attributes = [], $unique = false, array $indexOptions = [])
{
$urlParams = [self::OPTION_COLLECTION => $collectionId];
$bodyParams = [
self::OPTION_TYPE => $type,
self::OPTION_FIELDS => $attributes,
];
if ($unique !== null) {
$bodyParams[self::OPTION_UNIQUE] = (bool) $unique;
}
$bodyParams = array_merge($bodyParams, $indexOptions);
$url = UrlHelper::appendParamsUrl(Urls::URL_INDEX, $urlParams);
$response = $this->getConnection()->post($url, $this->json_encode_wrapper($bodyParams));
$httpCode = $response->getHttpCode();
switch ($httpCode) {
case 404:
throw new ClientException('Collection-identifier is unknown');
break;
case 400:
throw new ClientException('cannot create unique index due to documents violating uniqueness');
break;
}
return $response->getJson();
} | [
"public",
"function",
"index",
"(",
"$",
"collectionId",
",",
"$",
"type",
",",
"array",
"$",
"attributes",
"=",
"[",
"]",
",",
"$",
"unique",
"=",
"false",
",",
"array",
"$",
"indexOptions",
"=",
"[",
"]",
")",
"{",
"$",
"urlParams",
"=",
"[",
"se... | Creates an index on a collection on the server
This will create an index on the collection on the server and return its id
This will throw if the index cannot be created
@throws Exception
@param mixed $collectionId - The id of the collection where the index is to be created
@param string $type - index type: hash, skiplist, geo, fulltext, or persistent
@param array $attributes - an array of attributes that can be defined like array('a') or array('a', 'b.c')
@param bool $unique - true/false to create a unique index
@param array $indexOptions - an associative array of options for the index like array('geoJson' => true, 'sparse' => false)
@return array - server response of the created index | [
"Creates",
"an",
"index",
"on",
"a",
"collection",
"on",
"the",
"server"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L987-L1017 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.getIndex | public function getIndex($collection, $indexId)
{
$url = UrlHelper::buildUrl(Urls::URL_INDEX, [$collection, $indexId]);
$response = $this->getConnection()->get($url);
return $response->getJson();
} | php | public function getIndex($collection, $indexId)
{
$url = UrlHelper::buildUrl(Urls::URL_INDEX, [$collection, $indexId]);
$response = $this->getConnection()->get($url);
return $response->getJson();
} | [
"public",
"function",
"getIndex",
"(",
"$",
"collection",
",",
"$",
"indexId",
")",
"{",
"$",
"url",
"=",
"UrlHelper",
"::",
"buildUrl",
"(",
"Urls",
"::",
"URL_INDEX",
",",
"[",
"$",
"collection",
",",
"$",
"indexId",
"]",
")",
";",
"$",
"response",
... | Get the information about an index in a collection
@param string $collection - the id of the collection
@param string $indexId - the id of the index
@return array
@throws \ArangoDBClient\Exception
@throws \ArangoDBClient\ClientException | [
"Get",
"the",
"information",
"about",
"an",
"index",
"in",
"a",
"collection"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L1030-L1036 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.getIndexes | public function getIndexes($collectionId)
{
$urlParams = [self::OPTION_COLLECTION => $collectionId];
$url = UrlHelper::appendParamsUrl(Urls::URL_INDEX, $urlParams);
$response = $this->getConnection()->get($url);
return $response->getJson();
} | php | public function getIndexes($collectionId)
{
$urlParams = [self::OPTION_COLLECTION => $collectionId];
$url = UrlHelper::appendParamsUrl(Urls::URL_INDEX, $urlParams);
$response = $this->getConnection()->get($url);
return $response->getJson();
} | [
"public",
"function",
"getIndexes",
"(",
"$",
"collectionId",
")",
"{",
"$",
"urlParams",
"=",
"[",
"self",
"::",
"OPTION_COLLECTION",
"=>",
"$",
"collectionId",
"]",
";",
"$",
"url",
"=",
"UrlHelper",
"::",
"appendParamsUrl",
"(",
"Urls",
"::",
"URL_INDEX",... | Get indexes of a collection
This will throw if the collection cannot be fetched from the server
@throws Exception
@param mixed $collectionId - collection id as a string or number
@return array $data - the indexes result-set from the server | [
"Get",
"indexes",
"of",
"a",
"collection"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L1050-L1057 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.dropIndex | public function dropIndex($indexHandle)
{
$handle = explode('/', $indexHandle);
$this->getConnection()->delete(UrlHelper::buildUrl(Urls::URL_INDEX, [$handle[0], $handle[1]]));
return true;
} | php | public function dropIndex($indexHandle)
{
$handle = explode('/', $indexHandle);
$this->getConnection()->delete(UrlHelper::buildUrl(Urls::URL_INDEX, [$handle[0], $handle[1]]));
return true;
} | [
"public",
"function",
"dropIndex",
"(",
"$",
"indexHandle",
")",
"{",
"$",
"handle",
"=",
"explode",
"(",
"'/'",
",",
"$",
"indexHandle",
")",
";",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"delete",
"(",
"UrlHelper",
"::",
"buildUrl",
"(",
"... | Drop an index
@throws Exception
@param mixed $indexHandle - index handle (collection name / index id)
@return bool - always true, will throw if there is an error | [
"Drop",
"an",
"index"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L1068-L1074 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.any | public function any($collectionId)
{
$_documentClass = $this->_documentClass;
$data = [
self::OPTION_COLLECTION => $collectionId,
];
$response = $this->getConnection()->put(Urls::URL_ANY, $this->json_encode_wrapper($data));
$data = $response->getJson();
if ($data['document']) {
return $_documentClass::createFromArray($data['document']);
}
return null;
} | php | public function any($collectionId)
{
$_documentClass = $this->_documentClass;
$data = [
self::OPTION_COLLECTION => $collectionId,
];
$response = $this->getConnection()->put(Urls::URL_ANY, $this->json_encode_wrapper($data));
$data = $response->getJson();
if ($data['document']) {
return $_documentClass::createFromArray($data['document']);
}
return null;
} | [
"public",
"function",
"any",
"(",
"$",
"collectionId",
")",
"{",
"$",
"_documentClass",
"=",
"$",
"this",
"->",
"_documentClass",
";",
"$",
"data",
"=",
"[",
"self",
"::",
"OPTION_COLLECTION",
"=>",
"$",
"collectionId",
",",
"]",
";",
"$",
"response",
"=... | Get a random document from the collection.
This will throw if the document cannot be fetched from the server
@throws Exception
@param mixed $collectionId - collection id as string or number
@return Document - the document fetched from the server
@since 1.2 | [
"Get",
"a",
"random",
"document",
"from",
"the",
"collection",
"."
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L1089-L1105 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.all | public function all($collectionId, array $options = [])
{
$body = [
self::OPTION_COLLECTION => $collectionId,
];
$body = $this->includeOptionsInBody(
$options,
$body,
[
self::OPTION_LIMIT => null,
self::OPTION_SKIP => null,
]
);
$response = $this->getConnection()->put(Urls::URL_ALL, $this->json_encode_wrapper($body));
if ($batchPart = $response->getBatchPart()) {
return $batchPart;
}
$options = array_merge(['_documentClass' => $this->_documentClass], $options);
return new Cursor($this->getConnection(), $response->getJson(), $options);
} | php | public function all($collectionId, array $options = [])
{
$body = [
self::OPTION_COLLECTION => $collectionId,
];
$body = $this->includeOptionsInBody(
$options,
$body,
[
self::OPTION_LIMIT => null,
self::OPTION_SKIP => null,
]
);
$response = $this->getConnection()->put(Urls::URL_ALL, $this->json_encode_wrapper($body));
if ($batchPart = $response->getBatchPart()) {
return $batchPart;
}
$options = array_merge(['_documentClass' => $this->_documentClass], $options);
return new Cursor($this->getConnection(), $response->getJson(), $options);
} | [
"public",
"function",
"all",
"(",
"$",
"collectionId",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"body",
"=",
"[",
"self",
"::",
"OPTION_COLLECTION",
"=>",
"$",
"collectionId",
",",
"]",
";",
"$",
"body",
"=",
"$",
"this",
"->",
"... | Returns all documents of a collection
@param mixed $collectionId - collection id as string or number
@param array $options - optional array of options.
<p>Options are :<br>
<li>'_sanitize' - True to remove _id and _rev attributes from result documents. Defaults to false.</li>
<li>'_hiddenAttributes' - Set an array of hidden attributes for created documents.
<p>
This is actually the same as setting hidden attributes using setHiddenAttributes() on a document.<br>
The difference is, that if you're returning a result set of documents, the getAll() is already called<br>
and the hidden attributes would not be applied to the attributes.<br>
</p>
<li>'batchSize' - can optionally be used to tell the server to limit the number of results to be transferred in one batch</li>
<li>'skip' - Optional, The number of documents to skip in the query.</li>
<li>'limit' - Optional, The maximal amount of documents to return. 'skip' is applied before the limit restriction.</li>
</li>
</p>
@return Cursor - documents
@throws \ArangoDBClient\Exception
@throws \ArangoDBClient\ClientException | [
"Returns",
"all",
"documents",
"of",
"a",
"collection"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L1132-L1156 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.getAllIds | public function getAllIds($collection)
{
$params = [
self::OPTION_COLLECTION => $this->makeCollection($collection)
];
$response = $this->getConnection()->put(Urls::URL_ALL_KEYS, $this->json_encode_wrapper($params));
$data = $response->getJson();
if (!isset($data[Cursor::ENTRY_RESULT])) {
throw new ClientException('Got an invalid document list from the server');
}
$cursor = new Cursor($this->getConnection(), $response->getJson(), ['_documentClass' => $this->_documentClass]);
$ids = [];
foreach ($cursor->getAll() as $location) {
$ids[] = UrlHelper::getDocumentIdFromLocation($location);
}
return $ids;
} | php | public function getAllIds($collection)
{
$params = [
self::OPTION_COLLECTION => $this->makeCollection($collection)
];
$response = $this->getConnection()->put(Urls::URL_ALL_KEYS, $this->json_encode_wrapper($params));
$data = $response->getJson();
if (!isset($data[Cursor::ENTRY_RESULT])) {
throw new ClientException('Got an invalid document list from the server');
}
$cursor = new Cursor($this->getConnection(), $response->getJson(), ['_documentClass' => $this->_documentClass]);
$ids = [];
foreach ($cursor->getAll() as $location) {
$ids[] = UrlHelper::getDocumentIdFromLocation($location);
}
return $ids;
} | [
"public",
"function",
"getAllIds",
"(",
"$",
"collection",
")",
"{",
"$",
"params",
"=",
"[",
"self",
"::",
"OPTION_COLLECTION",
"=>",
"$",
"this",
"->",
"makeCollection",
"(",
"$",
"collection",
")",
"]",
";",
"$",
"response",
"=",
"$",
"this",
"->",
... | Get the list of all documents' ids from a collection
This will throw if the list cannot be fetched from the server
@throws Exception
@param mixed $collection - collection id as string or number
@return array - ids of documents in the collection | [
"Get",
"the",
"list",
"of",
"all",
"documents",
"ids",
"from",
"a",
"collection"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L1170-L1189 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.byExample | public function byExample($collectionId, $document, array $options = [])
{
$_documentClass = $this->_documentClass;
if (is_array($document)) {
$document = $_documentClass::createFromArray($document, $options);
}
if (!($document instanceof Document)) {
throw new ClientException('Invalid example document specification');
}
$body = [
self::OPTION_COLLECTION => $collectionId,
self::OPTION_EXAMPLE => $document->getAllAsObject(['_ignoreHiddenAttributes' => true])
];
$body = $this->includeOptionsInBody(
$options,
$body,
[
ConnectionOptions::OPTION_BATCHSIZE => $this->getConnectionOption(
ConnectionOptions::OPTION_BATCHSIZE
),
self::OPTION_LIMIT => null,
self::OPTION_SKIP => null,
]
);
$response = $this->getConnection()->put(Urls::URL_EXAMPLE, $this->json_encode_wrapper($body));
if ($batchPart = $response->getBatchPart()) {
return $batchPart;
}
$options['isNew'] = false;
$options = array_merge(['_documentClass' => $this->_documentClass], $options);
return new Cursor($this->getConnection(), $response->getJson(), $options);
} | php | public function byExample($collectionId, $document, array $options = [])
{
$_documentClass = $this->_documentClass;
if (is_array($document)) {
$document = $_documentClass::createFromArray($document, $options);
}
if (!($document instanceof Document)) {
throw new ClientException('Invalid example document specification');
}
$body = [
self::OPTION_COLLECTION => $collectionId,
self::OPTION_EXAMPLE => $document->getAllAsObject(['_ignoreHiddenAttributes' => true])
];
$body = $this->includeOptionsInBody(
$options,
$body,
[
ConnectionOptions::OPTION_BATCHSIZE => $this->getConnectionOption(
ConnectionOptions::OPTION_BATCHSIZE
),
self::OPTION_LIMIT => null,
self::OPTION_SKIP => null,
]
);
$response = $this->getConnection()->put(Urls::URL_EXAMPLE, $this->json_encode_wrapper($body));
if ($batchPart = $response->getBatchPart()) {
return $batchPart;
}
$options['isNew'] = false;
$options = array_merge(['_documentClass' => $this->_documentClass], $options);
return new Cursor($this->getConnection(), $response->getJson(), $options);
} | [
"public",
"function",
"byExample",
"(",
"$",
"collectionId",
",",
"$",
"document",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"_documentClass",
"=",
"$",
"this",
"->",
"_documentClass",
";",
"if",
"(",
"is_array",
"(",
"$",
"document",
... | Get document(s) by specifying an example
This will throw if the list cannot be fetched from the server
@throws Exception
@param mixed $collectionId - collection id as string or number
@param mixed $document - the example document as a Document object or an array
@param 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.
<p>Options are :<br>
<li>'_sanitize' - True to remove _id and _rev attributes from result documents. Defaults to false.</li>
<li>'_hiddenAttributes' - Set an array of hidden attributes for created documents.
<p>
This is actually the same as setting hidden attributes using setHiddenAttributes() on a document. <br>
The difference is, that if you're returning a result set of documents, the getAll() is already called <br>
and the hidden attributes would not be applied to the attributes.<br>
</p>
</li>
<li>'batchSize' - can optionally be used to tell the server to limit the number of results to be transferred in one batch</li>
<li>'skip' - Optional, The number of documents to skip in the query.</li>
<li>'limit' - Optional, The maximal amount of documents to return. 'skip' is applied before the limit restriction.</li>
</p>
@return cursor - Returns a cursor containing the result | [
"Get",
"document",
"(",
"s",
")",
"by",
"specifying",
"an",
"example"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L1218-L1258 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.firstExample | public function firstExample($collectionId, $document, array $options = [])
{
$_documentClass = $this->_documentClass;
if (is_array($document)) {
$document = $_documentClass::createFromArray($document, $options);
}
if (!($document instanceof Document)) {
throw new ClientException('Invalid example document specification');
}
$data = [
self::OPTION_COLLECTION => $collectionId,
self::OPTION_EXAMPLE => $document->getAll(['_ignoreHiddenAttributes' => true])
];
$response = $this->getConnection()->put(Urls::URL_FIRST_EXAMPLE, $this->json_encode_wrapper($data));
if ($batchPart = $response->getBatchPart()) {
return $batchPart;
}
$data = $response->getJson();
$options['_isNew'] = false;
return $_documentClass::createFromArray($data['document'], $options);
} | php | public function firstExample($collectionId, $document, array $options = [])
{
$_documentClass = $this->_documentClass;
if (is_array($document)) {
$document = $_documentClass::createFromArray($document, $options);
}
if (!($document instanceof Document)) {
throw new ClientException('Invalid example document specification');
}
$data = [
self::OPTION_COLLECTION => $collectionId,
self::OPTION_EXAMPLE => $document->getAll(['_ignoreHiddenAttributes' => true])
];
$response = $this->getConnection()->put(Urls::URL_FIRST_EXAMPLE, $this->json_encode_wrapper($data));
if ($batchPart = $response->getBatchPart()) {
return $batchPart;
}
$data = $response->getJson();
$options['_isNew'] = false;
return $_documentClass::createFromArray($data['document'], $options);
} | [
"public",
"function",
"firstExample",
"(",
"$",
"collectionId",
",",
"$",
"document",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"_documentClass",
"=",
"$",
"this",
"->",
"_documentClass",
";",
"if",
"(",
"is_array",
"(",
"$",
"document"... | Get the first document matching a given example.
This will throw if the document cannot be fetched from the server
@throws Exception
@param mixed $collectionId - collection id as string or number
@param mixed $document - the example document as a Document object or an array
@param array $options - optional, an array of options.
<p>Options are :<br>
<li>'_sanitize' - True to remove _id and _rev attributes from result documents. Defaults to false.</li>
<li>'_hiddenAttributes' - Set an array of hidden attributes for created documents.
<p>
This is actually the same as setting hidden attributes using setHiddenAttributes() on a document. <br>
The difference is, that if you're returning a result set of documents, the getAll() is already called <br>
and the hidden attributes would not be applied to the attributes.<br>
</p>
</li>
</p>
@return Document - the document fetched from the server
@since 1.2 | [
"Get",
"the",
"first",
"document",
"matching",
"a",
"given",
"example",
"."
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L1285-L1313 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.fulltext | public function fulltext($collection, $attribute, $query, array $options = [])
{
$body = [
self::OPTION_COLLECTION => $collection,
self::OPTION_ATTRIBUTE => $attribute,
self::OPTION_QUERY => $query,
];
$body = $this->includeOptionsInBody(
$options,
$body,
[
ConnectionOptions::OPTION_BATCHSIZE => $this->getConnectionOption(
ConnectionOptions::OPTION_BATCHSIZE
),
self::OPTION_LIMIT => null,
self::OPTION_SKIP => null,
self::OPTION_INDEX => null,
]
);
$response = $this->getConnection()->put(Urls::URL_FULLTEXT, $this->json_encode_wrapper($body));
$options['_isNew'] = false;
$options = array_merge(['_documentClass' => $this->_documentClass], $options);
return new Cursor($this->getConnection(), $response->getJson(), $options);
} | php | public function fulltext($collection, $attribute, $query, array $options = [])
{
$body = [
self::OPTION_COLLECTION => $collection,
self::OPTION_ATTRIBUTE => $attribute,
self::OPTION_QUERY => $query,
];
$body = $this->includeOptionsInBody(
$options,
$body,
[
ConnectionOptions::OPTION_BATCHSIZE => $this->getConnectionOption(
ConnectionOptions::OPTION_BATCHSIZE
),
self::OPTION_LIMIT => null,
self::OPTION_SKIP => null,
self::OPTION_INDEX => null,
]
);
$response = $this->getConnection()->put(Urls::URL_FULLTEXT, $this->json_encode_wrapper($body));
$options['_isNew'] = false;
$options = array_merge(['_documentClass' => $this->_documentClass], $options);
return new Cursor($this->getConnection(), $response->getJson(), $options);
} | [
"public",
"function",
"fulltext",
"(",
"$",
"collection",
",",
"$",
"attribute",
",",
"$",
"query",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"body",
"=",
"[",
"self",
"::",
"OPTION_COLLECTION",
"=>",
"$",
"collection",
",",
"self",
... | Get document(s) by a fulltext query
This will find all documents from the collection that match the fulltext query specified in query.
In order to use the fulltext operator, a fulltext index must be defined for the collection and the specified attribute.
@throws Exception
@param mixed $collection - collection id as string or number
@param mixed $attribute - The attribute that contains the texts.
@param mixed $query - The fulltext query.
@param 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.
<p>Options are :<br>
<li>'_sanitize' - True to remove _id and _rev attributes from result documents. Defaults to false.</li>
<li>'_hiddenAttributes' - Set an array of hidden attributes for created documents.
<p>
This is actually the same as setting hidden attributes using setHiddenAttributes() on a document. <br>
The difference is, that if you're returning a result set of documents, the getAll() is already called <br>
and the hidden attributes would not be applied to the attributes.<br>
</p>
</li>
<li>'batchSize' - can optionally be used to tell the server to limit the number of results to be transferred in one batch</li>
<li>'skip' - Optional, The number of documents to skip in the query.</li>
<li>'limit' - Optional, The maximal amount of documents to return. 'skip' is applied before the limit restriction.</li>
<li>'index' - If given, the identifier of the fulltext-index to use.</li>
</p>
@return cursor - Returns a cursor containing the result | [
"Get",
"document",
"(",
"s",
")",
"by",
"a",
"fulltext",
"query"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L1346-L1374 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.updateByExample | public function updateByExample($collectionId, $example, $newValue, array $options = [])
{
$_documentClass = $this->_documentClass;
if (is_array($example)) {
$example = $_documentClass::createFromArray($example);
}
if (is_array($newValue)) {
$newValue = $_documentClass::createFromArray($newValue);
}
$body = [
self::OPTION_COLLECTION => $collectionId,
self::OPTION_EXAMPLE => $example->getAllAsObject(['_ignoreHiddenAttributes' => true]),
self::OPTION_NEW_VALUE => $newValue->getAllAsObject(['_ignoreHiddenAttributes' => true])
];
$body = $this->includeOptionsInBody(
$options,
$body,
[
ConnectionOptions::OPTION_WAIT_SYNC => $this->getConnectionOption(
ConnectionOptions::OPTION_WAIT_SYNC
),
'keepNull' => true,
self::OPTION_LIMIT => null,
]
);
$response = $this->getConnection()->put(Urls::URL_UPDATE_BY_EXAMPLE, $this->json_encode_wrapper($body));
$responseArray = $response->getJson();
if ($responseArray['error'] === true) {
throw new ClientException('Invalid example document specification');
}
return $responseArray['updated'];
} | php | public function updateByExample($collectionId, $example, $newValue, array $options = [])
{
$_documentClass = $this->_documentClass;
if (is_array($example)) {
$example = $_documentClass::createFromArray($example);
}
if (is_array($newValue)) {
$newValue = $_documentClass::createFromArray($newValue);
}
$body = [
self::OPTION_COLLECTION => $collectionId,
self::OPTION_EXAMPLE => $example->getAllAsObject(['_ignoreHiddenAttributes' => true]),
self::OPTION_NEW_VALUE => $newValue->getAllAsObject(['_ignoreHiddenAttributes' => true])
];
$body = $this->includeOptionsInBody(
$options,
$body,
[
ConnectionOptions::OPTION_WAIT_SYNC => $this->getConnectionOption(
ConnectionOptions::OPTION_WAIT_SYNC
),
'keepNull' => true,
self::OPTION_LIMIT => null,
]
);
$response = $this->getConnection()->put(Urls::URL_UPDATE_BY_EXAMPLE, $this->json_encode_wrapper($body));
$responseArray = $response->getJson();
if ($responseArray['error'] === true) {
throw new ClientException('Invalid example document specification');
}
return $responseArray['updated'];
} | [
"public",
"function",
"updateByExample",
"(",
"$",
"collectionId",
",",
"$",
"example",
",",
"$",
"newValue",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"_documentClass",
"=",
"$",
"this",
"->",
"_documentClass",
";",
"if",
"(",
"is_arra... | Update document(s) matching a given example
This will update the document(s) on the server
This will throw if the document cannot be updated
@throws Exception
@param mixed $collectionId - collection id as string or number
@param mixed $example - the example document as a Document object or an array
@param mixed $newValue - patch document or array which contains the attributes and values to be updated
@param mixed $options - optional, array of options (see below) or the boolean value for $policy (for compatibility prior to version 1.1 of this method)
<p>Options are :
<li>'keepNull' - can be used to instruct ArangoDB to delete existing attributes instead setting their values to null. Defaults to true (keep attributes when set to null)</li>
<li>'waitForSync' - can be used to force synchronisation of the document update operation to disk even in case that the waitForSync flag had been disabled for the entire collection</li>
<li>'limit' - can be used set a limit on how many documents to update at most. If limit is specified but is less than the number of documents in the collection, it is undefined which of the documents will be updated.</li>
</p>
@return bool - always true, will throw if there is an error
@since 1.2 | [
"Update",
"document",
"(",
"s",
")",
"matching",
"a",
"given",
"example"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L1399-L1438 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.removeByExample | public function removeByExample($collectionId, $document, array $options = [])
{
$_documentClass = $this->_documentClass;
if (is_array($document)) {
$document = $_documentClass::createFromArray($document, $options);
}
if (!($document instanceof Document)) {
throw new ClientException('Invalid example document specification');
}
$body = [
self::OPTION_COLLECTION => $collectionId,
self::OPTION_EXAMPLE => $document->getAllAsObject(['_ignoreHiddenAttributes' => true])
];
$body = $this->includeOptionsInBody(
$options,
$body,
[
ConnectionOptions::OPTION_WAIT_SYNC => $this->getConnectionOption(
ConnectionOptions::OPTION_WAIT_SYNC
),
self::OPTION_LIMIT => null,
]
);
$response = $this->getConnection()->put(Urls::URL_REMOVE_BY_EXAMPLE, $this->json_encode_wrapper($body));
$responseArray = $response->getJson();
if ($responseArray['error'] === true) {
throw new ClientException('Invalid example document specification');
}
return $responseArray['deleted'];
} | php | public function removeByExample($collectionId, $document, array $options = [])
{
$_documentClass = $this->_documentClass;
if (is_array($document)) {
$document = $_documentClass::createFromArray($document, $options);
}
if (!($document instanceof Document)) {
throw new ClientException('Invalid example document specification');
}
$body = [
self::OPTION_COLLECTION => $collectionId,
self::OPTION_EXAMPLE => $document->getAllAsObject(['_ignoreHiddenAttributes' => true])
];
$body = $this->includeOptionsInBody(
$options,
$body,
[
ConnectionOptions::OPTION_WAIT_SYNC => $this->getConnectionOption(
ConnectionOptions::OPTION_WAIT_SYNC
),
self::OPTION_LIMIT => null,
]
);
$response = $this->getConnection()->put(Urls::URL_REMOVE_BY_EXAMPLE, $this->json_encode_wrapper($body));
$responseArray = $response->getJson();
if ($responseArray['error'] === true) {
throw new ClientException('Invalid example document specification');
}
return $responseArray['deleted'];
} | [
"public",
"function",
"removeByExample",
"(",
"$",
"collectionId",
",",
"$",
"document",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"_documentClass",
"=",
"$",
"this",
"->",
"_documentClass",
";",
"if",
"(",
"is_array",
"(",
"$",
"docume... | Remove document(s) by specifying an example
This will throw on any error
@throws Exception
@param mixed $collectionId - collection id as string or number
@param mixed $document - the example document as a Document object or an array
@param array $options - optional - an array of options.
<p>Options are :<br>
<li>
'waitForSync' - if set to true, then all removal operations will instantly be synchronised to disk.<br>
If this is not specified, then the collection's default sync behavior will be applied.
</li>
</p>
<li>'limit' - Optional, The maximal amount of documents to return. 'skip' is applied before the limit restriction.</li>
@return int - number of documents that were deleted
@since 1.2 | [
"Remove",
"document",
"(",
"s",
")",
"by",
"specifying",
"an",
"example"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L1527-L1564 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.removeByKeys | public function removeByKeys($collectionId, array $keys, array $options = [])
{
$body = [
self::OPTION_COLLECTION => $collectionId,
self::OPTION_KEYS => $keys
];
$body = $this->includeOptionsInBody(
$options,
$body,
[
ConnectionOptions::OPTION_WAIT_SYNC => $this->getConnectionOption(
ConnectionOptions::OPTION_WAIT_SYNC
)
]
);
$response = $this->getConnection()->put(Urls::URL_REMOVE_BY_KEYS, $this->json_encode_wrapper($body));
if ($batchPart = $response->getBatchPart()) {
return $batchPart;
}
$responseArray = $response->getJson();
return [
'removed' => $responseArray['removed'],
'ignored' => $responseArray['ignored']
];
} | php | public function removeByKeys($collectionId, array $keys, array $options = [])
{
$body = [
self::OPTION_COLLECTION => $collectionId,
self::OPTION_KEYS => $keys
];
$body = $this->includeOptionsInBody(
$options,
$body,
[
ConnectionOptions::OPTION_WAIT_SYNC => $this->getConnectionOption(
ConnectionOptions::OPTION_WAIT_SYNC
)
]
);
$response = $this->getConnection()->put(Urls::URL_REMOVE_BY_KEYS, $this->json_encode_wrapper($body));
if ($batchPart = $response->getBatchPart()) {
return $batchPart;
}
$responseArray = $response->getJson();
return [
'removed' => $responseArray['removed'],
'ignored' => $responseArray['ignored']
];
} | [
"public",
"function",
"removeByKeys",
"(",
"$",
"collectionId",
",",
"array",
"$",
"keys",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"body",
"=",
"[",
"self",
"::",
"OPTION_COLLECTION",
"=>",
"$",
"collectionId",
",",
"self",
"::",
"O... | Remove document(s) by specifying an array of keys
This will throw on any error
@throws Exception
@param mixed $collectionId - collection id as string or number
@param array $keys - array of document keys
@param array $options - optional - an array of options.
<p>Options are :<br>
<li>
'waitForSync' - if set to true, then all removal operations will instantly be synchronised to disk.<br>
If this is not specified, then the collection's default sync behavior will be applied.
</li>
</p>
@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
@since 2.6 | [
"Remove",
"document",
"(",
"s",
")",
"by",
"specifying",
"an",
"array",
"of",
"keys"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L1587-L1616 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.lookupByKeys | public function lookupByKeys($collectionId, array $keys, array $options = [])
{
$_documentClass = $this->_documentClass;
$body = [
self::OPTION_COLLECTION => $collectionId,
self::OPTION_KEYS => $keys
];
$response = $this->getConnection()->put(Urls::URL_LOOKUP_BY_KEYS, $this->json_encode_wrapper($body));
$responseArray = $response->getJson();
$result = [];
foreach ($responseArray['documents'] as $document) {
$result[] = $_documentClass::createFromArray($document, $options);
}
return $result;
} | php | public function lookupByKeys($collectionId, array $keys, array $options = [])
{
$_documentClass = $this->_documentClass;
$body = [
self::OPTION_COLLECTION => $collectionId,
self::OPTION_KEYS => $keys
];
$response = $this->getConnection()->put(Urls::URL_LOOKUP_BY_KEYS, $this->json_encode_wrapper($body));
$responseArray = $response->getJson();
$result = [];
foreach ($responseArray['documents'] as $document) {
$result[] = $_documentClass::createFromArray($document, $options);
}
return $result;
} | [
"public",
"function",
"lookupByKeys",
"(",
"$",
"collectionId",
",",
"array",
"$",
"keys",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"_documentClass",
"=",
"$",
"this",
"->",
"_documentClass",
";",
"$",
"body",
"=",
"[",
"self",
"::",... | Bulk lookup documents by specifying an array of keys
This will throw on any error
@throws Exception
@param mixed $collectionId - collection id as string or number
@param array $keys - array of document keys
@param array $options - optional array of options.
<p>Options are :<br>
<li>'_sanitize' - True to remove _id and _rev attributes from result documents. Defaults to false.</li>
<li>'_hiddenAttributes' - Set an array of hidden attributes for created documents.
</p>
@return array - an array containing all documents found for the keys specified.
note that if for a given key not document is found, it will not be returned nor will the document's non-existence be reported.
@since 2.6 | [
"Bulk",
"lookup",
"documents",
"by",
"specifying",
"an",
"array",
"of",
"keys"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L1639-L1658 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.range | public function range($collectionId, $attribute, $left, $right, array $options = [])
{
if ($attribute === '') {
throw new ClientException('Invalid attribute specification');
}
if (strpos($attribute, '.') !== false) {
// split attribute name
$attribute = explode('.', $attribute);
}
$body = [
self::OPTION_COLLECTION => $collectionId,
self::OPTION_ATTRIBUTE => $attribute,
self::OPTION_LEFT => $left,
self::OPTION_RIGHT => $right
];
$body = $this->includeOptionsInBody(
$options,
$body,
[
self::OPTION_CLOSED => null,
self::OPTION_LIMIT => null,
self::OPTION_SKIP => null,
]
);
$response = $this->getConnection()->put(Urls::URL_RANGE, $this->json_encode_wrapper($body));
$options = array_merge(['_documentClass' => $this->_documentClass], $options);
return new Cursor($this->getConnection(), $response->getJson(), $options);
} | php | public function range($collectionId, $attribute, $left, $right, array $options = [])
{
if ($attribute === '') {
throw new ClientException('Invalid attribute specification');
}
if (strpos($attribute, '.') !== false) {
// split attribute name
$attribute = explode('.', $attribute);
}
$body = [
self::OPTION_COLLECTION => $collectionId,
self::OPTION_ATTRIBUTE => $attribute,
self::OPTION_LEFT => $left,
self::OPTION_RIGHT => $right
];
$body = $this->includeOptionsInBody(
$options,
$body,
[
self::OPTION_CLOSED => null,
self::OPTION_LIMIT => null,
self::OPTION_SKIP => null,
]
);
$response = $this->getConnection()->put(Urls::URL_RANGE, $this->json_encode_wrapper($body));
$options = array_merge(['_documentClass' => $this->_documentClass], $options);
return new Cursor($this->getConnection(), $response->getJson(), $options);
} | [
"public",
"function",
"range",
"(",
"$",
"collectionId",
",",
"$",
"attribute",
",",
"$",
"left",
",",
"$",
"right",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"attribute",
"===",
"''",
")",
"{",
"throw",
"new",
"ClientE... | Get document(s) by specifying range
This will throw if the list cannot be fetched from the server
@throws Exception
@param mixed $collectionId - collection id as string or number
@param string $attribute - the attribute path , like 'a', 'a.b', etc...
@param mixed $left - The lower bound.
@param mixed $right - The upper bound.
@param array $options - optional array of options.
<p>Options are :<br>
<li>'_sanitize' - True to remove _id and _rev attributes from result documents. Defaults to false.</li>
<li>'_hiddenAttributes' - Set an array of hidden attributes for created documents.
<p>
This is actually the same as setting hidden attributes using setHiddenAttributes() on a document.<br>
The difference is, that if you're returning a result set of documents, the getAll() is already called<br>
and the hidden attributes would not be applied to the attributes.<br>
</p>
<li>'closed' - If true, use interval including left and right, otherwise exclude right, but include left.
<li>'batchSize' - can optionally be used to tell the server to limit the number of results to be transferred in one batch</li>
<li>'skip' - Optional, The number of documents to skip in the query.</li>
<li>'limit' - Optional, The maximal amount of documents to return. 'skip' is applied before the limit restriction.</li>
</li>
</p>
@return Cursor - documents matching the example [0...n] | [
"Get",
"document",
"(",
"s",
")",
"by",
"specifying",
"range"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L1692-L1725 |
arangodb/arangodb-php | lib/ArangoDBClient/CollectionHandler.php | CollectionHandler.within | public function within($collectionId, $latitude, $longitude, $radius, array $options = [])
{
$body = [
self::OPTION_COLLECTION => $collectionId,
self::OPTION_LATITUDE => $latitude,
self::OPTION_LONGITUDE => $longitude,
self::OPTION_RADIUS => $radius
];
$body = $this->includeOptionsInBody(
$options,
$body,
[
self::OPTION_DISTANCE => null,
self::OPTION_LIMIT => null,
self::OPTION_SKIP => null,
]
);
$response = $this->getConnection()->put(Urls::URL_WITHIN, $this->json_encode_wrapper($body));
$options = array_merge(['_documentClass' => $this->_documentClass], $options);
return new Cursor($this->getConnection(), $response->getJson(), $options);
} | php | public function within($collectionId, $latitude, $longitude, $radius, array $options = [])
{
$body = [
self::OPTION_COLLECTION => $collectionId,
self::OPTION_LATITUDE => $latitude,
self::OPTION_LONGITUDE => $longitude,
self::OPTION_RADIUS => $radius
];
$body = $this->includeOptionsInBody(
$options,
$body,
[
self::OPTION_DISTANCE => null,
self::OPTION_LIMIT => null,
self::OPTION_SKIP => null,
]
);
$response = $this->getConnection()->put(Urls::URL_WITHIN, $this->json_encode_wrapper($body));
$options = array_merge(['_documentClass' => $this->_documentClass], $options);
return new Cursor($this->getConnection(), $response->getJson(), $options);
} | [
"public",
"function",
"within",
"(",
"$",
"collectionId",
",",
"$",
"latitude",
",",
"$",
"longitude",
",",
"$",
"radius",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"body",
"=",
"[",
"self",
"::",
"OPTION_COLLECTION",
"=>",
"$",
"co... | Get document(s) by specifying within
This will throw if the list cannot be fetched from the server
@throws Exception
@param mixed $collectionId - collection id as string or number
@param double $latitude - The latitude of the coordinate.
@param double $longitude - The longitude of the coordinate.
@param int $radius - The maximal radius (in meters).
@param array $options - optional array of options.
<p>Options are :<br>
<li>'_sanitize' - True to remove _id and _rev attributes from result documents. Defaults to false.</li>
<li>'_hiddenAttributes' - Set an array of hidden attributes for created documents.
<p>
This is actually the same as setting hidden attributes using setHiddenAttributes() on a document.<br>
The difference is, that if you're returning a result set of documents, the getAll() is already called <br>
and the hidden attributes would not be applied to the attributes.<br>
</p>
<li>'distance' - If given, the attribute key used to store the distance. (optional)
<li>'batchSize' - can optionally be used to tell the server to limit the number of results to be transferred in one batch</li>
<li>'skip' - Optional, The number of documents to skip in the query.</li>
<li>'limit' - Optional, The maximal amount of documents to return. 'skip' is applied before the limit restriction.</li>
</li>
</p>
@return Cursor - documents matching the example [0...n] | [
"Get",
"document",
"(",
"s",
")",
"by",
"specifying",
"within"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/CollectionHandler.php#L1815-L1839 |
arangodb/arangodb-php | lib/ArangoDBClient/AdminHandler.php | AdminHandler.getServerVersion | public function getServerVersion($details = false)
{
$url = Urls::URL_ADMIN_VERSION;
if ($details) {
$url = UrlHelper::appendParamsUrl($url, ['details' => true]);
}
$response = $this->getConnection()->get($url);
$data = $response->getJson();
if ($details) {
return $data;
}
return $data['version'];
} | php | public function getServerVersion($details = false)
{
$url = Urls::URL_ADMIN_VERSION;
if ($details) {
$url = UrlHelper::appendParamsUrl($url, ['details' => true]);
}
$response = $this->getConnection()->get($url);
$data = $response->getJson();
if ($details) {
return $data;
}
return $data['version'];
} | [
"public",
"function",
"getServerVersion",
"(",
"$",
"details",
"=",
"false",
")",
"{",
"$",
"url",
"=",
"Urls",
"::",
"URL_ADMIN_VERSION",
";",
"if",
"(",
"$",
"details",
")",
"{",
"$",
"url",
"=",
"UrlHelper",
"::",
"appendParamsUrl",
"(",
"$",
"url",
... | Get the server version
This will throw if the version cannot be retrieved
@param bool $details - True to get a more detailed response
@throws Exception
@return string - a string holding the ArangoDB version
@since 1.2 | [
"Get",
"the",
"server",
"version"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/AdminHandler.php#L59-L75 |
arangodb/arangodb-php | lib/ArangoDBClient/AdminHandler.php | AdminHandler.getServerRole | public function getServerRole()
{
$url = Urls::URL_ADMIN_SERVER_ROLE;
$response = $this->getConnection()->get($url);
$data = $response->getJson();
return $data['role'];
} | php | public function getServerRole()
{
$url = Urls::URL_ADMIN_SERVER_ROLE;
$response = $this->getConnection()->get($url);
$data = $response->getJson();
return $data['role'];
} | [
"public",
"function",
"getServerRole",
"(",
")",
"{",
"$",
"url",
"=",
"Urls",
"::",
"URL_ADMIN_SERVER_ROLE",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"get",
"(",
"$",
"url",
")",
";",
"$",
"data",
"=",
"$",
"res... | Get the server role
This will throw if the role cannot be retrieved
@throws Exception
@return string - a string holding the server role (e.g. UNDEFINED, COORDINATOR, DBSERVER)
@since 2.0 | [
"Get",
"the",
"server",
"role"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/AdminHandler.php#L87-L94 |
arangodb/arangodb-php | lib/ArangoDBClient/AdminHandler.php | AdminHandler.getServerTime | public function getServerTime()
{
$response = $this->getConnection()->get(Urls::URL_ADMIN_TIME);
$data = $response->getJson();
return $data['time'];
} | php | public function getServerTime()
{
$response = $this->getConnection()->get(Urls::URL_ADMIN_TIME);
$data = $response->getJson();
return $data['time'];
} | [
"public",
"function",
"getServerTime",
"(",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"get",
"(",
"Urls",
"::",
"URL_ADMIN_TIME",
")",
";",
"$",
"data",
"=",
"$",
"response",
"->",
"getJson",
"(",
")",
";",
"... | Get the server time
This will throw if the time cannot be retrieved
@throws Exception
@return double - a double holding the timestamp
@since 1.2 | [
"Get",
"the",
"server",
"time"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/AdminHandler.php#L107-L113 |
arangodb/arangodb-php | lib/ArangoDBClient/AdminHandler.php | AdminHandler.getServerLog | public function getServerLog(array $options = [])
{
$url = UrlHelper::appendParamsUrl(Urls::URL_ADMIN_LOG, $options);
$response = $this->getConnection()->get($url);
return $response->getJson();
} | php | public function getServerLog(array $options = [])
{
$url = UrlHelper::appendParamsUrl(Urls::URL_ADMIN_LOG, $options);
$response = $this->getConnection()->get($url);
return $response->getJson();
} | [
"public",
"function",
"getServerLog",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"url",
"=",
"UrlHelper",
"::",
"appendParamsUrl",
"(",
"Urls",
"::",
"URL_ADMIN_LOG",
",",
"$",
"options",
")",
";",
"$",
"response",
"=",
"$",
"this",
"-... | Get the server log
This will throw if the log cannot be retrieved
@throws Exception
@param array $options - an array of options that define the result-set:
<p>Options are :<br>
<li>'upto' - returns all log entries up to a log-level. Note that log-level must be one of:</li>
<p>
<li>fatal / 0</li>
<li>error / 1</li>
<li>warning / 2</li>
<li>info / 3</li>
<li>debug / 4</li>
</p>
<li>'level' - limits the log entries to the ones defined in level. Note that `level` and `upto` are mutably exclusive.</li>
<li>'offset' - skip the first offset entries.</li>
<li>'size' - limit the number of returned log-entries to size.</li>
<li>'start' - Returns all log entries such that their log-entry identifier is greater or equal to lid.</li>
<li>'sort' - Sort the log-entries either ascending if direction is asc, or descending if it is desc according to their lid. Note that the lid imposes a chronological order.</li>
<li>'search' - Only return the log-entries containing the text string...</li>
</p>
@return array - an array holding the various attributes of a log: lid, level, timestamp, text and the total amount of log entries before pagination.
@since 1.2 | [
"Get",
"the",
"server",
"log"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/AdminHandler.php#L145-L151 |
arangodb/arangodb-php | lib/ArangoDBClient/AdminHandler.php | AdminHandler.getServerStatistics | public function getServerStatistics()
{
$url = UrlHelper::appendParamsUrl(Urls::URL_ADMIN_STATISTICS, []);
$response = $this->getConnection()->get($url);
return $response->getJson();
} | php | public function getServerStatistics()
{
$url = UrlHelper::appendParamsUrl(Urls::URL_ADMIN_STATISTICS, []);
$response = $this->getConnection()->get($url);
return $response->getJson();
} | [
"public",
"function",
"getServerStatistics",
"(",
")",
"{",
"$",
"url",
"=",
"UrlHelper",
"::",
"appendParamsUrl",
"(",
"Urls",
"::",
"URL_ADMIN_STATISTICS",
",",
"[",
"]",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",... | Get the server statistics
Returns the statistics information. The returned objects contains the statistics figures, grouped together
according to the description returned by _admin/statistics-description.
For instance, to access a figure userTime from the group system, you first select the sub-object
describing the group stored in system and in that sub-object the value for userTime is stored in the
attribute of the same name.In case of a distribution, the returned object contains the total count in count
and the distribution list in counts.
For more information on the statistics returned, please lookup the statistics interface description at
@link https://docs.arangodb.com/HTTP/AdministrationAndMonitoring/index.html
This will throw if the statistics cannot be retrieved
@throws Exception
@return array
@see getServerStatisticsDescription()
@since 1.3 | [
"Get",
"the",
"server",
"statistics",
"Returns",
"the",
"statistics",
"information",
".",
"The",
"returned",
"objects",
"contains",
"the",
"statistics",
"figures",
"grouped",
"together",
"according",
"to",
"the",
"description",
"returned",
"by",
"_admin",
"/",
"st... | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/AdminHandler.php#L195-L201 |
arangodb/arangodb-php | lib/ArangoDBClient/AdminHandler.php | AdminHandler.getServerStatisticsDescription | public function getServerStatisticsDescription(array $options = [])
{
$url = UrlHelper::appendParamsUrl(Urls::URL_ADMIN_STATISTICS_DESCRIPTION, $options);
$response = $this->getConnection()->get($url);
return $response->getJson();
} | php | public function getServerStatisticsDescription(array $options = [])
{
$url = UrlHelper::appendParamsUrl(Urls::URL_ADMIN_STATISTICS_DESCRIPTION, $options);
$response = $this->getConnection()->get($url);
return $response->getJson();
} | [
"public",
"function",
"getServerStatisticsDescription",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"url",
"=",
"UrlHelper",
"::",
"appendParamsUrl",
"(",
"Urls",
"::",
"URL_ADMIN_STATISTICS_DESCRIPTION",
",",
"$",
"options",
")",
";",
"$",
"re... | Returns a description of the statistics returned by getServerStatistics().
The returned objects contains a list of statistics groups in the attribute groups
and a list of statistics figures in the attribute figures.
For more information on the statistics returned, please lookup the statistics interface description at
@link https://docs.arangodb.com/HTTP/AdministrationAndMonitoring/index.html
This will throw if the statistics-description cannot be retrieved
@throws Exception
@param array $options - an array of options that define the result-set:
<p>Options are :<br>
<li>'granularity' - use minutes for a granularity of minutes, hours for hours, and days for days. The default is minutes.</li>
<li>'figures' - a list of figures, comma-separated. Possible figures are httpConnections. You can use all to get all figures. The default is httpConnections.</li>
<li>'length' - If you want a time series, the maximal length of the series as integer. You can use all to get all available information. You can use current to get the latest interval.</li>
@return array
@see getServerStatistics()
@since 1.3 | [
"Returns",
"a",
"description",
"of",
"the",
"statistics",
"returned",
"by",
"getServerStatistics",
"()",
".",
"The",
"returned",
"objects",
"contains",
"a",
"list",
"of",
"statistics",
"groups",
"in",
"the",
"attribute",
"groups",
"and",
"a",
"list",
"of",
"st... | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/AdminHandler.php#L229-L235 |
arangodb/arangodb-php | lib/ArangoDBClient/ExportCursor.php | ExportCursor.getNextBatch | public function getNextBatch()
{
if ($this->_result === [] && $this->_hasMore) {
// read more from server
$this->fetchOutstanding();
}
if ($this->_result !== []) {
$result = $this->_result;
$this->_result = [];
return $result;
}
// cursor is exhausted
return false;
} | php | public function getNextBatch()
{
if ($this->_result === [] && $this->_hasMore) {
// read more from server
$this->fetchOutstanding();
}
if ($this->_result !== []) {
$result = $this->_result;
$this->_result = [];
return $result;
}
// cursor is exhausted
return false;
} | [
"public",
"function",
"getNextBatch",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_result",
"===",
"[",
"]",
"&&",
"$",
"this",
"->",
"_hasMore",
")",
"{",
"// read more from server",
"$",
"this",
"->",
"fetchOutstanding",
"(",
")",
";",
"}",
"if",
"... | Get next results as an array
This might issue additional HTTP requests to fetch any outstanding
results from the server
@throws Exception
@return mixed - an array with the next results or false if the cursor is exhausted | [
"Get",
"next",
"results",
"as",
"an",
"array"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/ExportCursor.php#L183-L199 |
arangodb/arangodb-php | lib/ArangoDBClient/ExportCursor.php | ExportCursor.setData | private function setData(array $data)
{
$_documentClass = $this->_documentClass;
$_edgeClass = $this->_edgeClass;
if (isset($this->_options[self::ENTRY_FLAT]) && $this->_options[self::ENTRY_FLAT]) {
$this->_result = $data;
} else {
$this->_result = [];
if ($this->_options[self::ENTRY_TYPE] === Collection::TYPE_EDGE) {
foreach ($data as $row) {
$this->_result[] = $_edgeClass::createFromArray($row, $this->_options);
}
} else {
foreach ($data as $row) {
$this->_result[] = $_documentClass::createFromArray($row, $this->_options);
}
}
}
} | php | private function setData(array $data)
{
$_documentClass = $this->_documentClass;
$_edgeClass = $this->_edgeClass;
if (isset($this->_options[self::ENTRY_FLAT]) && $this->_options[self::ENTRY_FLAT]) {
$this->_result = $data;
} else {
$this->_result = [];
if ($this->_options[self::ENTRY_TYPE] === Collection::TYPE_EDGE) {
foreach ($data as $row) {
$this->_result[] = $_edgeClass::createFromArray($row, $this->_options);
}
} else {
foreach ($data as $row) {
$this->_result[] = $_documentClass::createFromArray($row, $this->_options);
}
}
}
} | [
"private",
"function",
"setData",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"_documentClass",
"=",
"$",
"this",
"->",
"_documentClass",
";",
"$",
"_edgeClass",
"=",
"$",
"this",
"->",
"_edgeClass",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_opt... | Create an array of results from the input array
@param array $data - incoming result
@return void
@throws \ArangoDBClient\ClientException | [
"Create",
"an",
"array",
"of",
"results",
"from",
"the",
"input",
"array"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/ExportCursor.php#L209-L229 |
arangodb/arangodb-php | lib/ArangoDBClient/ExportCursor.php | ExportCursor.url | private function url()
{
if (isset($this->_options[self::ENTRY_BASEURL])) {
return $this->_options[self::ENTRY_BASEURL];
}
// this is the default
return Urls::URL_EXPORT;
} | php | private function url()
{
if (isset($this->_options[self::ENTRY_BASEURL])) {
return $this->_options[self::ENTRY_BASEURL];
}
// this is the default
return Urls::URL_EXPORT;
} | [
"private",
"function",
"url",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_options",
"[",
"self",
"::",
"ENTRY_BASEURL",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_options",
"[",
"self",
"::",
"ENTRY_BASEURL",
"]",
";",
"}",
... | Return the base URL for the cursor
@return string | [
"Return",
"the",
"base",
"URL",
"for",
"the",
"cursor"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/ExportCursor.php#L260-L268 |
arangodb/arangodb-php | lib/ArangoDBClient/Database.php | Database.create | public static function create(Connection $connection, $name)
{
$payload = [
self::ENTRY_DATABASE_NAME => $name,
self::ENTRY_DATABASE_USERS => [
[
'username' => $connection->getOption(ConnectionOptions::OPTION_AUTH_USER),
'passwd' => $connection->getOption(ConnectionOptions::OPTION_AUTH_PASSWD)
]
]
];
$response = $connection->post(Urls::URL_DATABASE, $connection->json_encode_wrapper($payload));
return $response->getJson();
} | php | public static function create(Connection $connection, $name)
{
$payload = [
self::ENTRY_DATABASE_NAME => $name,
self::ENTRY_DATABASE_USERS => [
[
'username' => $connection->getOption(ConnectionOptions::OPTION_AUTH_USER),
'passwd' => $connection->getOption(ConnectionOptions::OPTION_AUTH_PASSWD)
]
]
];
$response = $connection->post(Urls::URL_DATABASE, $connection->json_encode_wrapper($payload));
return $response->getJson();
} | [
"public",
"static",
"function",
"create",
"(",
"Connection",
"$",
"connection",
",",
"$",
"name",
")",
"{",
"$",
"payload",
"=",
"[",
"self",
"::",
"ENTRY_DATABASE_NAME",
"=>",
"$",
"name",
",",
"self",
"::",
"ENTRY_DATABASE_USERS",
"=>",
"[",
"[",
"'usern... | creates a database
This creates a new database<br>
@param Connection $connection - the connection to be used
@param string $name - the database specification, for example 'myDatabase'
@link https://docs.arangodb.com/HTTP/Database/index.html
@return array $responseArray - The response array.
@throws \ArangoDBClient\Exception
@throws \ArangoDBClient\ClientException | [
"creates",
"a",
"database"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Database.php#L49-L64 |
arangodb/arangodb-php | lib/ArangoDBClient/Database.php | Database.delete | public static function delete(Connection $connection, $name)
{
$url = UrlHelper::buildUrl(Urls::URL_DATABASE, [$name]);
$response = $connection->delete($url);
return $response->getJson();
} | php | public static function delete(Connection $connection, $name)
{
$url = UrlHelper::buildUrl(Urls::URL_DATABASE, [$name]);
$response = $connection->delete($url);
return $response->getJson();
} | [
"public",
"static",
"function",
"delete",
"(",
"Connection",
"$",
"connection",
",",
"$",
"name",
")",
"{",
"$",
"url",
"=",
"UrlHelper",
"::",
"buildUrl",
"(",
"Urls",
"::",
"URL_DATABASE",
",",
"[",
"$",
"name",
"]",
")",
";",
"$",
"response",
"=",
... | Deletes a database
This will delete an existing database.
@param Connection $connection - the connection to be used
@param string $name - the database specification, for example 'myDatabase'
@link https://docs.arangodb.com/HTTP/Database/index.html
@return array $responseArray - The response array.
@throws \ArangoDBClient\Exception
@throws \ArangoDBClient\ClientException | [
"Deletes",
"a",
"database"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Database.php#L81-L88 |
arangodb/arangodb-php | lib/ArangoDBClient/Database.php | Database.databases | public static function databases(Connection $connection)
{
$response = $connection->get(Urls::URL_DATABASE);
return $response->getJson();
} | php | public static function databases(Connection $connection)
{
$response = $connection->get(Urls::URL_DATABASE);
return $response->getJson();
} | [
"public",
"static",
"function",
"databases",
"(",
"Connection",
"$",
"connection",
")",
"{",
"$",
"response",
"=",
"$",
"connection",
"->",
"get",
"(",
"Urls",
"::",
"URL_DATABASE",
")",
";",
"return",
"$",
"response",
"->",
"getJson",
"(",
")",
";",
"}"... | List databases
This will list the databases that exist on the server
@param Connection $connection - the connection to be used
@link https://docs.arangodb.com/HTTP/Database/index.html
@return array $responseArray - The response array.
@throws \ArangoDBClient\Exception
@throws \ArangoDBClient\ClientException | [
"List",
"databases"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Database.php#L122-L127 |
arangodb/arangodb-php | lib/ArangoDBClient/Database.php | Database.listUserDatabases | public static function listUserDatabases(Connection $connection)
{
$url = UrlHelper::buildUrl(Urls::URL_DATABASE, ['user']);
$response = $connection->get($url);
return $response->getJson();
} | php | public static function listUserDatabases(Connection $connection)
{
$url = UrlHelper::buildUrl(Urls::URL_DATABASE, ['user']);
$response = $connection->get($url);
return $response->getJson();
} | [
"public",
"static",
"function",
"listUserDatabases",
"(",
"Connection",
"$",
"connection",
")",
"{",
"$",
"url",
"=",
"UrlHelper",
"::",
"buildUrl",
"(",
"Urls",
"::",
"URL_DATABASE",
",",
"[",
"'user'",
"]",
")",
";",
"$",
"response",
"=",
"$",
"connectio... | List user databases
Retrieves the list of all databases the current user can access without
specifying a different username or password.
@param Connection $connection - the connection to be used
@link https://docs.arangodb.com/HTTP/Database/index.html
@return array $responseArray - The response array.
@throws \ArangoDBClient\Exception
@throws \ArangoDBClient\ClientException | [
"List",
"user",
"databases"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Database.php#L143-L151 |
arangodb/arangodb-php | lib/ArangoDBClient/View.php | View.getAll | public function getAll()
{
return [
self::ENTRY_ID => $this->getId(),
self::ENTRY_NAME => $this->getName(),
self::ENTRY_TYPE => $this->getType(),
];
} | php | public function getAll()
{
return [
self::ENTRY_ID => $this->getId(),
self::ENTRY_NAME => $this->getName(),
self::ENTRY_TYPE => $this->getType(),
];
} | [
"public",
"function",
"getAll",
"(",
")",
"{",
"return",
"[",
"self",
"::",
"ENTRY_ID",
"=>",
"$",
"this",
"->",
"getId",
"(",
")",
",",
"self",
"::",
"ENTRY_NAME",
"=>",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"self",
"::",
"ENTRY_TYPE",
"=>",
... | Return the view as an array
@return array - view data as an array | [
"Return",
"the",
"view",
"as",
"an",
"array"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/View.php#L117-L124 |
arangodb/arangodb-php | lib/ArangoDBClient/Traversal.php | Traversal.getResult | public function getResult()
{
$bodyParams = $this->attributes;
$response = $this->_connection->post(
Urls::URL_TRAVERSAL,
$this->getConnection()->json_encode_wrapper($bodyParams)
);
return $response->getJson();
} | php | public function getResult()
{
$bodyParams = $this->attributes;
$response = $this->_connection->post(
Urls::URL_TRAVERSAL,
$this->getConnection()->json_encode_wrapper($bodyParams)
);
return $response->getJson();
} | [
"public",
"function",
"getResult",
"(",
")",
"{",
"$",
"bodyParams",
"=",
"$",
"this",
"->",
"attributes",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"_connection",
"->",
"post",
"(",
"Urls",
"::",
"URL_TRAVERSAL",
",",
"$",
"this",
"->",
"getConnecti... | Execute and get the traversal result
@return array $responseArray
@throws \ArangoDBClient\Exception
@throws \ArangoDBClient\ClientException | [
"Execute",
"and",
"get",
"the",
"traversal",
"result"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Traversal.php#L91-L103 |
arangodb/arangodb-php | lib/ArangoDBClient/BatchPart.php | BatchPart.getProcessedResponse | public function getProcessedResponse()
{
$_documentClass = $this->_documentClass;
$_edgeClass = $this->_edgeClass;
$response = $this->getResponse();
switch ($this->_type) {
case 'first':
$json = $response->getJson();
if (!isset($json['error']) || $json['error'] === false) {
$options = $this->getCursorOptions();
$options['_isNew'] = false;
$response = $_documentClass::createFromArray($json['document'], $options);
} else {
$response = false;
}
break;
case 'getdocument':
$json = $response->getJson();
$options = $this->getCursorOptions();
$options['_isNew'] = false;
$response = $_documentClass::createFromArray($json, $options);
break;
case 'document':
$json = $response->getJson();
if (!isset($json['error']) || $json['error'] === false) {
$id = $json[$_documentClass::ENTRY_ID];
$response = $id;
}
break;
case 'getedge':
$json = $response->getJson();
$options = $this->getCursorOptions();
$options['_isNew'] = false;
$response = $_edgeClass::createFromArray($json, $options);
break;
case 'edge':
$json = $response->getJson();
if (!isset($json['error']) || $json['error'] === false) {
$id = $json[Edge::ENTRY_ID];
$response = $id;
}
break;
case 'getedges':
$json = $response->getJson();
$options = $this->getCursorOptions();
$options['_isNew'] = false;
$response = [];
foreach ($json[EdgeHandler::ENTRY_EDGES] as $data) {
$response[] = $_edgeClass::createFromArray($data, $options);
}
break;
case 'getcollection':
$json = $response->getJson();
$response = Collection::createFromArray($json);
break;
case 'collection':
$json = $response->getJson();
if (!isset($json['error']) || $json['error'] === false) {
$id = $json[Collection::ENTRY_ID];
$response = $id;
}
break;
case 'cursor':
case 'all':
case 'by':
$options = $this->getCursorOptions();
$options['isNew'] = false;
$options = array_merge(['_documentClass' => $this->_documentClass], $options);
$response = new Cursor($this->_batch->getConnection(), $response->getJson(), $options);
break;
case 'remove':
$json = $response->getJson();
$response = [
'removed' => $json['removed'],
'ignored' => $json['ignored']
];
break;
default:
throw new ClientException('Could not determine response data type.');
break;
}
return $response;
} | php | public function getProcessedResponse()
{
$_documentClass = $this->_documentClass;
$_edgeClass = $this->_edgeClass;
$response = $this->getResponse();
switch ($this->_type) {
case 'first':
$json = $response->getJson();
if (!isset($json['error']) || $json['error'] === false) {
$options = $this->getCursorOptions();
$options['_isNew'] = false;
$response = $_documentClass::createFromArray($json['document'], $options);
} else {
$response = false;
}
break;
case 'getdocument':
$json = $response->getJson();
$options = $this->getCursorOptions();
$options['_isNew'] = false;
$response = $_documentClass::createFromArray($json, $options);
break;
case 'document':
$json = $response->getJson();
if (!isset($json['error']) || $json['error'] === false) {
$id = $json[$_documentClass::ENTRY_ID];
$response = $id;
}
break;
case 'getedge':
$json = $response->getJson();
$options = $this->getCursorOptions();
$options['_isNew'] = false;
$response = $_edgeClass::createFromArray($json, $options);
break;
case 'edge':
$json = $response->getJson();
if (!isset($json['error']) || $json['error'] === false) {
$id = $json[Edge::ENTRY_ID];
$response = $id;
}
break;
case 'getedges':
$json = $response->getJson();
$options = $this->getCursorOptions();
$options['_isNew'] = false;
$response = [];
foreach ($json[EdgeHandler::ENTRY_EDGES] as $data) {
$response[] = $_edgeClass::createFromArray($data, $options);
}
break;
case 'getcollection':
$json = $response->getJson();
$response = Collection::createFromArray($json);
break;
case 'collection':
$json = $response->getJson();
if (!isset($json['error']) || $json['error'] === false) {
$id = $json[Collection::ENTRY_ID];
$response = $id;
}
break;
case 'cursor':
case 'all':
case 'by':
$options = $this->getCursorOptions();
$options['isNew'] = false;
$options = array_merge(['_documentClass' => $this->_documentClass], $options);
$response = new Cursor($this->_batch->getConnection(), $response->getJson(), $options);
break;
case 'remove':
$json = $response->getJson();
$response = [
'removed' => $json['removed'],
'ignored' => $json['ignored']
];
break;
default:
throw new ClientException('Could not determine response data type.');
break;
}
return $response;
} | [
"public",
"function",
"getProcessedResponse",
"(",
")",
"{",
"$",
"_documentClass",
"=",
"$",
"this",
"->",
"_documentClass",
";",
"$",
"_edgeClass",
"=",
"$",
"this",
"->",
"_edgeClass",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"getResponse",
"(",
")... | Get the batch part identified by the array key (0...n) or its id (if it was set with nextBatchPartId($id) )
@throws ClientException
@return mixed $partId | [
"Get",
"the",
"batch",
"part",
"identified",
"by",
"the",
"array",
"key",
"(",
"0",
"...",
"n",
")",
"or",
"its",
"id",
"(",
"if",
"it",
"was",
"set",
"with",
"nextBatchPartId",
"(",
"$id",
")",
")"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/BatchPart.php#L245-L331 |
arangodb/arangodb-php | lib/ArangoDBClient/UrlHelper.php | UrlHelper.getDocumentIdFromLocation | public static function getDocumentIdFromLocation($location)
{
if (!is_string($location)) {
// can't do anything about it if location is not even a string
return null;
}
if (0 === strpos($location, '/_db/')) {
// /_db/<dbname>/_api/document/<collection>/<key>
@list(, , , , , $collectionName, $id) = explode('/', $location);
} else {
// /_api/document/<collection>/<key>
@list(, , , $collectionName, $id) = explode('/', $location);
}
if (is_string($id)) {
$id = urldecode($id);
}
return $collectionName . '/' . $id;
} | php | public static function getDocumentIdFromLocation($location)
{
if (!is_string($location)) {
// can't do anything about it if location is not even a string
return null;
}
if (0 === strpos($location, '/_db/')) {
// /_db/<dbname>/_api/document/<collection>/<key>
@list(, , , , , $collectionName, $id) = explode('/', $location);
} else {
// /_api/document/<collection>/<key>
@list(, , , $collectionName, $id) = explode('/', $location);
}
if (is_string($id)) {
$id = urldecode($id);
}
return $collectionName . '/' . $id;
} | [
"public",
"static",
"function",
"getDocumentIdFromLocation",
"(",
"$",
"location",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"location",
")",
")",
"{",
"// can't do anything about it if location is not even a string",
"return",
"null",
";",
"}",
"if",
"(",
... | Get the document id from a location header
@param string $location - HTTP response location header
@return string - document id parsed from header | [
"Get",
"the",
"document",
"id",
"from",
"a",
"location",
"header"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/UrlHelper.php#L28-L48 |
arangodb/arangodb-php | lib/ArangoDBClient/UrlHelper.php | UrlHelper.buildUrl | public static function buildUrl($baseUrl, array $parts = [])
{
$url = $baseUrl;
foreach ($parts as $part) {
if (strpos($part, '/') !== false) {
@list(,$part) = explode('/', $part);
}
$url .= '/' . urlencode($part);
}
return $url;
} | php | public static function buildUrl($baseUrl, array $parts = [])
{
$url = $baseUrl;
foreach ($parts as $part) {
if (strpos($part, '/') !== false) {
@list(,$part) = explode('/', $part);
}
$url .= '/' . urlencode($part);
}
return $url;
} | [
"public",
"static",
"function",
"buildUrl",
"(",
"$",
"baseUrl",
",",
"array",
"$",
"parts",
"=",
"[",
"]",
")",
"{",
"$",
"url",
"=",
"$",
"baseUrl",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"part",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
... | Construct a URL from a base URL and additional parts, separated with '/' each
This function accepts variable arguments.
@param string $baseUrl - base URL
@param array $parts - URL parts to append
@return string - assembled URL | [
"Construct",
"a",
"URL",
"from",
"a",
"base",
"URL",
"and",
"additional",
"parts",
"separated",
"with",
"/",
"each"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/UrlHelper.php#L60-L73 |
arangodb/arangodb-php | lib/ArangoDBClient/UrlHelper.php | UrlHelper.appendParamsUrl | public static function appendParamsUrl($baseUrl, $params)
{
foreach ($params as $key => &$value) {
if (is_bool($value)) {
$value = self::getBoolString($value);
}
}
return $baseUrl . '?' . http_build_query($params);
} | php | public static function appendParamsUrl($baseUrl, $params)
{
foreach ($params as $key => &$value) {
if (is_bool($value)) {
$value = self::getBoolString($value);
}
}
return $baseUrl . '?' . http_build_query($params);
} | [
"public",
"static",
"function",
"appendParamsUrl",
"(",
"$",
"baseUrl",
",",
"$",
"params",
")",
"{",
"foreach",
"(",
"$",
"params",
"as",
"$",
"key",
"=>",
"&",
"$",
"value",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"value",
")",
")",
"{",
"$",
... | Append parameters to a URL
Parameter values will be URL-encoded
@param string $baseUrl - base URL
@param array $params - an array of parameters
@return string - the assembled URL | [
"Append",
"parameters",
"to",
"a",
"URL"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/UrlHelper.php#L85-L94 |
arangodb/arangodb-php | lib/ArangoDBClient/QueryHandler.php | QueryHandler.clearSlow | public function clearSlow()
{
$url = UrlHelper::buildUrl(Urls::URL_QUERY, ['slow']);
$this->getConnection()->delete($url);
} | php | public function clearSlow()
{
$url = UrlHelper::buildUrl(Urls::URL_QUERY, ['slow']);
$this->getConnection()->delete($url);
} | [
"public",
"function",
"clearSlow",
"(",
")",
"{",
"$",
"url",
"=",
"UrlHelper",
"::",
"buildUrl",
"(",
"Urls",
"::",
"URL_QUERY",
",",
"[",
"'slow'",
"]",
")",
";",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"delete",
"(",
"$",
"url",
")",
... | Clears the list of slow queries
@throws Exception | [
"Clears",
"the",
"list",
"of",
"slow",
"queries"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/QueryHandler.php#L20-L24 |
arangodb/arangodb-php | lib/ArangoDBClient/QueryHandler.php | QueryHandler.getSlow | public function getSlow()
{
$url = UrlHelper::buildUrl(Urls::URL_QUERY, ['slow']);
$response = $this->getConnection()->get($url);
return $response->getJson();
} | php | public function getSlow()
{
$url = UrlHelper::buildUrl(Urls::URL_QUERY, ['slow']);
$response = $this->getConnection()->get($url);
return $response->getJson();
} | [
"public",
"function",
"getSlow",
"(",
")",
"{",
"$",
"url",
"=",
"UrlHelper",
"::",
"buildUrl",
"(",
"Urls",
"::",
"URL_QUERY",
",",
"[",
"'slow'",
"]",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"get",
"(",
... | Returns the list of slow queries
@throws Exception
@return array | [
"Returns",
"the",
"list",
"of",
"slow",
"queries"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/QueryHandler.php#L33-L39 |
arangodb/arangodb-php | lib/ArangoDBClient/QueryHandler.php | QueryHandler.kill | public function kill($id)
{
$url = UrlHelper::buildUrl(Urls::URL_QUERY, [$id]);
$this->getConnection()->delete($url);
return true;
} | php | public function kill($id)
{
$url = UrlHelper::buildUrl(Urls::URL_QUERY, [$id]);
$this->getConnection()->delete($url);
return true;
} | [
"public",
"function",
"kill",
"(",
"$",
"id",
")",
"{",
"$",
"url",
"=",
"UrlHelper",
"::",
"buildUrl",
"(",
"Urls",
"::",
"URL_QUERY",
",",
"[",
"$",
"id",
"]",
")",
";",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"delete",
"(",
"$",
"u... | Kills a specific query
This will send an HTTP DELETE command to the server to terminate the specified query
@param string $id - query id
@throws Exception
@return bool | [
"Kills",
"a",
"specific",
"query"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/QueryHandler.php#L67-L73 |
arangodb/arangodb-php | lib/ArangoDBClient/Connection.php | Connection.setOption | public function setOption($name, $value)
{
if ($name === ConnectionOptions::OPTION_ENDPOINT ||
$name === ConnectionOptions::OPTION_HOST ||
$name === ConnectionOptions::OPTION_PORT ||
$name === ConnectionOptions::OPTION_VERIFY_CERT ||
$name === ConnectionOptions::OPTION_CIPHERS ||
$name === ConnectionOptions::OPTION_ALLOW_SELF_SIGNED
) {
throw new ClientException('Must not set option ' . $value . ' after connection is created.');
}
$this->_options[$name] = $value;
// special handling for several options
if ($name === ConnectionOptions::OPTION_TIMEOUT) {
// set the timeout option: patch the stream of an existing connection
if (is_resource($this->_handle)) {
stream_set_timeout($this->_handle, $value);
}
} else if ($name === ConnectionOptions::OPTION_CONNECTION) {
// set keep-alive flag
$this->_useKeepAlive = (strtolower($value) === 'keep-alive');
} else if ($name === ConnectionOptions::OPTION_DATABASE) {
// set database
$this->setDatabase($value);
}
$this->updateHttpHeader();
} | php | public function setOption($name, $value)
{
if ($name === ConnectionOptions::OPTION_ENDPOINT ||
$name === ConnectionOptions::OPTION_HOST ||
$name === ConnectionOptions::OPTION_PORT ||
$name === ConnectionOptions::OPTION_VERIFY_CERT ||
$name === ConnectionOptions::OPTION_CIPHERS ||
$name === ConnectionOptions::OPTION_ALLOW_SELF_SIGNED
) {
throw new ClientException('Must not set option ' . $value . ' after connection is created.');
}
$this->_options[$name] = $value;
// special handling for several options
if ($name === ConnectionOptions::OPTION_TIMEOUT) {
// set the timeout option: patch the stream of an existing connection
if (is_resource($this->_handle)) {
stream_set_timeout($this->_handle, $value);
}
} else if ($name === ConnectionOptions::OPTION_CONNECTION) {
// set keep-alive flag
$this->_useKeepAlive = (strtolower($value) === 'keep-alive');
} else if ($name === ConnectionOptions::OPTION_DATABASE) {
// set database
$this->setDatabase($value);
}
$this->updateHttpHeader();
} | [
"public",
"function",
"setOption",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"name",
"===",
"ConnectionOptions",
"::",
"OPTION_ENDPOINT",
"||",
"$",
"name",
"===",
"ConnectionOptions",
"::",
"OPTION_HOST",
"||",
"$",
"name",
"===",
"Co... | Set an option set for the connection
@throws ClientException
@param string $name - name of option
@param string $value - value of option | [
"Set",
"an",
"option",
"set",
"for",
"the",
"connection"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Connection.php#L139-L168 |
arangodb/arangodb-php | lib/ArangoDBClient/Connection.php | Connection.get | public function get($url, array $customHeaders = [])
{
return $this->handleFailover(function() use ($url, $customHeaders) {
$response = $this->executeRequest(HttpHelper::METHOD_GET, $url, '', $customHeaders);
return $this->parseResponse($response);
});
} | php | public function get($url, array $customHeaders = [])
{
return $this->handleFailover(function() use ($url, $customHeaders) {
$response = $this->executeRequest(HttpHelper::METHOD_GET, $url, '', $customHeaders);
return $this->parseResponse($response);
});
} | [
"public",
"function",
"get",
"(",
"$",
"url",
",",
"array",
"$",
"customHeaders",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"handleFailover",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"url",
",",
"$",
"customHeaders",
")",
"{",
"$",
"... | Issue an HTTP GET request
@throws Exception
@param string $url - GET URL
@param array $customHeaders
@return HttpResponse | [
"Issue",
"an",
"HTTP",
"GET",
"request"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Connection.php#L207-L214 |
arangodb/arangodb-php | lib/ArangoDBClient/Connection.php | Connection.post | public function post($url, $data, array $customHeaders = [])
{
return $this->handleFailover(function() use ($url, $data, $customHeaders) {
$response = $this->executeRequest(HttpHelper::METHOD_POST, $url, $data, $customHeaders);
return $this->parseResponse($response);
});
} | php | public function post($url, $data, array $customHeaders = [])
{
return $this->handleFailover(function() use ($url, $data, $customHeaders) {
$response = $this->executeRequest(HttpHelper::METHOD_POST, $url, $data, $customHeaders);
return $this->parseResponse($response);
});
} | [
"public",
"function",
"post",
"(",
"$",
"url",
",",
"$",
"data",
",",
"array",
"$",
"customHeaders",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"handleFailover",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"url",
",",
"$",
"data",
",",
... | Issue an HTTP POST request with the data provided
@throws Exception
@param string $url - POST URL
@param string $data - body to post
@param array $customHeaders
@return HttpResponse | [
"Issue",
"an",
"HTTP",
"POST",
"request",
"with",
"the",
"data",
"provided"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Connection.php#L227-L234 |
arangodb/arangodb-php | lib/ArangoDBClient/Connection.php | Connection.put | public function put($url, $data, array $customHeaders = [])
{
return $this->handleFailover(function() use ($url, $data, $customHeaders) {
$response = $this->executeRequest(HttpHelper::METHOD_PUT, $url, $data, $customHeaders);
return $this->parseResponse($response);
});
} | php | public function put($url, $data, array $customHeaders = [])
{
return $this->handleFailover(function() use ($url, $data, $customHeaders) {
$response = $this->executeRequest(HttpHelper::METHOD_PUT, $url, $data, $customHeaders);
return $this->parseResponse($response);
});
} | [
"public",
"function",
"put",
"(",
"$",
"url",
",",
"$",
"data",
",",
"array",
"$",
"customHeaders",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"handleFailover",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"url",
",",
"$",
"data",
",",
... | Issue an HTTP PUT request with the data provided
@throws Exception
@param string $url - PUT URL
@param string $data - body to post
@param array $customHeaders
@return HttpResponse | [
"Issue",
"an",
"HTTP",
"PUT",
"request",
"with",
"the",
"data",
"provided"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Connection.php#L247-L254 |
arangodb/arangodb-php | lib/ArangoDBClient/Connection.php | Connection.head | public function head($url, array $customHeaders = [])
{
return $this->handleFailover(function() use ($url, $customHeaders) {
$response = $this->executeRequest(HttpHelper::METHOD_HEAD, $url, '', $customHeaders);
return $this->parseResponse($response);
});
} | php | public function head($url, array $customHeaders = [])
{
return $this->handleFailover(function() use ($url, $customHeaders) {
$response = $this->executeRequest(HttpHelper::METHOD_HEAD, $url, '', $customHeaders);
return $this->parseResponse($response);
});
} | [
"public",
"function",
"head",
"(",
"$",
"url",
",",
"array",
"$",
"customHeaders",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"handleFailover",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"url",
",",
"$",
"customHeaders",
")",
"{",
"$",
... | Issue an HTTP Head request with the data provided
@throws Exception
@param string $url - PUT URL
@param array $customHeaders
@return HttpResponse | [
"Issue",
"an",
"HTTP",
"Head",
"request",
"with",
"the",
"data",
"provided"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Connection.php#L266-L273 |
arangodb/arangodb-php | lib/ArangoDBClient/Connection.php | Connection.patch | public function patch($url, $data, array $customHeaders = [])
{
return $this->handleFailover(function() use ($url, $data, $customHeaders) {
$response = $this->executeRequest(HttpHelper::METHOD_PATCH, $url, $data, $customHeaders);
return $this->parseResponse($response);
});
} | php | public function patch($url, $data, array $customHeaders = [])
{
return $this->handleFailover(function() use ($url, $data, $customHeaders) {
$response = $this->executeRequest(HttpHelper::METHOD_PATCH, $url, $data, $customHeaders);
return $this->parseResponse($response);
});
} | [
"public",
"function",
"patch",
"(",
"$",
"url",
",",
"$",
"data",
",",
"array",
"$",
"customHeaders",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"handleFailover",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"url",
",",
"$",
"data",
",",
... | Issue an HTTP PATCH request with the data provided
@throws Exception
@param string $url - PATCH URL
@param string $data - patch body
@param array $customHeaders
@return HttpResponse | [
"Issue",
"an",
"HTTP",
"PATCH",
"request",
"with",
"the",
"data",
"provided"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Connection.php#L286-L293 |
arangodb/arangodb-php | lib/ArangoDBClient/Connection.php | Connection.delete | public function delete($url, array $customHeaders = [], $data = '')
{
return $this->handleFailover(function() use ($url, $customHeaders, $data) {
$response = $this->executeRequest(HttpHelper::METHOD_DELETE, $url, $data, $customHeaders);
return $this->parseResponse($response);
});
} | php | public function delete($url, array $customHeaders = [], $data = '')
{
return $this->handleFailover(function() use ($url, $customHeaders, $data) {
$response = $this->executeRequest(HttpHelper::METHOD_DELETE, $url, $data, $customHeaders);
return $this->parseResponse($response);
});
} | [
"public",
"function",
"delete",
"(",
"$",
"url",
",",
"array",
"$",
"customHeaders",
"=",
"[",
"]",
",",
"$",
"data",
"=",
"''",
")",
"{",
"return",
"$",
"this",
"->",
"handleFailover",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"url",
",",
"$",
... | Issue an HTTP DELETE request with the data provided
@throws Exception
@param string $url - DELETE URL
@param array $customHeaders
@param string $data - delete body
@return HttpResponse | [
"Issue",
"an",
"HTTP",
"DELETE",
"request",
"with",
"the",
"data",
"provided"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Connection.php#L306-L313 |
arangodb/arangodb-php | lib/ArangoDBClient/Connection.php | Connection.handleFailover | private function handleFailover($cb)
{
$start = microtime(true);
if (!$this->_options->haveMultipleEndpoints()) {
// the simple case: just one server
while (true) {
try {
return $cb();
} catch (FailoverException $e) {
if (microtime(true) - $start >= $this->_options[ConnectionOptions::OPTION_FAILOVER_TIMEOUT]) {
// timeout reached, we will abort now
$this->notify('servers not reachable after timeout');
throw $e;
}
// continue because we have not yet reached the timeout
usleep(20 * 1000);
}
}
}
// here we need to try it with failover
$tried = [];
$notReachable = [];
while (true) {
$ep = $this->_options->getCurrentEndpoint();
$normalized = Endpoint::normalizeHostname($ep);
if (isset($notReachable[$normalized])) {
$this->notify('no more servers available to try connecting to');
throw new ConnectException('no more servers available to try connecting to');
}
try {
// mark the endpoint as being tried
$tried[$normalized] = true;
return $cb();
} catch (ConnectException $e) {
// could not connect. now try again with a different server if possible
if ($this->_options[ConnectionOptions::OPTION_FAILOVER_TRIES] > 0 &&
count($tried) > $this->_options[ConnectionOptions::OPTION_FAILOVER_TRIES]) {
$this->notify('tried too many different servers in failover');
throw $e;
}
// mark endpoint as unreachable
$notReachable[$normalized] = true;
// move on to next endpoint
$ep = $this->_options->nextEndpoint();
$normalized = Endpoint::normalizeHostname($ep);
if (isset($tried[$normalized])) {
if (microtime(true) - $start >= $this->_options[ConnectionOptions::OPTION_FAILOVER_TIMEOUT]) {
// timeout reached, we will abort now
$this->notify('no servers reachable after failover timeout');
throw $e;
}
// continue because we have not yet reached the timeout
usleep(20 * 1000);
}
} catch (FailoverException $e) {
// got a failover. now try again with a different server if possible
// endpoint should have changed by failover procedure
$ep = $this->_options->getCurrentEndpoint();
$normalized = Endpoint::normalizeHostname($ep);
if ($this->_options[ConnectionOptions::OPTION_FAILOVER_TRIES] > 0 &&
count($tried) > $this->_options[ConnectionOptions::OPTION_FAILOVER_TRIES]) {
$this->notify('tried too many different servers in failover');
throw $e;
}
if (isset($tried[$normalized])) {
if (microtime(true) - $start >= $this->_options[ConnectionOptions::OPTION_FAILOVER_TIMEOUT]) {
// timeout reached, we can abort now
$this->notify('no servers reachable after failover timeout');
throw $e;
}
// continue because we have not yet reached the timeout
usleep(20 * 1000);
}
// we need to try the recommended leader again
unset($notReachable[$normalized]);
}
// let all other exception types escape from here
}
} | php | private function handleFailover($cb)
{
$start = microtime(true);
if (!$this->_options->haveMultipleEndpoints()) {
// the simple case: just one server
while (true) {
try {
return $cb();
} catch (FailoverException $e) {
if (microtime(true) - $start >= $this->_options[ConnectionOptions::OPTION_FAILOVER_TIMEOUT]) {
// timeout reached, we will abort now
$this->notify('servers not reachable after timeout');
throw $e;
}
// continue because we have not yet reached the timeout
usleep(20 * 1000);
}
}
}
// here we need to try it with failover
$tried = [];
$notReachable = [];
while (true) {
$ep = $this->_options->getCurrentEndpoint();
$normalized = Endpoint::normalizeHostname($ep);
if (isset($notReachable[$normalized])) {
$this->notify('no more servers available to try connecting to');
throw new ConnectException('no more servers available to try connecting to');
}
try {
// mark the endpoint as being tried
$tried[$normalized] = true;
return $cb();
} catch (ConnectException $e) {
// could not connect. now try again with a different server if possible
if ($this->_options[ConnectionOptions::OPTION_FAILOVER_TRIES] > 0 &&
count($tried) > $this->_options[ConnectionOptions::OPTION_FAILOVER_TRIES]) {
$this->notify('tried too many different servers in failover');
throw $e;
}
// mark endpoint as unreachable
$notReachable[$normalized] = true;
// move on to next endpoint
$ep = $this->_options->nextEndpoint();
$normalized = Endpoint::normalizeHostname($ep);
if (isset($tried[$normalized])) {
if (microtime(true) - $start >= $this->_options[ConnectionOptions::OPTION_FAILOVER_TIMEOUT]) {
// timeout reached, we will abort now
$this->notify('no servers reachable after failover timeout');
throw $e;
}
// continue because we have not yet reached the timeout
usleep(20 * 1000);
}
} catch (FailoverException $e) {
// got a failover. now try again with a different server if possible
// endpoint should have changed by failover procedure
$ep = $this->_options->getCurrentEndpoint();
$normalized = Endpoint::normalizeHostname($ep);
if ($this->_options[ConnectionOptions::OPTION_FAILOVER_TRIES] > 0 &&
count($tried) > $this->_options[ConnectionOptions::OPTION_FAILOVER_TRIES]) {
$this->notify('tried too many different servers in failover');
throw $e;
}
if (isset($tried[$normalized])) {
if (microtime(true) - $start >= $this->_options[ConnectionOptions::OPTION_FAILOVER_TIMEOUT]) {
// timeout reached, we can abort now
$this->notify('no servers reachable after failover timeout');
throw $e;
}
// continue because we have not yet reached the timeout
usleep(20 * 1000);
}
// we need to try the recommended leader again
unset($notReachable[$normalized]);
}
// let all other exception types escape from here
}
} | [
"private",
"function",
"handleFailover",
"(",
"$",
"cb",
")",
"{",
"$",
"start",
"=",
"microtime",
"(",
"true",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"_options",
"->",
"haveMultipleEndpoints",
"(",
")",
")",
"{",
"// the simple case: just one server",... | Execute the specified callback, and try again if it fails because
the target server is not available. In this case, try again with failing
over to an alternative server (the new leader) until the maximum number
of failover attempts have been made
@throws Exception - either a ConnectException or a FailoverException or an
Exception produced by the callback function
@param mixed $cb - the callback function to execute
@return HttpResponse | [
"Execute",
"the",
"specified",
"callback",
"and",
"try",
"again",
"if",
"it",
"fails",
"because",
"the",
"target",
"server",
"is",
"not",
"available",
".",
"In",
"this",
"case",
"try",
"again",
"with",
"failing",
"over",
"to",
"an",
"alternative",
"server",
... | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Connection.php#L328-L413 |
arangodb/arangodb-php | lib/ArangoDBClient/Connection.php | Connection.updateHttpHeader | private function updateHttpHeader()
{
$this->_httpHeader = HttpHelper::EOL;
$endpoint = $this->_options->getCurrentEndpoint();
if (Endpoint::getType($endpoint) !== Endpoint::TYPE_UNIX) {
$this->_httpHeader .= sprintf('Host: %s%s', Endpoint::getHost($endpoint), HttpHelper::EOL);
}
if (isset($this->_options[ConnectionOptions::OPTION_AUTH_TYPE], $this->_options[ConnectionOptions::OPTION_AUTH_USER])) {
// add authorization header
$authorizationValue = base64_encode(
$this->_options[ConnectionOptions::OPTION_AUTH_USER] . ':' .
$this->_options[ConnectionOptions::OPTION_AUTH_PASSWD]
);
$this->_httpHeader .= sprintf(
'Authorization: %s %s%s',
$this->_options[ConnectionOptions::OPTION_AUTH_TYPE],
$authorizationValue,
HttpHelper::EOL
);
}
if (isset($this->_options[ConnectionOptions::OPTION_CONNECTION])) {
// add connection header
$this->_httpHeader .= sprintf('Connection: %s%s', $this->_options[ConnectionOptions::OPTION_CONNECTION], HttpHelper::EOL);
}
if ($this->_database === '') {
$this->_baseUrl = '/_db/_system';
} else {
$this->_baseUrl = '/_db/' . urlencode($this->_database);
}
} | php | private function updateHttpHeader()
{
$this->_httpHeader = HttpHelper::EOL;
$endpoint = $this->_options->getCurrentEndpoint();
if (Endpoint::getType($endpoint) !== Endpoint::TYPE_UNIX) {
$this->_httpHeader .= sprintf('Host: %s%s', Endpoint::getHost($endpoint), HttpHelper::EOL);
}
if (isset($this->_options[ConnectionOptions::OPTION_AUTH_TYPE], $this->_options[ConnectionOptions::OPTION_AUTH_USER])) {
// add authorization header
$authorizationValue = base64_encode(
$this->_options[ConnectionOptions::OPTION_AUTH_USER] . ':' .
$this->_options[ConnectionOptions::OPTION_AUTH_PASSWD]
);
$this->_httpHeader .= sprintf(
'Authorization: %s %s%s',
$this->_options[ConnectionOptions::OPTION_AUTH_TYPE],
$authorizationValue,
HttpHelper::EOL
);
}
if (isset($this->_options[ConnectionOptions::OPTION_CONNECTION])) {
// add connection header
$this->_httpHeader .= sprintf('Connection: %s%s', $this->_options[ConnectionOptions::OPTION_CONNECTION], HttpHelper::EOL);
}
if ($this->_database === '') {
$this->_baseUrl = '/_db/_system';
} else {
$this->_baseUrl = '/_db/' . urlencode($this->_database);
}
} | [
"private",
"function",
"updateHttpHeader",
"(",
")",
"{",
"$",
"this",
"->",
"_httpHeader",
"=",
"HttpHelper",
"::",
"EOL",
";",
"$",
"endpoint",
"=",
"$",
"this",
"->",
"_options",
"->",
"getCurrentEndpoint",
"(",
")",
";",
"if",
"(",
"Endpoint",
"::",
... | Recalculate the static HTTP header string used for all HTTP requests in this connection | [
"Recalculate",
"the",
"static",
"HTTP",
"header",
"string",
"used",
"for",
"all",
"HTTP",
"requests",
"in",
"this",
"connection"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Connection.php#L418-L452 |
arangodb/arangodb-php | lib/ArangoDBClient/Connection.php | Connection.getHandle | private function getHandle()
{
if ($this->_useKeepAlive && $this->_handle && is_resource($this->_handle)) {
// keep-alive and handle was created already
$handle = $this->_handle;
// check if connection is still valid
if (!feof($handle)) {
// connection still valid
return $handle;
}
// close handle
$this->closeHandle();
if (!$this->_options[ConnectionOptions::OPTION_RECONNECT]) {
// if reconnect option not set, this is the end
throw new ClientException('Server has closed the connection already.');
}
}
// no keep-alive or no handle available yet or a reconnect
$handle = HttpHelper::createConnection($this->_options);
if ($this->_useKeepAlive && is_resource($handle)) {
$this->_handle = $handle;
}
return $handle;
} | php | private function getHandle()
{
if ($this->_useKeepAlive && $this->_handle && is_resource($this->_handle)) {
// keep-alive and handle was created already
$handle = $this->_handle;
// check if connection is still valid
if (!feof($handle)) {
// connection still valid
return $handle;
}
// close handle
$this->closeHandle();
if (!$this->_options[ConnectionOptions::OPTION_RECONNECT]) {
// if reconnect option not set, this is the end
throw new ClientException('Server has closed the connection already.');
}
}
// no keep-alive or no handle available yet or a reconnect
$handle = HttpHelper::createConnection($this->_options);
if ($this->_useKeepAlive && is_resource($handle)) {
$this->_handle = $handle;
}
return $handle;
} | [
"private",
"function",
"getHandle",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_useKeepAlive",
"&&",
"$",
"this",
"->",
"_handle",
"&&",
"is_resource",
"(",
"$",
"this",
"->",
"_handle",
")",
")",
"{",
"// keep-alive and handle was created already",
"$",
... | Get a connection handle
If keep-alive connections are used, the handle will be stored and re-used
@throws ClientException
@return resource - connection handle
@throws \ArangoDBClient\ConnectException | [
"Get",
"a",
"connection",
"handle"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Connection.php#L463-L492 |
arangodb/arangodb-php | lib/ArangoDBClient/Connection.php | Connection.closeHandle | private function closeHandle()
{
if ($this->_handle && is_resource($this->_handle)) {
@fclose($this->_handle);
}
$this->_handle = null;
} | php | private function closeHandle()
{
if ($this->_handle && is_resource($this->_handle)) {
@fclose($this->_handle);
}
$this->_handle = null;
} | [
"private",
"function",
"closeHandle",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_handle",
"&&",
"is_resource",
"(",
"$",
"this",
"->",
"_handle",
")",
")",
"{",
"@",
"fclose",
"(",
"$",
"this",
"->",
"_handle",
")",
";",
"}",
"$",
"this",
"->",... | Close an existing connection handle
@return void | [
"Close",
"an",
"existing",
"connection",
"handle"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Connection.php#L500-L506 |
arangodb/arangodb-php | lib/ArangoDBClient/Connection.php | Connection.executeRequest | private function executeRequest($method, $url, $data, array $customHeaders = [])
{
assert($this->_httpHeader !== '');
$wasAsync = false;
if (is_array($customHeaders) && isset($customHeaders[HttpHelper::ASYNC_HEADER])) {
$wasAsync = true;
}
HttpHelper::validateMethod($method);
$url = $this->_baseUrl . $url;
// create request data
if ($this->_batchRequest === false) {
if ($this->_captureBatch === true) {
$this->_options->offsetSet(ConnectionOptions::OPTION_BATCHPART, true);
$request = HttpHelper::buildRequest($this->_options, $this->_httpHeader, $method, $url, $data, $customHeaders);
$this->_options->offsetSet(ConnectionOptions::OPTION_BATCHPART, false);
} else {
$request = HttpHelper::buildRequest($this->_options, $this->_httpHeader, $method, $url, $data, $customHeaders);
}
if ($this->_captureBatch === true) {
$batchPart = $this->doBatch($method, $request);
if (null !== $batchPart) {
return $batchPart;
}
}
} else {
$this->_batchRequest = false;
$this->_options->offsetSet(ConnectionOptions::OPTION_BATCH, true);
$request = HttpHelper::buildRequest($this->_options, $this->_httpHeader, $method, $url, $data, $customHeaders);
$this->_options->offsetSet(ConnectionOptions::OPTION_BATCH, false);
}
$traceFunc = $this->_options[ConnectionOptions::OPTION_TRACE];
if ($traceFunc) {
// call tracer func
if ($this->_options[ConnectionOptions::OPTION_ENHANCED_TRACE]) {
list($header) = HttpHelper::parseHttpMessage($request, $url, $method);
$headers = HttpHelper::parseHeaders($header);
$traceFunc(new TraceRequest($headers[2], $method, $url, $data));
} else {
$traceFunc('send', $request);
}
}
// open the socket. note: this might throw if the connection cannot be established
$handle = $this->getHandle();
if ($handle !== null) {
// send data and get response back
if ($traceFunc) {
// only issue syscall if we need it
$startTime = microtime(true);
}
$result = HttpHelper::transfer($handle, $request, $method);
if ($traceFunc) {
// only issue syscall if we need it
$timeTaken = microtime(true) - $startTime;
}
$status = socket_get_status($handle);
if ($status['timed_out']) {
// can't connect to server because of timeout.
// now check if we have additional servers to connect to
if ($this->_options->haveMultipleEndpoints()) {
// connect to next server in list
$currentLeader = $this->_options->getCurrentEndpoint();
$newLeader = $this->_options->nextEndpoint();
if ($newLeader && ($newLeader !== $currentLeader)) {
// close existing connection
$this->closeHandle();
$this->updateHttpHeader();
$exception = new FailoverException("Got a timeout while waiting for the server's response", 408);
$exception->setLeader($newLeader);
throw $exception;
}
}
throw new ClientException('Got a timeout while waiting for the server\'s response', 408);
}
if (!$this->_useKeepAlive) {
// must close the connection
fclose($handle);
}
$response = new HttpResponse($result, $url, $method, $wasAsync);
if ($traceFunc) {
// call tracer func
if ($this->_options[ConnectionOptions::OPTION_ENHANCED_TRACE]) {
$traceFunc(
new TraceResponse(
$response->getHeaders(), $response->getHttpCode(), $response->getBody(),
$timeTaken
)
);
} else {
$traceFunc('receive', $result);
}
}
return $response;
}
throw new ClientException('Whoops, this should never happen');
} | php | private function executeRequest($method, $url, $data, array $customHeaders = [])
{
assert($this->_httpHeader !== '');
$wasAsync = false;
if (is_array($customHeaders) && isset($customHeaders[HttpHelper::ASYNC_HEADER])) {
$wasAsync = true;
}
HttpHelper::validateMethod($method);
$url = $this->_baseUrl . $url;
// create request data
if ($this->_batchRequest === false) {
if ($this->_captureBatch === true) {
$this->_options->offsetSet(ConnectionOptions::OPTION_BATCHPART, true);
$request = HttpHelper::buildRequest($this->_options, $this->_httpHeader, $method, $url, $data, $customHeaders);
$this->_options->offsetSet(ConnectionOptions::OPTION_BATCHPART, false);
} else {
$request = HttpHelper::buildRequest($this->_options, $this->_httpHeader, $method, $url, $data, $customHeaders);
}
if ($this->_captureBatch === true) {
$batchPart = $this->doBatch($method, $request);
if (null !== $batchPart) {
return $batchPart;
}
}
} else {
$this->_batchRequest = false;
$this->_options->offsetSet(ConnectionOptions::OPTION_BATCH, true);
$request = HttpHelper::buildRequest($this->_options, $this->_httpHeader, $method, $url, $data, $customHeaders);
$this->_options->offsetSet(ConnectionOptions::OPTION_BATCH, false);
}
$traceFunc = $this->_options[ConnectionOptions::OPTION_TRACE];
if ($traceFunc) {
// call tracer func
if ($this->_options[ConnectionOptions::OPTION_ENHANCED_TRACE]) {
list($header) = HttpHelper::parseHttpMessage($request, $url, $method);
$headers = HttpHelper::parseHeaders($header);
$traceFunc(new TraceRequest($headers[2], $method, $url, $data));
} else {
$traceFunc('send', $request);
}
}
// open the socket. note: this might throw if the connection cannot be established
$handle = $this->getHandle();
if ($handle !== null) {
// send data and get response back
if ($traceFunc) {
// only issue syscall if we need it
$startTime = microtime(true);
}
$result = HttpHelper::transfer($handle, $request, $method);
if ($traceFunc) {
// only issue syscall if we need it
$timeTaken = microtime(true) - $startTime;
}
$status = socket_get_status($handle);
if ($status['timed_out']) {
// can't connect to server because of timeout.
// now check if we have additional servers to connect to
if ($this->_options->haveMultipleEndpoints()) {
// connect to next server in list
$currentLeader = $this->_options->getCurrentEndpoint();
$newLeader = $this->_options->nextEndpoint();
if ($newLeader && ($newLeader !== $currentLeader)) {
// close existing connection
$this->closeHandle();
$this->updateHttpHeader();
$exception = new FailoverException("Got a timeout while waiting for the server's response", 408);
$exception->setLeader($newLeader);
throw $exception;
}
}
throw new ClientException('Got a timeout while waiting for the server\'s response', 408);
}
if (!$this->_useKeepAlive) {
// must close the connection
fclose($handle);
}
$response = new HttpResponse($result, $url, $method, $wasAsync);
if ($traceFunc) {
// call tracer func
if ($this->_options[ConnectionOptions::OPTION_ENHANCED_TRACE]) {
$traceFunc(
new TraceResponse(
$response->getHeaders(), $response->getHttpCode(), $response->getBody(),
$timeTaken
)
);
} else {
$traceFunc('receive', $result);
}
}
return $response;
}
throw new ClientException('Whoops, this should never happen');
} | [
"private",
"function",
"executeRequest",
"(",
"$",
"method",
",",
"$",
"url",
",",
"$",
"data",
",",
"array",
"$",
"customHeaders",
"=",
"[",
"]",
")",
"{",
"assert",
"(",
"$",
"this",
"->",
"_httpHeader",
"!==",
"''",
")",
";",
"$",
"wasAsync",
"=",... | Execute an HTTP request and return the results
This function will throw if no connection to the server can be established or if
there is a problem during data exchange with the server.
will restore it.
@throws Exception
@param string $method - HTTP request method
@param string $url - HTTP URL
@param string $data - data to post in body
@param array $customHeaders - any array containing header elements
@return HttpResponse | [
"Execute",
"an",
"HTTP",
"request",
"and",
"return",
"the",
"results"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Connection.php#L525-L641 |
arangodb/arangodb-php | lib/ArangoDBClient/Connection.php | Connection.parseResponse | public function parseResponse(HttpResponse $response)
{
$httpCode = $response->getHttpCode();
if ($httpCode < 200 || $httpCode >= 400) {
// failure on server
$body = $response->getBody();
if ($body !== '') {
// check if we can find details in the response body
$details = json_decode($body, true);
// handle failover
if (is_array($details) && isset($details['errorNum'])) {
if ($details['errorNum'] === 1495) {
// 1495 = leadership challenge is ongoing
$exception = new FailoverException(@$details['errorMessage'], @$details['code']);
throw $exception;
}
if ($details['errorNum'] === 1496) {
// 1496 = not a leader
// not a leader. now try to find new leader
$leader = $response->getLeaderEndpointHeader();
if ($leader) {
// have a different leader
$leader = Endpoint::normalize($leader);
$this->_options->addEndpoint($leader);
} else {
$leader = $this->_options->nextEndpoint();
}
// close existing connection
$this->closeHandle();
$this->updateHttpHeader();
$exception = new FailoverException(@$details['errorMessage'], @$details['code']);
$exception->setLeader($leader);
throw $exception;
}
}
if (is_array($details) && isset($details['errorMessage'])) {
// yes, we got details
$exception = new ServerException($details['errorMessage'], $details['code']);
$exception->setDetails($details);
throw $exception;
}
}
// check if server has responded with any other 503 response not handled above
if ($httpCode === 503) {
// generic service unavailable response
$exception = new FailoverException('service unavailable', 503);
throw $exception;
}
// no details found, throw normal exception
throw new ServerException($response->getResult(), $httpCode);
}
return $response;
} | php | public function parseResponse(HttpResponse $response)
{
$httpCode = $response->getHttpCode();
if ($httpCode < 200 || $httpCode >= 400) {
// failure on server
$body = $response->getBody();
if ($body !== '') {
// check if we can find details in the response body
$details = json_decode($body, true);
// handle failover
if (is_array($details) && isset($details['errorNum'])) {
if ($details['errorNum'] === 1495) {
// 1495 = leadership challenge is ongoing
$exception = new FailoverException(@$details['errorMessage'], @$details['code']);
throw $exception;
}
if ($details['errorNum'] === 1496) {
// 1496 = not a leader
// not a leader. now try to find new leader
$leader = $response->getLeaderEndpointHeader();
if ($leader) {
// have a different leader
$leader = Endpoint::normalize($leader);
$this->_options->addEndpoint($leader);
} else {
$leader = $this->_options->nextEndpoint();
}
// close existing connection
$this->closeHandle();
$this->updateHttpHeader();
$exception = new FailoverException(@$details['errorMessage'], @$details['code']);
$exception->setLeader($leader);
throw $exception;
}
}
if (is_array($details) && isset($details['errorMessage'])) {
// yes, we got details
$exception = new ServerException($details['errorMessage'], $details['code']);
$exception->setDetails($details);
throw $exception;
}
}
// check if server has responded with any other 503 response not handled above
if ($httpCode === 503) {
// generic service unavailable response
$exception = new FailoverException('service unavailable', 503);
throw $exception;
}
// no details found, throw normal exception
throw new ServerException($response->getResult(), $httpCode);
}
return $response;
} | [
"public",
"function",
"parseResponse",
"(",
"HttpResponse",
"$",
"response",
")",
"{",
"$",
"httpCode",
"=",
"$",
"response",
"->",
"getHttpCode",
"(",
")",
";",
"if",
"(",
"$",
"httpCode",
"<",
"200",
"||",
"$",
"httpCode",
">=",
"400",
")",
"{",
"// ... | Parse the response return the body values as an assoc array
@throws Exception
@param HttpResponse $response - the response as supplied by the server
@return HttpResponse | [
"Parse",
"the",
"response",
"return",
"the",
"body",
"values",
"as",
"an",
"assoc",
"array"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Connection.php#L652-L714 |
arangodb/arangodb-php | lib/ArangoDBClient/Connection.php | Connection.doBatch | private function doBatch($method, $request)
{
$batchPart = null;
if ($this->_captureBatch === true) {
/** @var $batch Batch */
$batch = $this->getActiveBatch();
$batchPart = $batch->append($method, $request);
}
# do batch processing
return $batchPart;
} | php | private function doBatch($method, $request)
{
$batchPart = null;
if ($this->_captureBatch === true) {
/** @var $batch Batch */
$batch = $this->getActiveBatch();
$batchPart = $batch->append($method, $request);
}
# do batch processing
return $batchPart;
} | [
"private",
"function",
"doBatch",
"(",
"$",
"method",
",",
"$",
"request",
")",
"{",
"$",
"batchPart",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"_captureBatch",
"===",
"true",
")",
"{",
"/** @var $batch Batch */",
"$",
"batch",
"=",
"$",
"this",
... | This is a helper function to executeRequest that captures requests if we're in batch mode
@param mixed $method - The method of the request (GET, POST...)
@param string $request - The request to process
This checks if we're in batch mode and returns a placeholder object,
since we need to return some object that is expected by the caller.
if we're not in batch mode it does not return anything, and
@return mixed Batchpart or null if not in batch capturing mode
@throws \ArangoDBClient\ClientException | [
"This",
"is",
"a",
"helper",
"function",
"to",
"executeRequest",
"that",
"captures",
"requests",
"if",
"we",
"re",
"in",
"batch",
"mode"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Connection.php#L810-L823 |
arangodb/arangodb-php | lib/ArangoDBClient/Connection.php | Connection.check_encoding | public static function check_encoding($data)
{
if (!is_array($data)) {
return;
}
foreach ($data as $key => $value) {
if (!is_array($value)) {
// check if the multibyte library function is installed and use it.
if (function_exists('mb_detect_encoding')) {
// check with mb library
if (is_string($key) && mb_detect_encoding($key, 'UTF-8', true) === false) {
throw new ClientException('Only UTF-8 encoded keys allowed. Wrong encoding in key string: ' . $key);
}
if (is_string($value) && mb_detect_encoding($value, 'UTF-8', true) === false) {
throw new ClientException('Only UTF-8 encoded values allowed. Wrong encoding in value string: ' . $value);
}
} else {
// fallback to preg_match checking
if (is_string($key) && self::detect_utf($key) === false) {
throw new ClientException('Only UTF-8 encoded keys allowed. Wrong encoding in key string: ' . $key);
}
if (is_string($value) && self::detect_utf($value) === false) {
throw new ClientException('Only UTF-8 encoded values allowed. Wrong encoding in value string: ' . $value);
}
}
} else {
self::check_encoding($value);
}
}
} | php | public static function check_encoding($data)
{
if (!is_array($data)) {
return;
}
foreach ($data as $key => $value) {
if (!is_array($value)) {
// check if the multibyte library function is installed and use it.
if (function_exists('mb_detect_encoding')) {
// check with mb library
if (is_string($key) && mb_detect_encoding($key, 'UTF-8', true) === false) {
throw new ClientException('Only UTF-8 encoded keys allowed. Wrong encoding in key string: ' . $key);
}
if (is_string($value) && mb_detect_encoding($value, 'UTF-8', true) === false) {
throw new ClientException('Only UTF-8 encoded values allowed. Wrong encoding in value string: ' . $value);
}
} else {
// fallback to preg_match checking
if (is_string($key) && self::detect_utf($key) === false) {
throw new ClientException('Only UTF-8 encoded keys allowed. Wrong encoding in key string: ' . $key);
}
if (is_string($value) && self::detect_utf($value) === false) {
throw new ClientException('Only UTF-8 encoded values allowed. Wrong encoding in value string: ' . $value);
}
}
} else {
self::check_encoding($value);
}
}
} | [
"public",
"static",
"function",
"check_encoding",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",... | This function checks that the encoding of the keys and
values of the array are utf-8, recursively.
It will raise an exception if it encounters wrong encoded strings.
@param array $data the data to check
@throws ClientException | [
"This",
"function",
"checks",
"that",
"the",
"encoding",
"of",
"the",
"keys",
"and",
"values",
"of",
"the",
"array",
"are",
"utf",
"-",
"8",
"recursively",
".",
"It",
"will",
"raise",
"an",
"exception",
"if",
"it",
"encounters",
"wrong",
"encoded",
"string... | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Connection.php#L853-L883 |
arangodb/arangodb-php | lib/ArangoDBClient/Connection.php | Connection.json_encode_wrapper | public function json_encode_wrapper($data, $options = 0)
{
if ($this->_options[ConnectionOptions::OPTION_CHECK_UTF8_CONFORM] === true) {
self::check_encoding($data);
}
if (empty($data)) {
$response = json_encode($data, $options | JSON_FORCE_OBJECT);
} else {
$response = json_encode($data, $options);
}
return $response;
} | php | public function json_encode_wrapper($data, $options = 0)
{
if ($this->_options[ConnectionOptions::OPTION_CHECK_UTF8_CONFORM] === true) {
self::check_encoding($data);
}
if (empty($data)) {
$response = json_encode($data, $options | JSON_FORCE_OBJECT);
} else {
$response = json_encode($data, $options);
}
return $response;
} | [
"public",
"function",
"json_encode_wrapper",
"(",
"$",
"data",
",",
"$",
"options",
"=",
"0",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_options",
"[",
"ConnectionOptions",
"::",
"OPTION_CHECK_UTF8_CONFORM",
"]",
"===",
"true",
")",
"{",
"self",
"::",
"chec... | This is a json_encode() wrapper that also checks if the data is utf-8 conform.
internally it calls the check_encoding() method. If that method does not throw
an Exception, this method will happily return the json_encoded data.
@param mixed $data the data to encode
@param mixed $options the options for the json_encode() call
@return string the result of the json_encode
@throws \ArangoDBClient\ClientException | [
"This",
"is",
"a",
"json_encode",
"()",
"wrapper",
"that",
"also",
"checks",
"if",
"the",
"data",
"is",
"utf",
"-",
"8",
"conform",
".",
"internally",
"it",
"calls",
"the",
"check_encoding",
"()",
"method",
".",
"If",
"that",
"method",
"does",
"not",
"th... | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Connection.php#L897-L909 |
arangodb/arangodb-php | lib/ArangoDBClient/Connection.php | Connection.setDatabase | public function setDatabase($database)
{
$this->_options[ConnectionOptions::OPTION_DATABASE] = $database;
$this->_database = $database;
$this->updateHttpHeader();
} | php | public function setDatabase($database)
{
$this->_options[ConnectionOptions::OPTION_DATABASE] = $database;
$this->_database = $database;
$this->updateHttpHeader();
} | [
"public",
"function",
"setDatabase",
"(",
"$",
"database",
")",
"{",
"$",
"this",
"->",
"_options",
"[",
"ConnectionOptions",
"::",
"OPTION_DATABASE",
"]",
"=",
"$",
"database",
";",
"$",
"this",
"->",
"_database",
"=",
"$",
"database",
";",
"$",
"this",
... | Set the database to use with this connection
Sets the database to use with this connection, for example: 'my_database'<br>
Further calls to the database will be addressed to the given database.
@param string $database the database to use | [
"Set",
"the",
"database",
"to",
"use",
"with",
"this",
"connection"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Connection.php#L920-L926 |
arangodb/arangodb-php | lib/ArangoDBClient/Endpoint.php | Endpoint.getType | public static function getType($value)
{
if (preg_match(self::REGEXP_TCP, $value)) {
return self::TYPE_TCP;
}
if (preg_match(self::REGEXP_SSL, $value)) {
return self::TYPE_SSL;
}
if (preg_match(self::REGEXP_UNIX, $value)) {
return self::TYPE_UNIX;
}
return null;
} | php | public static function getType($value)
{
if (preg_match(self::REGEXP_TCP, $value)) {
return self::TYPE_TCP;
}
if (preg_match(self::REGEXP_SSL, $value)) {
return self::TYPE_SSL;
}
if (preg_match(self::REGEXP_UNIX, $value)) {
return self::TYPE_UNIX;
}
return null;
} | [
"public",
"static",
"function",
"getType",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"preg_match",
"(",
"self",
"::",
"REGEXP_TCP",
",",
"$",
"value",
")",
")",
"{",
"return",
"self",
"::",
"TYPE_TCP",
";",
"}",
"if",
"(",
"preg_match",
"(",
"self",
":... | Return the type of an endpoint
@param string $value - endpoint specification value
@return string - endpoint type | [
"Return",
"the",
"type",
"of",
"an",
"endpoint"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Endpoint.php#L117-L132 |
arangodb/arangodb-php | lib/ArangoDBClient/Endpoint.php | Endpoint.getHost | public static function getHost($value)
{
if (preg_match(self::REGEXP_TCP, $value, $matches)) {
return preg_replace("/^http:/", "tcp:", $matches[2]);
}
if (preg_match(self::REGEXP_SSL, $value, $matches)) {
return preg_replace("/^https:/", "ssl:", $matches[2]);
}
return null;
} | php | public static function getHost($value)
{
if (preg_match(self::REGEXP_TCP, $value, $matches)) {
return preg_replace("/^http:/", "tcp:", $matches[2]);
}
if (preg_match(self::REGEXP_SSL, $value, $matches)) {
return preg_replace("/^https:/", "ssl:", $matches[2]);
}
return null;
} | [
"public",
"static",
"function",
"getHost",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"preg_match",
"(",
"self",
"::",
"REGEXP_TCP",
",",
"$",
"value",
",",
"$",
"matches",
")",
")",
"{",
"return",
"preg_replace",
"(",
"\"/^http:/\"",
",",
"\"tcp:\"",
",",
... | Return the host name of an endpoint
@param string $value - endpoint specification value
@return string - host name | [
"Return",
"the",
"host",
"name",
"of",
"an",
"endpoint"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Endpoint.php#L154-L165 |
arangodb/arangodb-php | lib/ArangoDBClient/Endpoint.php | Endpoint.isValid | public static function isValid($value)
{
if (is_string($value)) {
$value = [ $value ];
}
if (!is_array($value) || count($value) === 0) {
return false;
}
foreach ($value as $ep) {
if (!is_string($ep)) {
return false;
}
$type = self::getType($ep);
if ($type === null) {
return false;
}
}
return true;
} | php | public static function isValid($value)
{
if (is_string($value)) {
$value = [ $value ];
}
if (!is_array($value) || count($value) === 0) {
return false;
}
foreach ($value as $ep) {
if (!is_string($ep)) {
return false;
}
$type = self::getType($ep);
if ($type === null) {
return false;
}
}
return true;
} | [
"public",
"static",
"function",
"isValid",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"[",
"$",
"value",
"]",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
"||",
"co... | check whether an endpoint specification is valid
@param string $mixed - endpoint specification value (can be a string or an array of strings)
@return bool - true if endpoint specification is valid, false otherwise | [
"check",
"whether",
"an",
"endpoint",
"specification",
"is",
"valid"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Endpoint.php#L174-L195 |
arangodb/arangodb-php | lib/ArangoDBClient/Endpoint.php | Endpoint.listEndpoints | public static function listEndpoints(Connection $connection)
{
$response = $connection->get(Urls::URL_ENDPOINT);
return $response->getJson();
} | php | public static function listEndpoints(Connection $connection)
{
$response = $connection->get(Urls::URL_ENDPOINT);
return $response->getJson();
} | [
"public",
"static",
"function",
"listEndpoints",
"(",
"Connection",
"$",
"connection",
")",
"{",
"$",
"response",
"=",
"$",
"connection",
"->",
"get",
"(",
"Urls",
"::",
"URL_ENDPOINT",
")",
";",
"return",
"$",
"response",
"->",
"getJson",
"(",
")",
";",
... | List endpoints
This will list the endpoints that are configured on the server
@param Connection $connection - the connection to be used
@link https://docs.arangodb.com/HTTP/Endpoints/index.html
@return array $responseArray - The response array.
@throws \ArangoDBClient\Exception | [
"List",
"endpoints"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Endpoint.php#L209-L214 |
arangodb/arangodb-php | lib/ArangoDBClient/Edge.php | Edge.set | public function set($key, $value)
{
if ($this->_doValidate) {
// validate the value passed
ValueValidator::validate($value);
}
if ($key[0] === '_') {
if ($key === self::ENTRY_ID) {
$this->setInternalId($value);
return;
}
if ($key === self::ENTRY_KEY) {
$this->setInternalKey($value);
return;
}
if ($key === self::ENTRY_REV) {
$this->setRevision($value);
return;
}
if ($key === self::ENTRY_FROM) {
$this->setFrom($value);
return;
}
if ($key === self::ENTRY_TO) {
$this->setTo($value);
return;
}
}
if (!$this->_changed) {
if (!isset($this->_values[$key]) || $this->_values[$key] !== $value) {
// set changed flag
$this->_changed = true;
}
}
// and store the value
$this->_values[$key] = $value;
} | php | public function set($key, $value)
{
if ($this->_doValidate) {
// validate the value passed
ValueValidator::validate($value);
}
if ($key[0] === '_') {
if ($key === self::ENTRY_ID) {
$this->setInternalId($value);
return;
}
if ($key === self::ENTRY_KEY) {
$this->setInternalKey($value);
return;
}
if ($key === self::ENTRY_REV) {
$this->setRevision($value);
return;
}
if ($key === self::ENTRY_FROM) {
$this->setFrom($value);
return;
}
if ($key === self::ENTRY_TO) {
$this->setTo($value);
return;
}
}
if (!$this->_changed) {
if (!isset($this->_values[$key]) || $this->_values[$key] !== $value) {
// set changed flag
$this->_changed = true;
}
}
// and store the value
$this->_values[$key] = $value;
} | [
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_doValidate",
")",
"{",
"// validate the value passed",
"ValueValidator",
"::",
"validate",
"(",
"$",
"value",
")",
";",
"}",
"if",
"(",
"$",
"key... | Set a document attribute
The key (attribute name) must be a string.
This will validate the value of the attribute and might throw an
exception if the value is invalid.
@throws ClientException
@param string $key - attribute name
@param mixed $value - value for attribute
@return void | [
"Set",
"a",
"document",
"attribute"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Edge.php#L64-L112 |
arangodb/arangodb-php | lib/ArangoDBClient/Edge.php | Edge.getAllForInsertUpdate | public function getAllForInsertUpdate()
{
$data = parent::getAllForInsertUpdate();
if ($this->_from !== null) {
$data['_from'] = $this->_from;
}
if ($this->_to !== null) {
$data['_to'] = $this->_to;
}
return $data;
} | php | public function getAllForInsertUpdate()
{
$data = parent::getAllForInsertUpdate();
if ($this->_from !== null) {
$data['_from'] = $this->_from;
}
if ($this->_to !== null) {
$data['_to'] = $this->_to;
}
return $data;
} | [
"public",
"function",
"getAllForInsertUpdate",
"(",
")",
"{",
"$",
"data",
"=",
"parent",
"::",
"getAllForInsertUpdate",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_from",
"!==",
"null",
")",
"{",
"$",
"data",
"[",
"'_from'",
"]",
"=",
"$",
"this",
... | Get all document attributes for insertion/update
@return mixed - associative array of all document attributes/values | [
"Get",
"all",
"document",
"attributes",
"for",
"insertion",
"/",
"update"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/Edge.php#L168-L179 |
arangodb/arangodb-php | lib/ArangoDBClient/HttpHelper.php | HttpHelper.createConnection | public static function createConnection(ConnectionOptions $options)
{
$endpoint = $options->getCurrentEndpoint();
$context = stream_context_create();
if (Endpoint::getType($endpoint) === Endpoint::TYPE_SSL) {
// set further SSL options for the endpoint
stream_context_set_option($context, 'ssl', 'verify_peer', $options[ConnectionOptions::OPTION_VERIFY_CERT]);
@stream_context_set_option($context, 'ssl', 'verify_peer_name', $options[ConnectionOptions::OPTION_VERIFY_CERT_NAME]);
stream_context_set_option($context, 'ssl', 'allow_self_signed', $options[ConnectionOptions::OPTION_ALLOW_SELF_SIGNED]);
if ($options[ConnectionOptions::OPTION_CIPHERS] !== null) {
// SSL ciphers
stream_context_set_option($context, 'ssl', 'ciphers', $options[ConnectionOptions::OPTION_CIPHERS]);
}
}
$fp = @stream_socket_client(
Endpoint::normalize($endpoint),
$errNo,
$message,
$options[ConnectionOptions::OPTION_TIMEOUT],
STREAM_CLIENT_CONNECT,
$context
);
if (!$fp) {
throw new ConnectException(
'cannot connect to endpoint \'' .
$endpoint . '\': ' . $message, $errNo
);
}
stream_set_timeout($fp, $options[ConnectionOptions::OPTION_TIMEOUT]);
return $fp;
} | php | public static function createConnection(ConnectionOptions $options)
{
$endpoint = $options->getCurrentEndpoint();
$context = stream_context_create();
if (Endpoint::getType($endpoint) === Endpoint::TYPE_SSL) {
// set further SSL options for the endpoint
stream_context_set_option($context, 'ssl', 'verify_peer', $options[ConnectionOptions::OPTION_VERIFY_CERT]);
@stream_context_set_option($context, 'ssl', 'verify_peer_name', $options[ConnectionOptions::OPTION_VERIFY_CERT_NAME]);
stream_context_set_option($context, 'ssl', 'allow_self_signed', $options[ConnectionOptions::OPTION_ALLOW_SELF_SIGNED]);
if ($options[ConnectionOptions::OPTION_CIPHERS] !== null) {
// SSL ciphers
stream_context_set_option($context, 'ssl', 'ciphers', $options[ConnectionOptions::OPTION_CIPHERS]);
}
}
$fp = @stream_socket_client(
Endpoint::normalize($endpoint),
$errNo,
$message,
$options[ConnectionOptions::OPTION_TIMEOUT],
STREAM_CLIENT_CONNECT,
$context
);
if (!$fp) {
throw new ConnectException(
'cannot connect to endpoint \'' .
$endpoint . '\': ' . $message, $errNo
);
}
stream_set_timeout($fp, $options[ConnectionOptions::OPTION_TIMEOUT]);
return $fp;
} | [
"public",
"static",
"function",
"createConnection",
"(",
"ConnectionOptions",
"$",
"options",
")",
"{",
"$",
"endpoint",
"=",
"$",
"options",
"->",
"getCurrentEndpoint",
"(",
")",
";",
"$",
"context",
"=",
"stream_context_create",
"(",
")",
";",
"if",
"(",
"... | Create a one-time HTTP connection by opening a socket to the server
It is the caller's responsibility to close the socket
@throws ConnectException
@param ConnectionOptions $options - connection options
@return resource - socket with server connection, will throw when no connection can be established | [
"Create",
"a",
"one",
"-",
"time",
"HTTP",
"connection",
"by",
"opening",
"a",
"socket",
"to",
"the",
"server"
] | train | https://github.com/arangodb/arangodb-php/blob/89fac3fc9ab21ec8cf0a5dc35118abfaa3d49b02/lib/ArangoDBClient/HttpHelper.php#L82-L118 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.