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 |
|---|---|---|---|---|---|---|---|---|---|---|
apisearch-io/php-client | Query/Filter.php | Filter.toArray | public function toArray(): array
{
return array_filter([
'field' => 'uuid.type' === $this->field
? null
: $this->field,
'values' => $this->values,
'application_type' => self::AT_LEAST_ONE === $this->applicationType
? null
: $this->applicationType,
'filter_type' => self::TYPE_FIELD === $this->filterType
? null
: $this->filterType,
'filter_terms' => $this->filterTerms,
], function ($element) {
return
!(
is_null($element) ||
(is_array($element) && empty($element))
);
});
} | php | public function toArray(): array
{
return array_filter([
'field' => 'uuid.type' === $this->field
? null
: $this->field,
'values' => $this->values,
'application_type' => self::AT_LEAST_ONE === $this->applicationType
? null
: $this->applicationType,
'filter_type' => self::TYPE_FIELD === $this->filterType
? null
: $this->filterType,
'filter_terms' => $this->filterTerms,
], function ($element) {
return
!(
is_null($element) ||
(is_array($element) && empty($element))
);
});
} | [
"public",
"function",
"toArray",
"(",
")",
":",
"array",
"{",
"return",
"array_filter",
"(",
"[",
"'field'",
"=>",
"'uuid.type'",
"===",
"$",
"this",
"->",
"field",
"?",
"null",
":",
"$",
"this",
"->",
"field",
",",
"'values'",
"=>",
"$",
"this",
"->",
"values",
",",
"'application_type'",
"=>",
"self",
"::",
"AT_LEAST_ONE",
"===",
"$",
"this",
"->",
"applicationType",
"?",
"null",
":",
"$",
"this",
"->",
"applicationType",
",",
"'filter_type'",
"=>",
"self",
"::",
"TYPE_FIELD",
"===",
"$",
"this",
"->",
"filterType",
"?",
"null",
":",
"$",
"this",
"->",
"filterType",
",",
"'filter_terms'",
"=>",
"$",
"this",
"->",
"filterTerms",
",",
"]",
",",
"function",
"(",
"$",
"element",
")",
"{",
"return",
"!",
"(",
"is_null",
"(",
"$",
"element",
")",
"||",
"(",
"is_array",
"(",
"$",
"element",
")",
"&&",
"empty",
"(",
"$",
"element",
")",
")",
")",
";",
"}",
")",
";",
"}"
] | To array.
@return array | [
"To",
"array",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Filter.php#L250-L271 |
apisearch-io/php-client | Query/Filter.php | Filter.createFromArray | public static function createFromArray(array $array): self
{
if (
isset($array['values']) &&
!is_array($array['values'])
) {
throw InvalidFormatException::queryFormatNotValid($array);
}
return self::create(
$array['field'] ?? 'uuid.type',
$array['values'] ?? [],
(int) ($array['application_type'] ?? self::AT_LEAST_ONE),
$array['filter_type'] ?? self::TYPE_FIELD,
$array['filter_terms'] ?? []
);
} | php | public static function createFromArray(array $array): self
{
if (
isset($array['values']) &&
!is_array($array['values'])
) {
throw InvalidFormatException::queryFormatNotValid($array);
}
return self::create(
$array['field'] ?? 'uuid.type',
$array['values'] ?? [],
(int) ($array['application_type'] ?? self::AT_LEAST_ONE),
$array['filter_type'] ?? self::TYPE_FIELD,
$array['filter_terms'] ?? []
);
} | [
"public",
"static",
"function",
"createFromArray",
"(",
"array",
"$",
"array",
")",
":",
"self",
"{",
"if",
"(",
"isset",
"(",
"$",
"array",
"[",
"'values'",
"]",
")",
"&&",
"!",
"is_array",
"(",
"$",
"array",
"[",
"'values'",
"]",
")",
")",
"{",
"throw",
"InvalidFormatException",
"::",
"queryFormatNotValid",
"(",
"$",
"array",
")",
";",
"}",
"return",
"self",
"::",
"create",
"(",
"$",
"array",
"[",
"'field'",
"]",
"??",
"'uuid.type'",
",",
"$",
"array",
"[",
"'values'",
"]",
"??",
"[",
"]",
",",
"(",
"int",
")",
"(",
"$",
"array",
"[",
"'application_type'",
"]",
"??",
"self",
"::",
"AT_LEAST_ONE",
")",
",",
"$",
"array",
"[",
"'filter_type'",
"]",
"??",
"self",
"::",
"TYPE_FIELD",
",",
"$",
"array",
"[",
"'filter_terms'",
"]",
"??",
"[",
"]",
")",
";",
"}"
] | Create from array.
@param array $array
@return Filter | [
"Create",
"from",
"array",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Filter.php#L280-L296 |
apisearch-io/php-client | Http/Retry.php | Retry.createFromArray | public static function createFromArray(array $data): Retry
{
return new Retry(
(string) (trim(trim(strtolower($data['url'] ?? '*')), '/')),
(string) (trim(strtolower($data['method'] ?? '*'))),
(int) ($data['retries'] ?? 0),
(int) ($data['microseconds_between_retries'] ?? self::DEFAULT_MICROSECONDS_BETWEEN_RETRIES)
);
} | php | public static function createFromArray(array $data): Retry
{
return new Retry(
(string) (trim(trim(strtolower($data['url'] ?? '*')), '/')),
(string) (trim(strtolower($data['method'] ?? '*'))),
(int) ($data['retries'] ?? 0),
(int) ($data['microseconds_between_retries'] ?? self::DEFAULT_MICROSECONDS_BETWEEN_RETRIES)
);
} | [
"public",
"static",
"function",
"createFromArray",
"(",
"array",
"$",
"data",
")",
":",
"Retry",
"{",
"return",
"new",
"Retry",
"(",
"(",
"string",
")",
"(",
"trim",
"(",
"trim",
"(",
"strtolower",
"(",
"$",
"data",
"[",
"'url'",
"]",
"??",
"'*'",
")",
")",
",",
"'/'",
")",
")",
",",
"(",
"string",
")",
"(",
"trim",
"(",
"strtolower",
"(",
"$",
"data",
"[",
"'method'",
"]",
"??",
"'*'",
")",
")",
")",
",",
"(",
"int",
")",
"(",
"$",
"data",
"[",
"'retries'",
"]",
"??",
"0",
")",
",",
"(",
"int",
")",
"(",
"$",
"data",
"[",
"'microseconds_between_retries'",
"]",
"??",
"self",
"::",
"DEFAULT_MICROSECONDS_BETWEEN_RETRIES",
")",
")",
";",
"}"
] | Create from array.
@param array $data
@return Retry | [
"Create",
"from",
"array",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Http/Retry.php#L85-L93 |
apisearch-io/php-client | Http/CurlAdapter.php | CurlAdapter.getByRequestParts | public function getByRequestParts(
string $host,
string $method,
RequestParts $requestParts
): array {
$json = json_encode($requestParts->getParameters()['json']);
$formattedUrl = rtrim($host, '/').'/'.ltrim($requestParts->getUrl(), '/');
$method = strtoupper($method);
$headers = [];
foreach ($requestParts->getParameters()['headers'] ?? [] as $header => $value) {
$headers[] = "$header: $value";
}
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $formattedUrl);
curl_setopt($c, CURLOPT_HEADER, false);
curl_setopt($c, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($c, CURLOPT_ENCODING, 'gzip, deflate');
if (!in_array($method, ['GET', 'HEAD'])) {
curl_setopt($c, CURLOPT_POSTFIELDS, $json);
$headers[] = 'Content-Type: application/json';
$headers[] = 'Content-Length: '.strlen($json);
}
curl_setopt($c, CURLOPT_HTTPHEADER, $headers);
$content = curl_exec($c);
$responseCode = curl_getinfo($c, CURLINFO_HTTP_CODE);
curl_close($c);
if (
'HEAD' !== $method &&
false === $content
) {
throw ConnectionException::buildConnectExceptionByUrl($requestParts->getUrl());
}
return [
'code' => (int) $responseCode,
'body' => empty($content)
? []
: json_decode($content, true),
];
} | php | public function getByRequestParts(
string $host,
string $method,
RequestParts $requestParts
): array {
$json = json_encode($requestParts->getParameters()['json']);
$formattedUrl = rtrim($host, '/').'/'.ltrim($requestParts->getUrl(), '/');
$method = strtoupper($method);
$headers = [];
foreach ($requestParts->getParameters()['headers'] ?? [] as $header => $value) {
$headers[] = "$header: $value";
}
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $formattedUrl);
curl_setopt($c, CURLOPT_HEADER, false);
curl_setopt($c, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($c, CURLOPT_ENCODING, 'gzip, deflate');
if (!in_array($method, ['GET', 'HEAD'])) {
curl_setopt($c, CURLOPT_POSTFIELDS, $json);
$headers[] = 'Content-Type: application/json';
$headers[] = 'Content-Length: '.strlen($json);
}
curl_setopt($c, CURLOPT_HTTPHEADER, $headers);
$content = curl_exec($c);
$responseCode = curl_getinfo($c, CURLINFO_HTTP_CODE);
curl_close($c);
if (
'HEAD' !== $method &&
false === $content
) {
throw ConnectionException::buildConnectExceptionByUrl($requestParts->getUrl());
}
return [
'code' => (int) $responseCode,
'body' => empty($content)
? []
: json_decode($content, true),
];
} | [
"public",
"function",
"getByRequestParts",
"(",
"string",
"$",
"host",
",",
"string",
"$",
"method",
",",
"RequestParts",
"$",
"requestParts",
")",
":",
"array",
"{",
"$",
"json",
"=",
"json_encode",
"(",
"$",
"requestParts",
"->",
"getParameters",
"(",
")",
"[",
"'json'",
"]",
")",
";",
"$",
"formattedUrl",
"=",
"rtrim",
"(",
"$",
"host",
",",
"'/'",
")",
".",
"'/'",
".",
"ltrim",
"(",
"$",
"requestParts",
"->",
"getUrl",
"(",
")",
",",
"'/'",
")",
";",
"$",
"method",
"=",
"strtoupper",
"(",
"$",
"method",
")",
";",
"$",
"headers",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"requestParts",
"->",
"getParameters",
"(",
")",
"[",
"'headers'",
"]",
"??",
"[",
"]",
"as",
"$",
"header",
"=>",
"$",
"value",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"\"$header: $value\"",
";",
"}",
"$",
"c",
"=",
"curl_init",
"(",
")",
";",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_RETURNTRANSFER",
",",
"1",
")",
";",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_URL",
",",
"$",
"formattedUrl",
")",
";",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_HEADER",
",",
"false",
")",
";",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_CUSTOMREQUEST",
",",
"$",
"method",
")",
";",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_ENCODING",
",",
"'gzip, deflate'",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"method",
",",
"[",
"'GET'",
",",
"'HEAD'",
"]",
")",
")",
"{",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_POSTFIELDS",
",",
"$",
"json",
")",
";",
"$",
"headers",
"[",
"]",
"=",
"'Content-Type: application/json'",
";",
"$",
"headers",
"[",
"]",
"=",
"'Content-Length: '",
".",
"strlen",
"(",
"$",
"json",
")",
";",
"}",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_HTTPHEADER",
",",
"$",
"headers",
")",
";",
"$",
"content",
"=",
"curl_exec",
"(",
"$",
"c",
")",
";",
"$",
"responseCode",
"=",
"curl_getinfo",
"(",
"$",
"c",
",",
"CURLINFO_HTTP_CODE",
")",
";",
"curl_close",
"(",
"$",
"c",
")",
";",
"if",
"(",
"'HEAD'",
"!==",
"$",
"method",
"&&",
"false",
"===",
"$",
"content",
")",
"{",
"throw",
"ConnectionException",
"::",
"buildConnectExceptionByUrl",
"(",
"$",
"requestParts",
"->",
"getUrl",
"(",
")",
")",
";",
"}",
"return",
"[",
"'code'",
"=>",
"(",
"int",
")",
"$",
"responseCode",
",",
"'body'",
"=>",
"empty",
"(",
"$",
"content",
")",
"?",
"[",
"]",
":",
"json_decode",
"(",
"$",
"content",
",",
"true",
")",
",",
"]",
";",
"}"
] | Get.
@param string $host
@param string $method
@param RequestParts $requestParts
@return array
@throws ConnectionException | [
"Get",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Http/CurlAdapter.php#L36-L80 |
apisearch-io/php-client | Http/Client.php | Client.buildRequestParts | public function buildRequestParts(
string $url,
array $query = [],
array $body = [],
array $server = []
): RequestParts {
$url = trim($url, '/');
$url = trim("{$this->version}/$url", '/');
$url = $this->buildUrlParams($url, $query);
return new RequestParts(
$url,
[
'json' => $body,
'headers' => $server,
],
[
'decode_content' => 'gzip',
]
);
} | php | public function buildRequestParts(
string $url,
array $query = [],
array $body = [],
array $server = []
): RequestParts {
$url = trim($url, '/');
$url = trim("{$this->version}/$url", '/');
$url = $this->buildUrlParams($url, $query);
return new RequestParts(
$url,
[
'json' => $body,
'headers' => $server,
],
[
'decode_content' => 'gzip',
]
);
} | [
"public",
"function",
"buildRequestParts",
"(",
"string",
"$",
"url",
",",
"array",
"$",
"query",
"=",
"[",
"]",
",",
"array",
"$",
"body",
"=",
"[",
"]",
",",
"array",
"$",
"server",
"=",
"[",
"]",
")",
":",
"RequestParts",
"{",
"$",
"url",
"=",
"trim",
"(",
"$",
"url",
",",
"'/'",
")",
";",
"$",
"url",
"=",
"trim",
"(",
"\"{$this->version}/$url\"",
",",
"'/'",
")",
";",
"$",
"url",
"=",
"$",
"this",
"->",
"buildUrlParams",
"(",
"$",
"url",
",",
"$",
"query",
")",
";",
"return",
"new",
"RequestParts",
"(",
"$",
"url",
",",
"[",
"'json'",
"=>",
"$",
"body",
",",
"'headers'",
"=>",
"$",
"server",
",",
"]",
",",
"[",
"'decode_content'",
"=>",
"'gzip'",
",",
"]",
")",
";",
"}"
] | Get some parameters and build a RequestParts instance.
@param string $url
@param array $query
@param array $body
@param array $server
@return RequestParts | [
"Get",
"some",
"parameters",
"and",
"build",
"a",
"RequestParts",
"instance",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Http/Client.php#L61-L81 |
apisearch-io/php-client | Http/Client.php | Client.buildUrlParams | private function buildUrlParams(
string $url,
array $params
) {
array_walk($params, function (&$value, $key) {
$value = "$key=$value";
});
return $url.'?'.implode('&', $params);
} | php | private function buildUrlParams(
string $url,
array $params
) {
array_walk($params, function (&$value, $key) {
$value = "$key=$value";
});
return $url.'?'.implode('&', $params);
} | [
"private",
"function",
"buildUrlParams",
"(",
"string",
"$",
"url",
",",
"array",
"$",
"params",
")",
"{",
"array_walk",
"(",
"$",
"params",
",",
"function",
"(",
"&",
"$",
"value",
",",
"$",
"key",
")",
"{",
"$",
"value",
"=",
"\"$key=$value\"",
";",
"}",
")",
";",
"return",
"$",
"url",
".",
"'?'",
".",
"implode",
"(",
"'&'",
",",
"$",
"params",
")",
";",
"}"
] | Build url params.
@param string $url
@param string[] $params
@return string | [
"Build",
"url",
"params",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Http/Client.php#L91-L100 |
apisearch-io/php-client | Exporter/JSONExporter.php | JSONExporter.formatToItems | public function formatToItems(string $data): array
{
return array_map(function (array $item) {
$itemAsArray = [
'uuid' => [
'id' => $item[0],
'type' => $item[1],
],
'metadata' => $item[2],
'indexed_metadata' => $item[3],
'searchable_metadata' => $item[4],
'exact_matching_metadata' => $item[5],
'suggest' => $item[6],
];
if (!empty($item[7])) {
$itemAsArray['coordinate'] = $item[7];
}
return Item::createFromArray($itemAsArray);
}, json_decode($data, true));
} | php | public function formatToItems(string $data): array
{
return array_map(function (array $item) {
$itemAsArray = [
'uuid' => [
'id' => $item[0],
'type' => $item[1],
],
'metadata' => $item[2],
'indexed_metadata' => $item[3],
'searchable_metadata' => $item[4],
'exact_matching_metadata' => $item[5],
'suggest' => $item[6],
];
if (!empty($item[7])) {
$itemAsArray['coordinate'] = $item[7];
}
return Item::createFromArray($itemAsArray);
}, json_decode($data, true));
} | [
"public",
"function",
"formatToItems",
"(",
"string",
"$",
"data",
")",
":",
"array",
"{",
"return",
"array_map",
"(",
"function",
"(",
"array",
"$",
"item",
")",
"{",
"$",
"itemAsArray",
"=",
"[",
"'uuid'",
"=>",
"[",
"'id'",
"=>",
"$",
"item",
"[",
"0",
"]",
",",
"'type'",
"=>",
"$",
"item",
"[",
"1",
"]",
",",
"]",
",",
"'metadata'",
"=>",
"$",
"item",
"[",
"2",
"]",
",",
"'indexed_metadata'",
"=>",
"$",
"item",
"[",
"3",
"]",
",",
"'searchable_metadata'",
"=>",
"$",
"item",
"[",
"4",
"]",
",",
"'exact_matching_metadata'",
"=>",
"$",
"item",
"[",
"5",
"]",
",",
"'suggest'",
"=>",
"$",
"item",
"[",
"6",
"]",
",",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"item",
"[",
"7",
"]",
")",
")",
"{",
"$",
"itemAsArray",
"[",
"'coordinate'",
"]",
"=",
"$",
"item",
"[",
"7",
"]",
";",
"}",
"return",
"Item",
"::",
"createFromArray",
"(",
"$",
"itemAsArray",
")",
";",
"}",
",",
"json_decode",
"(",
"$",
"data",
",",
"true",
")",
")",
";",
"}"
] | Convert string formatted to array of Items.
@param string $data
@return Item[] | [
"Convert",
"string",
"formatted",
"to",
"array",
"of",
"Items",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Exporter/JSONExporter.php#L78-L99 |
apisearch-io/php-client | Exception/ExporterNotAvailableException.php | ExporterNotAvailableException.createForMissingDependency | public static function createForMissingDependency(
string $format,
string $missingClass,
string $package
): self {
return new self(sprintf('Exporter %s not available. Missing class %s. To resolve it, add %d in your composer',
$format,
$missingClass,
$package
));
} | php | public static function createForMissingDependency(
string $format,
string $missingClass,
string $package
): self {
return new self(sprintf('Exporter %s not available. Missing class %s. To resolve it, add %d in your composer',
$format,
$missingClass,
$package
));
} | [
"public",
"static",
"function",
"createForMissingDependency",
"(",
"string",
"$",
"format",
",",
"string",
"$",
"missingClass",
",",
"string",
"$",
"package",
")",
":",
"self",
"{",
"return",
"new",
"self",
"(",
"sprintf",
"(",
"'Exporter %s not available. Missing class %s. To resolve it, add %d in your composer'",
",",
"$",
"format",
",",
"$",
"missingClass",
",",
"$",
"package",
")",
")",
";",
"}"
] | Create exporter not available because of missing dependency.
@param string $format
@param string $missingClass
@param string $package
@return ExporterNotAvailableException | [
"Create",
"exporter",
"not",
"available",
"because",
"of",
"missing",
"dependency",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Exception/ExporterNotAvailableException.php#L34-L44 |
apisearch-io/php-client | Url/UrlBuilder.php | UrlBuilder.guessFilterValue | public function guessFilterValue(
Result $result,
Aggregation $aggregation,
Counter $counter
): string {
return $counter->isUsed()
? $this->removeFilterValue(
$result,
$aggregation->getName(),
$counter->getId()
)
: $this->addFilterValue(
$result,
$aggregation->getName(),
$counter->getId()
);
} | php | public function guessFilterValue(
Result $result,
Aggregation $aggregation,
Counter $counter
): string {
return $counter->isUsed()
? $this->removeFilterValue(
$result,
$aggregation->getName(),
$counter->getId()
)
: $this->addFilterValue(
$result,
$aggregation->getName(),
$counter->getId()
);
} | [
"public",
"function",
"guessFilterValue",
"(",
"Result",
"$",
"result",
",",
"Aggregation",
"$",
"aggregation",
",",
"Counter",
"$",
"counter",
")",
":",
"string",
"{",
"return",
"$",
"counter",
"->",
"isUsed",
"(",
")",
"?",
"$",
"this",
"->",
"removeFilterValue",
"(",
"$",
"result",
",",
"$",
"aggregation",
"->",
"getName",
"(",
")",
",",
"$",
"counter",
"->",
"getId",
"(",
")",
")",
":",
"$",
"this",
"->",
"addFilterValue",
"(",
"$",
"result",
",",
"$",
"aggregation",
"->",
"getName",
"(",
")",
",",
"$",
"counter",
"->",
"getId",
"(",
")",
")",
";",
"}"
] | Guess filter value.
@param Result $result
@param Aggregation $aggregation
@param Counter $counter
@return string | [
"Guess",
"filter",
"value",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Url/UrlBuilder.php#L79-L95 |
apisearch-io/php-client | Url/UrlBuilder.php | UrlBuilder.addFilterValue | public function addFilterValue(
Result $result,
string $filterName,
string $value
): string {
if (isset($this->routesCache[spl_object_hash($result)][$filterName])) {
return str_replace(
['{id}', '{slug}'],
$result->getAggregation($filterName)->getCounter($value)->getValues(),
$this->routesCache[spl_object_hash($result)][$filterName]
);
}
$urlParameters = $this->generateQueryUrlParameters($result, $filterName);
if (
!isset($urlParameters[$filterName]) ||
!in_array($value, $urlParameters[$filterName])
) {
$urlParameters[$filterName][] = $value;
}
$urlElements = $this->createUrlByUrlParameters(
$result,
$urlParameters
);
$templateRoute = in_array($urlElements['field'], [false, $filterName])
? $urlElements['template_path']
: parse_url($urlElements['route'], PHP_URL_PATH);
$filteredUrlParameters = $urlElements['url_parameters'];
$routeQuery = parse_url($urlElements['route'], PHP_URL_QUERY);
$route = rtrim("$templateRoute?$routeQuery", '?');
if (isset($filteredUrlParameters[$filterName])) {
$paremeterKey = array_search($value, $filteredUrlParameters[$filterName]);
$route = str_replace(
"{$filterName}[$paremeterKey]=$value",
"{$filterName}[$paremeterKey]={id}",
$route
);
}
$this->routesCache[spl_object_hash($result)][$filterName] = $route;
return $urlElements['route'];
} | php | public function addFilterValue(
Result $result,
string $filterName,
string $value
): string {
if (isset($this->routesCache[spl_object_hash($result)][$filterName])) {
return str_replace(
['{id}', '{slug}'],
$result->getAggregation($filterName)->getCounter($value)->getValues(),
$this->routesCache[spl_object_hash($result)][$filterName]
);
}
$urlParameters = $this->generateQueryUrlParameters($result, $filterName);
if (
!isset($urlParameters[$filterName]) ||
!in_array($value, $urlParameters[$filterName])
) {
$urlParameters[$filterName][] = $value;
}
$urlElements = $this->createUrlByUrlParameters(
$result,
$urlParameters
);
$templateRoute = in_array($urlElements['field'], [false, $filterName])
? $urlElements['template_path']
: parse_url($urlElements['route'], PHP_URL_PATH);
$filteredUrlParameters = $urlElements['url_parameters'];
$routeQuery = parse_url($urlElements['route'], PHP_URL_QUERY);
$route = rtrim("$templateRoute?$routeQuery", '?');
if (isset($filteredUrlParameters[$filterName])) {
$paremeterKey = array_search($value, $filteredUrlParameters[$filterName]);
$route = str_replace(
"{$filterName}[$paremeterKey]=$value",
"{$filterName}[$paremeterKey]={id}",
$route
);
}
$this->routesCache[spl_object_hash($result)][$filterName] = $route;
return $urlElements['route'];
} | [
"public",
"function",
"addFilterValue",
"(",
"Result",
"$",
"result",
",",
"string",
"$",
"filterName",
",",
"string",
"$",
"value",
")",
":",
"string",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"routesCache",
"[",
"spl_object_hash",
"(",
"$",
"result",
")",
"]",
"[",
"$",
"filterName",
"]",
")",
")",
"{",
"return",
"str_replace",
"(",
"[",
"'{id}'",
",",
"'{slug}'",
"]",
",",
"$",
"result",
"->",
"getAggregation",
"(",
"$",
"filterName",
")",
"->",
"getCounter",
"(",
"$",
"value",
")",
"->",
"getValues",
"(",
")",
",",
"$",
"this",
"->",
"routesCache",
"[",
"spl_object_hash",
"(",
"$",
"result",
")",
"]",
"[",
"$",
"filterName",
"]",
")",
";",
"}",
"$",
"urlParameters",
"=",
"$",
"this",
"->",
"generateQueryUrlParameters",
"(",
"$",
"result",
",",
"$",
"filterName",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"urlParameters",
"[",
"$",
"filterName",
"]",
")",
"||",
"!",
"in_array",
"(",
"$",
"value",
",",
"$",
"urlParameters",
"[",
"$",
"filterName",
"]",
")",
")",
"{",
"$",
"urlParameters",
"[",
"$",
"filterName",
"]",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"$",
"urlElements",
"=",
"$",
"this",
"->",
"createUrlByUrlParameters",
"(",
"$",
"result",
",",
"$",
"urlParameters",
")",
";",
"$",
"templateRoute",
"=",
"in_array",
"(",
"$",
"urlElements",
"[",
"'field'",
"]",
",",
"[",
"false",
",",
"$",
"filterName",
"]",
")",
"?",
"$",
"urlElements",
"[",
"'template_path'",
"]",
":",
"parse_url",
"(",
"$",
"urlElements",
"[",
"'route'",
"]",
",",
"PHP_URL_PATH",
")",
";",
"$",
"filteredUrlParameters",
"=",
"$",
"urlElements",
"[",
"'url_parameters'",
"]",
";",
"$",
"routeQuery",
"=",
"parse_url",
"(",
"$",
"urlElements",
"[",
"'route'",
"]",
",",
"PHP_URL_QUERY",
")",
";",
"$",
"route",
"=",
"rtrim",
"(",
"\"$templateRoute?$routeQuery\"",
",",
"'?'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"filteredUrlParameters",
"[",
"$",
"filterName",
"]",
")",
")",
"{",
"$",
"paremeterKey",
"=",
"array_search",
"(",
"$",
"value",
",",
"$",
"filteredUrlParameters",
"[",
"$",
"filterName",
"]",
")",
";",
"$",
"route",
"=",
"str_replace",
"(",
"\"{$filterName}[$paremeterKey]=$value\"",
",",
"\"{$filterName}[$paremeterKey]={id}\"",
",",
"$",
"route",
")",
";",
"}",
"$",
"this",
"->",
"routesCache",
"[",
"spl_object_hash",
"(",
"$",
"result",
")",
"]",
"[",
"$",
"filterName",
"]",
"=",
"$",
"route",
";",
"return",
"$",
"urlElements",
"[",
"'route'",
"]",
";",
"}"
] | Add filter into query.
@param Result $result
@param string $filterName
@param string $value
@return string | [
"Add",
"filter",
"into",
"query",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Url/UrlBuilder.php#L106-L151 |
apisearch-io/php-client | Url/UrlBuilder.php | UrlBuilder.removeFilterValue | public function removeFilterValue(
Result $result,
string $filterName,
string $value = null
): string {
$urlParameters = $this->generateQueryUrlParameters($result);
if (
is_null($value) ||
!isset($urlParameters[$filterName])
) {
unset($urlParameters[$filterName]);
} elseif (false !== ($key = array_search($value, $urlParameters[$filterName]))) {
unset($urlParameters[$filterName][$key]);
}
return $this->createUrlByUrlParameters(
$result,
$urlParameters
)['route'];
} | php | public function removeFilterValue(
Result $result,
string $filterName,
string $value = null
): string {
$urlParameters = $this->generateQueryUrlParameters($result);
if (
is_null($value) ||
!isset($urlParameters[$filterName])
) {
unset($urlParameters[$filterName]);
} elseif (false !== ($key = array_search($value, $urlParameters[$filterName]))) {
unset($urlParameters[$filterName][$key]);
}
return $this->createUrlByUrlParameters(
$result,
$urlParameters
)['route'];
} | [
"public",
"function",
"removeFilterValue",
"(",
"Result",
"$",
"result",
",",
"string",
"$",
"filterName",
",",
"string",
"$",
"value",
"=",
"null",
")",
":",
"string",
"{",
"$",
"urlParameters",
"=",
"$",
"this",
"->",
"generateQueryUrlParameters",
"(",
"$",
"result",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
"||",
"!",
"isset",
"(",
"$",
"urlParameters",
"[",
"$",
"filterName",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"urlParameters",
"[",
"$",
"filterName",
"]",
")",
";",
"}",
"elseif",
"(",
"false",
"!==",
"(",
"$",
"key",
"=",
"array_search",
"(",
"$",
"value",
",",
"$",
"urlParameters",
"[",
"$",
"filterName",
"]",
")",
")",
")",
"{",
"unset",
"(",
"$",
"urlParameters",
"[",
"$",
"filterName",
"]",
"[",
"$",
"key",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"createUrlByUrlParameters",
"(",
"$",
"result",
",",
"$",
"urlParameters",
")",
"[",
"'route'",
"]",
";",
"}"
] | Remove filter from query.
@param Result $result
@param string $filterName
@param string $value
@return string | [
"Remove",
"filter",
"from",
"query",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Url/UrlBuilder.php#L162-L182 |
apisearch-io/php-client | Url/UrlBuilder.php | UrlBuilder.removePriceRangeFilter | public function removePriceRangeFilter(Result $result): string
{
$urlParameters = $this->generateQueryUrlParameters($result);
unset($urlParameters['price']);
return $this->createUrlByUrlParameters(
$result,
$urlParameters
)['route'];
} | php | public function removePriceRangeFilter(Result $result): string
{
$urlParameters = $this->generateQueryUrlParameters($result);
unset($urlParameters['price']);
return $this->createUrlByUrlParameters(
$result,
$urlParameters
)['route'];
} | [
"public",
"function",
"removePriceRangeFilter",
"(",
"Result",
"$",
"result",
")",
":",
"string",
"{",
"$",
"urlParameters",
"=",
"$",
"this",
"->",
"generateQueryUrlParameters",
"(",
"$",
"result",
")",
";",
"unset",
"(",
"$",
"urlParameters",
"[",
"'price'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"createUrlByUrlParameters",
"(",
"$",
"result",
",",
"$",
"urlParameters",
")",
"[",
"'route'",
"]",
";",
"}"
] | Change price range.
@param Result $result
@return string | [
"Change",
"price",
"range",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Url/UrlBuilder.php#L191-L200 |
apisearch-io/php-client | Url/UrlBuilder.php | UrlBuilder.getCurrent | public function getCurrent(
Result $result,
bool $addQuersyStringPlaceholder = false
): ? string {
$urlParameters = $this->generateQueryUrlParameters($result);
if ($addQuersyStringPlaceholder) {
$urlParameters['q'] = '{{q}}';
}
return $this->createUrlByUrlParameters(
$result,
$urlParameters
)['route'];
} | php | public function getCurrent(
Result $result,
bool $addQuersyStringPlaceholder = false
): ? string {
$urlParameters = $this->generateQueryUrlParameters($result);
if ($addQuersyStringPlaceholder) {
$urlParameters['q'] = '{{q}}';
}
return $this->createUrlByUrlParameters(
$result,
$urlParameters
)['route'];
} | [
"public",
"function",
"getCurrent",
"(",
"Result",
"$",
"result",
",",
"bool",
"$",
"addQuersyStringPlaceholder",
"=",
"false",
")",
":",
"?",
"string",
"{",
"$",
"urlParameters",
"=",
"$",
"this",
"->",
"generateQueryUrlParameters",
"(",
"$",
"result",
")",
";",
"if",
"(",
"$",
"addQuersyStringPlaceholder",
")",
"{",
"$",
"urlParameters",
"[",
"'q'",
"]",
"=",
"'{{q}}'",
";",
"}",
"return",
"$",
"this",
"->",
"createUrlByUrlParameters",
"(",
"$",
"result",
",",
"$",
"urlParameters",
")",
"[",
"'route'",
"]",
";",
"}"
] | Get current.
@param Result $result
@param bool $addQuersyStringPlaceholder
@return string | [
"Get",
"current",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Url/UrlBuilder.php#L210-L223 |
apisearch-io/php-client | Url/UrlBuilder.php | UrlBuilder.addPage | public function addPage(
Result $result,
int $page
): string {
$urlParameters = $this->generateQueryUrlParameters($result);
$urlParameters['page'] = $page;
return $this->createUrlByUrlParameters(
$result,
$urlParameters
)['route'];
} | php | public function addPage(
Result $result,
int $page
): string {
$urlParameters = $this->generateQueryUrlParameters($result);
$urlParameters['page'] = $page;
return $this->createUrlByUrlParameters(
$result,
$urlParameters
)['route'];
} | [
"public",
"function",
"addPage",
"(",
"Result",
"$",
"result",
",",
"int",
"$",
"page",
")",
":",
"string",
"{",
"$",
"urlParameters",
"=",
"$",
"this",
"->",
"generateQueryUrlParameters",
"(",
"$",
"result",
")",
";",
"$",
"urlParameters",
"[",
"'page'",
"]",
"=",
"$",
"page",
";",
"return",
"$",
"this",
"->",
"createUrlByUrlParameters",
"(",
"$",
"result",
",",
"$",
"urlParameters",
")",
"[",
"'route'",
"]",
";",
"}"
] | Set pagination.
@param Result $result
@param int $page
@return string | [
"Set",
"pagination",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Url/UrlBuilder.php#L233-L244 |
apisearch-io/php-client | Url/UrlBuilder.php | UrlBuilder.addPrevPage | public function addPrevPage(Result $result): ? string
{
$query = $result->getQuery();
$urlParameters = $this->generateQueryUrlParameters($result);
$page = $query->getPage();
$prevPage = $page - 1;
if ($prevPage < 1) {
return null;
}
$urlParameters['page'] = $prevPage;
return $this->createUrlByUrlParameters(
$result,
$urlParameters
)['route'];
} | php | public function addPrevPage(Result $result): ? string
{
$query = $result->getQuery();
$urlParameters = $this->generateQueryUrlParameters($result);
$page = $query->getPage();
$prevPage = $page - 1;
if ($prevPage < 1) {
return null;
}
$urlParameters['page'] = $prevPage;
return $this->createUrlByUrlParameters(
$result,
$urlParameters
)['route'];
} | [
"public",
"function",
"addPrevPage",
"(",
"Result",
"$",
"result",
")",
":",
"?",
"string",
"{",
"$",
"query",
"=",
"$",
"result",
"->",
"getQuery",
"(",
")",
";",
"$",
"urlParameters",
"=",
"$",
"this",
"->",
"generateQueryUrlParameters",
"(",
"$",
"result",
")",
";",
"$",
"page",
"=",
"$",
"query",
"->",
"getPage",
"(",
")",
";",
"$",
"prevPage",
"=",
"$",
"page",
"-",
"1",
";",
"if",
"(",
"$",
"prevPage",
"<",
"1",
")",
"{",
"return",
"null",
";",
"}",
"$",
"urlParameters",
"[",
"'page'",
"]",
"=",
"$",
"prevPage",
";",
"return",
"$",
"this",
"->",
"createUrlByUrlParameters",
"(",
"$",
"result",
",",
"$",
"urlParameters",
")",
"[",
"'route'",
"]",
";",
"}"
] | Add previous page.
@param Result $result
@return string|null | [
"Add",
"previous",
"page",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Url/UrlBuilder.php#L253-L270 |
apisearch-io/php-client | Url/UrlBuilder.php | UrlBuilder.addNextPage | public function addNextPage(Result $result): ? string
{
$query = $result->getQuery();
$urlParameters = $this->generateQueryUrlParameters($result);
$page = $query->getPage();
$nextPage = $page + 1;
if ((($nextPage - 1) * $query->getSize()) > $result->getTotalHits()) {
return null;
}
$urlParameters['page'] = $nextPage;
return $this->createUrlByUrlParameters(
$result,
$urlParameters
)['route'];
} | php | public function addNextPage(Result $result): ? string
{
$query = $result->getQuery();
$urlParameters = $this->generateQueryUrlParameters($result);
$page = $query->getPage();
$nextPage = $page + 1;
if ((($nextPage - 1) * $query->getSize()) > $result->getTotalHits()) {
return null;
}
$urlParameters['page'] = $nextPage;
return $this->createUrlByUrlParameters(
$result,
$urlParameters
)['route'];
} | [
"public",
"function",
"addNextPage",
"(",
"Result",
"$",
"result",
")",
":",
"?",
"string",
"{",
"$",
"query",
"=",
"$",
"result",
"->",
"getQuery",
"(",
")",
";",
"$",
"urlParameters",
"=",
"$",
"this",
"->",
"generateQueryUrlParameters",
"(",
"$",
"result",
")",
";",
"$",
"page",
"=",
"$",
"query",
"->",
"getPage",
"(",
")",
";",
"$",
"nextPage",
"=",
"$",
"page",
"+",
"1",
";",
"if",
"(",
"(",
"(",
"$",
"nextPage",
"-",
"1",
")",
"*",
"$",
"query",
"->",
"getSize",
"(",
")",
")",
">",
"$",
"result",
"->",
"getTotalHits",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"urlParameters",
"[",
"'page'",
"]",
"=",
"$",
"nextPage",
";",
"return",
"$",
"this",
"->",
"createUrlByUrlParameters",
"(",
"$",
"result",
",",
"$",
"urlParameters",
")",
"[",
"'route'",
"]",
";",
"}"
] | Add next page.
@param Result $result
@return string|null | [
"Add",
"next",
"page",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Url/UrlBuilder.php#L279-L296 |
apisearch-io/php-client | Url/UrlBuilder.php | UrlBuilder.addSortBy | public function addSortBy(
Result $result,
string $field,
string $mode
): ? string {
$urlParameters = $this->generateQueryUrlParameters($result);
if (
isset($urlParameters['sort_by'][$field]) &&
$urlParameters['sort_by'][$field] == $mode
) {
return null;
}
if (
!isset($urlParameters['sort_by']) &&
SortBy::SCORE === [$field => $mode]
) {
return null;
}
unset($urlParameters['sort_by']);
if (SortBy::SCORE !== [$field => $mode]) {
$urlParameters['sort_by'][$field] = $mode;
}
return $this->createUrlByUrlParameters(
$result,
$urlParameters
)['route'];
} | php | public function addSortBy(
Result $result,
string $field,
string $mode
): ? string {
$urlParameters = $this->generateQueryUrlParameters($result);
if (
isset($urlParameters['sort_by'][$field]) &&
$urlParameters['sort_by'][$field] == $mode
) {
return null;
}
if (
!isset($urlParameters['sort_by']) &&
SortBy::SCORE === [$field => $mode]
) {
return null;
}
unset($urlParameters['sort_by']);
if (SortBy::SCORE !== [$field => $mode]) {
$urlParameters['sort_by'][$field] = $mode;
}
return $this->createUrlByUrlParameters(
$result,
$urlParameters
)['route'];
} | [
"public",
"function",
"addSortBy",
"(",
"Result",
"$",
"result",
",",
"string",
"$",
"field",
",",
"string",
"$",
"mode",
")",
":",
"?",
"string",
"{",
"$",
"urlParameters",
"=",
"$",
"this",
"->",
"generateQueryUrlParameters",
"(",
"$",
"result",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"urlParameters",
"[",
"'sort_by'",
"]",
"[",
"$",
"field",
"]",
")",
"&&",
"$",
"urlParameters",
"[",
"'sort_by'",
"]",
"[",
"$",
"field",
"]",
"==",
"$",
"mode",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"urlParameters",
"[",
"'sort_by'",
"]",
")",
"&&",
"SortBy",
"::",
"SCORE",
"===",
"[",
"$",
"field",
"=>",
"$",
"mode",
"]",
")",
"{",
"return",
"null",
";",
"}",
"unset",
"(",
"$",
"urlParameters",
"[",
"'sort_by'",
"]",
")",
";",
"if",
"(",
"SortBy",
"::",
"SCORE",
"!==",
"[",
"$",
"field",
"=>",
"$",
"mode",
"]",
")",
"{",
"$",
"urlParameters",
"[",
"'sort_by'",
"]",
"[",
"$",
"field",
"]",
"=",
"$",
"mode",
";",
"}",
"return",
"$",
"this",
"->",
"createUrlByUrlParameters",
"(",
"$",
"result",
",",
"$",
"urlParameters",
")",
"[",
"'route'",
"]",
";",
"}"
] | Add sort by. Return null if doesn't change.
@param Result $result
@param string $field
@param string $mode
@return string | [
"Add",
"sort",
"by",
".",
"Return",
"null",
"if",
"doesn",
"t",
"change",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Url/UrlBuilder.php#L307-L338 |
apisearch-io/php-client | Url/UrlBuilder.php | UrlBuilder.generateQueryUrlParameters | private function generateQueryUrlParameters(
Result $result,
string $filterName = null
): array {
$query = $result->getQuery();
$queryFilters = $query->getFilters();
$urlParameters = [];
foreach ($queryFilters as $currentFilterName => $filter) {
/*
* Special case for elements with LEVEL.
*/
$urlParameters[$currentFilterName] = (
!is_null($filterName) &&
$currentFilterName === $filterName &&
Filter::MUST_ALL_WITH_LEVELS === $filter->getApplicationType()
)
? []
: $filter->getValues();
}
unset($urlParameters['_query']);
$queryFilter = $query->getFilter('_query');
$queryString = $queryFilter instanceof Filter
? $queryFilter->getValues()[0]
: '';
if (!empty($queryString)) {
$urlParameters['q'] = $queryString;
}
$sort = $query->getSortBy();
if (SortBy::SCORE !== $sort) {
$urlParameters['sort_by'] = $sort;
}
return $urlParameters;
} | php | private function generateQueryUrlParameters(
Result $result,
string $filterName = null
): array {
$query = $result->getQuery();
$queryFilters = $query->getFilters();
$urlParameters = [];
foreach ($queryFilters as $currentFilterName => $filter) {
/*
* Special case for elements with LEVEL.
*/
$urlParameters[$currentFilterName] = (
!is_null($filterName) &&
$currentFilterName === $filterName &&
Filter::MUST_ALL_WITH_LEVELS === $filter->getApplicationType()
)
? []
: $filter->getValues();
}
unset($urlParameters['_query']);
$queryFilter = $query->getFilter('_query');
$queryString = $queryFilter instanceof Filter
? $queryFilter->getValues()[0]
: '';
if (!empty($queryString)) {
$urlParameters['q'] = $queryString;
}
$sort = $query->getSortBy();
if (SortBy::SCORE !== $sort) {
$urlParameters['sort_by'] = $sort;
}
return $urlParameters;
} | [
"private",
"function",
"generateQueryUrlParameters",
"(",
"Result",
"$",
"result",
",",
"string",
"$",
"filterName",
"=",
"null",
")",
":",
"array",
"{",
"$",
"query",
"=",
"$",
"result",
"->",
"getQuery",
"(",
")",
";",
"$",
"queryFilters",
"=",
"$",
"query",
"->",
"getFilters",
"(",
")",
";",
"$",
"urlParameters",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"queryFilters",
"as",
"$",
"currentFilterName",
"=>",
"$",
"filter",
")",
"{",
"/*\n * Special case for elements with LEVEL.\n */",
"$",
"urlParameters",
"[",
"$",
"currentFilterName",
"]",
"=",
"(",
"!",
"is_null",
"(",
"$",
"filterName",
")",
"&&",
"$",
"currentFilterName",
"===",
"$",
"filterName",
"&&",
"Filter",
"::",
"MUST_ALL_WITH_LEVELS",
"===",
"$",
"filter",
"->",
"getApplicationType",
"(",
")",
")",
"?",
"[",
"]",
":",
"$",
"filter",
"->",
"getValues",
"(",
")",
";",
"}",
"unset",
"(",
"$",
"urlParameters",
"[",
"'_query'",
"]",
")",
";",
"$",
"queryFilter",
"=",
"$",
"query",
"->",
"getFilter",
"(",
"'_query'",
")",
";",
"$",
"queryString",
"=",
"$",
"queryFilter",
"instanceof",
"Filter",
"?",
"$",
"queryFilter",
"->",
"getValues",
"(",
")",
"[",
"0",
"]",
":",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"queryString",
")",
")",
"{",
"$",
"urlParameters",
"[",
"'q'",
"]",
"=",
"$",
"queryString",
";",
"}",
"$",
"sort",
"=",
"$",
"query",
"->",
"getSortBy",
"(",
")",
";",
"if",
"(",
"SortBy",
"::",
"SCORE",
"!==",
"$",
"sort",
")",
"{",
"$",
"urlParameters",
"[",
"'sort_by'",
"]",
"=",
"$",
"sort",
";",
"}",
"return",
"$",
"urlParameters",
";",
"}"
] | Query to url parameters.
@param Result $result
@param string $filterName
@return array | [
"Query",
"to",
"url",
"parameters",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Url/UrlBuilder.php#L348-L385 |
apisearch-io/php-client | Url/UrlBuilder.php | UrlBuilder.createUrlByUrlParameters | private function createUrlByUrlParameters(
Result $result,
array $urlParameters
): array {
foreach ($this->routesDictionary as $field => $route) {
if (
!isset($urlParameters[$field]) ||
(
is_array($urlParameters[$field]) &&
1 !== count($urlParameters[$field])
)
) {
continue;
}
$value = is_array($urlParameters[$field])
? reset($urlParameters[$field])
: $urlParameters[$field];
if (!$result
->getAggregation($field)
->getAllElements()[$value] instanceof Counter) {
continue;
}
unset($urlParameters[$field]);
$path = $this
->router
->getRouteCollection()
->get($route)
->getPath();
preg_match_all(
'~\{(.+?)\}~',
$path,
$matches
);
return [
'route' => urldecode($this
->router
->generate(
$route,
array_merge(
array_intersect_key(
$result
->getAggregation($field)
->getAllElements()[$value]
->getValues(),
array_flip($matches[1])
),
$urlParameters
),
UrlGeneratorInterface::ABSOLUTE_URL
)),
'url_parameters' => $urlParameters,
'template_path' => $path,
'field' => $field,
];
}
return [
'route' => urldecode($this
->router
->generate(
$this->routesDictionary['main'],
$urlParameters,
UrlGeneratorInterface::ABSOLUTE_URL
)),
'url_parameters' => $urlParameters,
'template_path' => urldecode($this
->router
->generate(
$this->routesDictionary['main'],
[],
UrlGeneratorInterface::ABSOLUTE_URL
)
),
'field' => false,
];
} | php | private function createUrlByUrlParameters(
Result $result,
array $urlParameters
): array {
foreach ($this->routesDictionary as $field => $route) {
if (
!isset($urlParameters[$field]) ||
(
is_array($urlParameters[$field]) &&
1 !== count($urlParameters[$field])
)
) {
continue;
}
$value = is_array($urlParameters[$field])
? reset($urlParameters[$field])
: $urlParameters[$field];
if (!$result
->getAggregation($field)
->getAllElements()[$value] instanceof Counter) {
continue;
}
unset($urlParameters[$field]);
$path = $this
->router
->getRouteCollection()
->get($route)
->getPath();
preg_match_all(
'~\{(.+?)\}~',
$path,
$matches
);
return [
'route' => urldecode($this
->router
->generate(
$route,
array_merge(
array_intersect_key(
$result
->getAggregation($field)
->getAllElements()[$value]
->getValues(),
array_flip($matches[1])
),
$urlParameters
),
UrlGeneratorInterface::ABSOLUTE_URL
)),
'url_parameters' => $urlParameters,
'template_path' => $path,
'field' => $field,
];
}
return [
'route' => urldecode($this
->router
->generate(
$this->routesDictionary['main'],
$urlParameters,
UrlGeneratorInterface::ABSOLUTE_URL
)),
'url_parameters' => $urlParameters,
'template_path' => urldecode($this
->router
->generate(
$this->routesDictionary['main'],
[],
UrlGeneratorInterface::ABSOLUTE_URL
)
),
'field' => false,
];
} | [
"private",
"function",
"createUrlByUrlParameters",
"(",
"Result",
"$",
"result",
",",
"array",
"$",
"urlParameters",
")",
":",
"array",
"{",
"foreach",
"(",
"$",
"this",
"->",
"routesDictionary",
"as",
"$",
"field",
"=>",
"$",
"route",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"urlParameters",
"[",
"$",
"field",
"]",
")",
"||",
"(",
"is_array",
"(",
"$",
"urlParameters",
"[",
"$",
"field",
"]",
")",
"&&",
"1",
"!==",
"count",
"(",
"$",
"urlParameters",
"[",
"$",
"field",
"]",
")",
")",
")",
"{",
"continue",
";",
"}",
"$",
"value",
"=",
"is_array",
"(",
"$",
"urlParameters",
"[",
"$",
"field",
"]",
")",
"?",
"reset",
"(",
"$",
"urlParameters",
"[",
"$",
"field",
"]",
")",
":",
"$",
"urlParameters",
"[",
"$",
"field",
"]",
";",
"if",
"(",
"!",
"$",
"result",
"->",
"getAggregation",
"(",
"$",
"field",
")",
"->",
"getAllElements",
"(",
")",
"[",
"$",
"value",
"]",
"instanceof",
"Counter",
")",
"{",
"continue",
";",
"}",
"unset",
"(",
"$",
"urlParameters",
"[",
"$",
"field",
"]",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"router",
"->",
"getRouteCollection",
"(",
")",
"->",
"get",
"(",
"$",
"route",
")",
"->",
"getPath",
"(",
")",
";",
"preg_match_all",
"(",
"'~\\{(.+?)\\}~'",
",",
"$",
"path",
",",
"$",
"matches",
")",
";",
"return",
"[",
"'route'",
"=>",
"urldecode",
"(",
"$",
"this",
"->",
"router",
"->",
"generate",
"(",
"$",
"route",
",",
"array_merge",
"(",
"array_intersect_key",
"(",
"$",
"result",
"->",
"getAggregation",
"(",
"$",
"field",
")",
"->",
"getAllElements",
"(",
")",
"[",
"$",
"value",
"]",
"->",
"getValues",
"(",
")",
",",
"array_flip",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
")",
",",
"$",
"urlParameters",
")",
",",
"UrlGeneratorInterface",
"::",
"ABSOLUTE_URL",
")",
")",
",",
"'url_parameters'",
"=>",
"$",
"urlParameters",
",",
"'template_path'",
"=>",
"$",
"path",
",",
"'field'",
"=>",
"$",
"field",
",",
"]",
";",
"}",
"return",
"[",
"'route'",
"=>",
"urldecode",
"(",
"$",
"this",
"->",
"router",
"->",
"generate",
"(",
"$",
"this",
"->",
"routesDictionary",
"[",
"'main'",
"]",
",",
"$",
"urlParameters",
",",
"UrlGeneratorInterface",
"::",
"ABSOLUTE_URL",
")",
")",
",",
"'url_parameters'",
"=>",
"$",
"urlParameters",
",",
"'template_path'",
"=>",
"urldecode",
"(",
"$",
"this",
"->",
"router",
"->",
"generate",
"(",
"$",
"this",
"->",
"routesDictionary",
"[",
"'main'",
"]",
",",
"[",
"]",
",",
"UrlGeneratorInterface",
"::",
"ABSOLUTE_URL",
")",
")",
",",
"'field'",
"=>",
"false",
",",
"]",
";",
"}"
] | Generate url by query parameters.
Given a route dictionary, we should apply the first one encontered
@param Result $result
@param array $urlParameters
@return string[] | [
"Generate",
"url",
"by",
"query",
"parameters",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Url/UrlBuilder.php#L397-L476 |
apisearch-io/php-client | Model/Changes.php | Changes.addChange | public function addChange(
string $field,
$value,
int $type = self::TYPE_VALUE
): self {
$this->changes[] = [
'field' => $field,
'type' => $type,
'value' => $value,
];
return $this;
} | php | public function addChange(
string $field,
$value,
int $type = self::TYPE_VALUE
): self {
$this->changes[] = [
'field' => $field,
'type' => $type,
'value' => $value,
];
return $this;
} | [
"public",
"function",
"addChange",
"(",
"string",
"$",
"field",
",",
"$",
"value",
",",
"int",
"$",
"type",
"=",
"self",
"::",
"TYPE_VALUE",
")",
":",
"self",
"{",
"$",
"this",
"->",
"changes",
"[",
"]",
"=",
"[",
"'field'",
"=>",
"$",
"field",
",",
"'type'",
"=>",
"$",
"type",
",",
"'value'",
"=>",
"$",
"value",
",",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Add change.
@param string $field
@param mixed $value
@param int $type
@return Changes | [
"Add",
"change",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Model/Changes.php#L90-L102 |
apisearch-io/php-client | Model/Changes.php | Changes.updateElementFromList | public function updateElementFromList(
string $field,
string $condition,
$value,
int $type
): self {
$this->changes[] = [
'field' => $field,
'type' => $type | self::TYPE_ARRAY_ELEMENT_UPDATE,
'condition' => $condition,
'value' => $value,
];
return $this;
} | php | public function updateElementFromList(
string $field,
string $condition,
$value,
int $type
): self {
$this->changes[] = [
'field' => $field,
'type' => $type | self::TYPE_ARRAY_ELEMENT_UPDATE,
'condition' => $condition,
'value' => $value,
];
return $this;
} | [
"public",
"function",
"updateElementFromList",
"(",
"string",
"$",
"field",
",",
"string",
"$",
"condition",
",",
"$",
"value",
",",
"int",
"$",
"type",
")",
":",
"self",
"{",
"$",
"this",
"->",
"changes",
"[",
"]",
"=",
"[",
"'field'",
"=>",
"$",
"field",
",",
"'type'",
"=>",
"$",
"type",
"|",
"self",
"::",
"TYPE_ARRAY_ELEMENT_UPDATE",
",",
"'condition'",
"=>",
"$",
"condition",
",",
"'value'",
"=>",
"$",
"value",
",",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Add change inside a list.
@param string $field
@param string $condition
@param mixed $value
@param int $type
@return Changes | [
"Add",
"change",
"inside",
"a",
"list",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Model/Changes.php#L114-L128 |
apisearch-io/php-client | Model/Changes.php | Changes.addElementInList | public function addElementInList(
string $field,
$value,
int $type
): self {
$this->changes[] = [
'field' => $field,
'type' => $type | self::TYPE_ARRAY_ELEMENT_ADD,
'value' => $value,
];
return $this;
} | php | public function addElementInList(
string $field,
$value,
int $type
): self {
$this->changes[] = [
'field' => $field,
'type' => $type | self::TYPE_ARRAY_ELEMENT_ADD,
'value' => $value,
];
return $this;
} | [
"public",
"function",
"addElementInList",
"(",
"string",
"$",
"field",
",",
"$",
"value",
",",
"int",
"$",
"type",
")",
":",
"self",
"{",
"$",
"this",
"->",
"changes",
"[",
"]",
"=",
"[",
"'field'",
"=>",
"$",
"field",
",",
"'type'",
"=>",
"$",
"type",
"|",
"self",
"::",
"TYPE_ARRAY_ELEMENT_ADD",
",",
"'value'",
"=>",
"$",
"value",
",",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Add change inside a list.
@param string $field
@param mixed $value
@param int $type
@return Changes | [
"Add",
"change",
"inside",
"a",
"list",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Model/Changes.php#L139-L151 |
apisearch-io/php-client | Model/Changes.php | Changes.deleteElementFromList | public function deleteElementFromList(
string $field,
string $condition
): self {
$this->changes[] = [
'field' => $field,
'type' => self::TYPE_ARRAY_ELEMENT_DELETE,
'condition' => $condition,
];
return $this;
} | php | public function deleteElementFromList(
string $field,
string $condition
): self {
$this->changes[] = [
'field' => $field,
'type' => self::TYPE_ARRAY_ELEMENT_DELETE,
'condition' => $condition,
];
return $this;
} | [
"public",
"function",
"deleteElementFromList",
"(",
"string",
"$",
"field",
",",
"string",
"$",
"condition",
")",
":",
"self",
"{",
"$",
"this",
"->",
"changes",
"[",
"]",
"=",
"[",
"'field'",
"=>",
"$",
"field",
",",
"'type'",
"=>",
"self",
"::",
"TYPE_ARRAY_ELEMENT_DELETE",
",",
"'condition'",
"=>",
"$",
"condition",
",",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Delete change from a list.
@param string $field
@param string $condition
@return Changes | [
"Delete",
"change",
"from",
"a",
"list",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Model/Changes.php#L161-L172 |
apisearch-io/php-client | Query/ScoreStrategies.php | ScoreStrategies.createEmpty | public static function createEmpty(string $scoreMode = self::SUM): self
{
$scoreStrategies = new self();
$scoreStrategies->scoreMode = $scoreMode;
return $scoreStrategies;
} | php | public static function createEmpty(string $scoreMode = self::SUM): self
{
$scoreStrategies = new self();
$scoreStrategies->scoreMode = $scoreMode;
return $scoreStrategies;
} | [
"public",
"static",
"function",
"createEmpty",
"(",
"string",
"$",
"scoreMode",
"=",
"self",
"::",
"SUM",
")",
":",
"self",
"{",
"$",
"scoreStrategies",
"=",
"new",
"self",
"(",
")",
";",
"$",
"scoreStrategies",
"->",
"scoreMode",
"=",
"$",
"scoreMode",
";",
"return",
"$",
"scoreStrategies",
";",
"}"
] | Create empty.
@param string $scoreMode
@return self | [
"Create",
"empty",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/ScoreStrategies.php#L81-L87 |
apisearch-io/php-client | Query/ScoreStrategies.php | ScoreStrategies.toArray | public function toArray(): array
{
return [
'score_mode' => $this->scoreMode,
'score_strategies' => array_map(function (ScoreStrategy $scoreStrategy) {
return $scoreStrategy->toArray();
}, $this->scoreStrategies),
];
} | php | public function toArray(): array
{
return [
'score_mode' => $this->scoreMode,
'score_strategies' => array_map(function (ScoreStrategy $scoreStrategy) {
return $scoreStrategy->toArray();
}, $this->scoreStrategies),
];
} | [
"public",
"function",
"toArray",
"(",
")",
":",
"array",
"{",
"return",
"[",
"'score_mode'",
"=>",
"$",
"this",
"->",
"scoreMode",
",",
"'score_strategies'",
"=>",
"array_map",
"(",
"function",
"(",
"ScoreStrategy",
"$",
"scoreStrategy",
")",
"{",
"return",
"$",
"scoreStrategy",
"->",
"toArray",
"(",
")",
";",
"}",
",",
"$",
"this",
"->",
"scoreStrategies",
")",
",",
"]",
";",
"}"
] | To array.
@return array | [
"To",
"array",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/ScoreStrategies.php#L128-L136 |
apisearch-io/php-client | Query/ScoreStrategies.php | ScoreStrategies.createFromArray | public static function createFromArray(array $array)
{
$scoreStrategies = new self();
$scoreStrategies->scoreMode = $array['score_mode'] ?: self::SUM;
$scoreStrategies->scoreStrategies = array_map(function (array $scoreStrategy) {
return ScoreStrategy::createFromArray($scoreStrategy);
}, $array['score_strategies']);
return $scoreStrategies;
} | php | public static function createFromArray(array $array)
{
$scoreStrategies = new self();
$scoreStrategies->scoreMode = $array['score_mode'] ?: self::SUM;
$scoreStrategies->scoreStrategies = array_map(function (array $scoreStrategy) {
return ScoreStrategy::createFromArray($scoreStrategy);
}, $array['score_strategies']);
return $scoreStrategies;
} | [
"public",
"static",
"function",
"createFromArray",
"(",
"array",
"$",
"array",
")",
"{",
"$",
"scoreStrategies",
"=",
"new",
"self",
"(",
")",
";",
"$",
"scoreStrategies",
"->",
"scoreMode",
"=",
"$",
"array",
"[",
"'score_mode'",
"]",
"?",
":",
"self",
"::",
"SUM",
";",
"$",
"scoreStrategies",
"->",
"scoreStrategies",
"=",
"array_map",
"(",
"function",
"(",
"array",
"$",
"scoreStrategy",
")",
"{",
"return",
"ScoreStrategy",
"::",
"createFromArray",
"(",
"$",
"scoreStrategy",
")",
";",
"}",
",",
"$",
"array",
"[",
"'score_strategies'",
"]",
")",
";",
"return",
"$",
"scoreStrategies",
";",
"}"
] | Create from array.
@param array $array
@return self | [
"Create",
"from",
"array",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/ScoreStrategies.php#L145-L154 |
apisearch-io/php-client | User/Interaction.php | Interaction.toArray | public function toArray(): array
{
return array_filter([
'user' => $this->user->toArray(),
'item_uuid' => $this->itemUUID->toArray(),
'event_name' => $this->eventName,
'metadata' => $this->metadata,
]);
} | php | public function toArray(): array
{
return array_filter([
'user' => $this->user->toArray(),
'item_uuid' => $this->itemUUID->toArray(),
'event_name' => $this->eventName,
'metadata' => $this->metadata,
]);
} | [
"public",
"function",
"toArray",
"(",
")",
":",
"array",
"{",
"return",
"array_filter",
"(",
"[",
"'user'",
"=>",
"$",
"this",
"->",
"user",
"->",
"toArray",
"(",
")",
",",
"'item_uuid'",
"=>",
"$",
"this",
"->",
"itemUUID",
"->",
"toArray",
"(",
")",
",",
"'event_name'",
"=>",
"$",
"this",
"->",
"eventName",
",",
"'metadata'",
"=>",
"$",
"this",
"->",
"metadata",
",",
"]",
")",
";",
"}"
] | To array.
@return array | [
"To",
"array",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/User/Interaction.php#L121-L129 |
apisearch-io/php-client | App/DiskAppRepository.php | DiskAppRepository.deleteIndex | public function deleteIndex(IndexUUID $indexUUID)
{
$this->load();
parent::deleteIndex($indexUUID);
$this->save();
} | php | public function deleteIndex(IndexUUID $indexUUID)
{
$this->load();
parent::deleteIndex($indexUUID);
$this->save();
} | [
"public",
"function",
"deleteIndex",
"(",
"IndexUUID",
"$",
"indexUUID",
")",
"{",
"$",
"this",
"->",
"load",
"(",
")",
";",
"parent",
"::",
"deleteIndex",
"(",
"$",
"indexUUID",
")",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}"
] | Delete an index.
@param IndexUUID $indexUUID | [
"Delete",
"an",
"index",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/App/DiskAppRepository.php#L85-L90 |
apisearch-io/php-client | App/DiskAppRepository.php | DiskAppRepository.resetIndex | public function resetIndex(IndexUUID $indexUUID)
{
$this->load();
parent::resetIndex($indexUUID);
$this->save();
} | php | public function resetIndex(IndexUUID $indexUUID)
{
$this->load();
parent::resetIndex($indexUUID);
$this->save();
} | [
"public",
"function",
"resetIndex",
"(",
"IndexUUID",
"$",
"indexUUID",
")",
"{",
"$",
"this",
"->",
"load",
"(",
")",
";",
"parent",
"::",
"resetIndex",
"(",
"$",
"indexUUID",
")",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}"
] | Reset the index.
@param IndexUUID $indexUUID | [
"Reset",
"the",
"index",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/App/DiskAppRepository.php#L97-L102 |
apisearch-io/php-client | App/DiskAppRepository.php | DiskAppRepository.configureIndex | public function configureIndex(
IndexUUID $indexUUID,
Config $config
) {
$this->load();
parent::configureIndex(
$indexUUID,
$config
);
$this->save();
} | php | public function configureIndex(
IndexUUID $indexUUID,
Config $config
) {
$this->load();
parent::configureIndex(
$indexUUID,
$config
);
$this->save();
} | [
"public",
"function",
"configureIndex",
"(",
"IndexUUID",
"$",
"indexUUID",
",",
"Config",
"$",
"config",
")",
"{",
"$",
"this",
"->",
"load",
"(",
")",
";",
"parent",
"::",
"configureIndex",
"(",
"$",
"indexUUID",
",",
"$",
"config",
")",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}"
] | Config the index.
@param IndexUUID $indexUUID
@param Config $config
@throws ResourceNotAvailableException | [
"Config",
"the",
"index",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/App/DiskAppRepository.php#L126-L136 |
apisearch-io/php-client | App/DiskAppRepository.php | DiskAppRepository.addToken | public function addToken(Token $token)
{
$this->load();
parent::addToken($token);
$this->save();
} | php | public function addToken(Token $token)
{
$this->load();
parent::addToken($token);
$this->save();
} | [
"public",
"function",
"addToken",
"(",
"Token",
"$",
"token",
")",
"{",
"$",
"this",
"->",
"load",
"(",
")",
";",
"parent",
"::",
"addToken",
"(",
"$",
"token",
")",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}"
] | Add token.
@param Token $token | [
"Add",
"token",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/App/DiskAppRepository.php#L143-L148 |
apisearch-io/php-client | App/DiskAppRepository.php | DiskAppRepository.deleteToken | public function deleteToken(TokenUUID $tokenUUID)
{
$this->load();
parent::deleteToken($tokenUUID);
$this->save();
} | php | public function deleteToken(TokenUUID $tokenUUID)
{
$this->load();
parent::deleteToken($tokenUUID);
$this->save();
} | [
"public",
"function",
"deleteToken",
"(",
"TokenUUID",
"$",
"tokenUUID",
")",
"{",
"$",
"this",
"->",
"load",
"(",
")",
";",
"parent",
"::",
"deleteToken",
"(",
"$",
"tokenUUID",
")",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}"
] | Delete token.
@param TokenUUID $tokenUUID | [
"Delete",
"token",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/App/DiskAppRepository.php#L155-L160 |
apisearch-io/php-client | App/DiskAppRepository.php | DiskAppRepository.load | private function load()
{
if (!file_exists($this->filename)) {
return;
}
list($tokens, $indices) = unserialize(
file_get_contents(
$this->filename
)
);
$this->tokens = $tokens ?? [];
$this->indices = $indices ?? [];
} | php | private function load()
{
if (!file_exists($this->filename)) {
return;
}
list($tokens, $indices) = unserialize(
file_get_contents(
$this->filename
)
);
$this->tokens = $tokens ?? [];
$this->indices = $indices ?? [];
} | [
"private",
"function",
"load",
"(",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"filename",
")",
")",
"{",
"return",
";",
"}",
"list",
"(",
"$",
"tokens",
",",
"$",
"indices",
")",
"=",
"unserialize",
"(",
"file_get_contents",
"(",
"$",
"this",
"->",
"filename",
")",
")",
";",
"$",
"this",
"->",
"tokens",
"=",
"$",
"tokens",
"??",
"[",
"]",
";",
"$",
"this",
"->",
"indices",
"=",
"$",
"indices",
"??",
"[",
"]",
";",
"}"
] | Load. | [
"Load",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/App/DiskAppRepository.php#L187-L201 |
apisearch-io/php-client | App/DiskAppRepository.php | DiskAppRepository.save | private function save()
{
file_put_contents(
$this->filename,
serialize([
$this->tokens,
$this->indices,
])
);
$this->tokens = [];
$this->indices = [];
} | php | private function save()
{
file_put_contents(
$this->filename,
serialize([
$this->tokens,
$this->indices,
])
);
$this->tokens = [];
$this->indices = [];
} | [
"private",
"function",
"save",
"(",
")",
"{",
"file_put_contents",
"(",
"$",
"this",
"->",
"filename",
",",
"serialize",
"(",
"[",
"$",
"this",
"->",
"tokens",
",",
"$",
"this",
"->",
"indices",
",",
"]",
")",
")",
";",
"$",
"this",
"->",
"tokens",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"indices",
"=",
"[",
"]",
";",
"}"
] | Save. | [
"Save",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/App/DiskAppRepository.php#L206-L217 |
apisearch-io/php-client | App/InMemoryAppRepository.php | InMemoryAppRepository.getIndices | public function getIndices(): array
{
$appId = $this->getAppKey();
$result = [];
foreach ($this->indices as $index => $_) {
if (false !== preg_match("/(?P<app_id>[^_]+)\_(?P<id>[\S]+)/", $index, $matches)) {
if (!empty($appId) && $matches['app_id'] !== $appId) {
continue;
}
$indexMeta = [
'uuid' => ['id' => $matches['id']],
'app_id' => ['id' => $matches['app_id']],
'doc_count' => 0,
];
$result[] = Index::createFromArray($indexMeta);
}
}
return $result;
} | php | public function getIndices(): array
{
$appId = $this->getAppKey();
$result = [];
foreach ($this->indices as $index => $_) {
if (false !== preg_match("/(?P<app_id>[^_]+)\_(?P<id>[\S]+)/", $index, $matches)) {
if (!empty($appId) && $matches['app_id'] !== $appId) {
continue;
}
$indexMeta = [
'uuid' => ['id' => $matches['id']],
'app_id' => ['id' => $matches['app_id']],
'doc_count' => 0,
];
$result[] = Index::createFromArray($indexMeta);
}
}
return $result;
} | [
"public",
"function",
"getIndices",
"(",
")",
":",
"array",
"{",
"$",
"appId",
"=",
"$",
"this",
"->",
"getAppKey",
"(",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"indices",
"as",
"$",
"index",
"=>",
"$",
"_",
")",
"{",
"if",
"(",
"false",
"!==",
"preg_match",
"(",
"\"/(?P<app_id>[^_]+)\\_(?P<id>[\\S]+)/\"",
",",
"$",
"index",
",",
"$",
"matches",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"appId",
")",
"&&",
"$",
"matches",
"[",
"'app_id'",
"]",
"!==",
"$",
"appId",
")",
"{",
"continue",
";",
"}",
"$",
"indexMeta",
"=",
"[",
"'uuid'",
"=>",
"[",
"'id'",
"=>",
"$",
"matches",
"[",
"'id'",
"]",
"]",
",",
"'app_id'",
"=>",
"[",
"'id'",
"=>",
"$",
"matches",
"[",
"'app_id'",
"]",
"]",
",",
"'doc_count'",
"=>",
"0",
",",
"]",
";",
"$",
"result",
"[",
"]",
"=",
"Index",
"::",
"createFromArray",
"(",
"$",
"indexMeta",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Get indices.
@return Index[] | [
"Get",
"indices",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/App/InMemoryAppRepository.php#L52-L74 |
apisearch-io/php-client | App/InMemoryAppRepository.php | InMemoryAppRepository.createIndex | public function createIndex(
IndexUUID $indexUUID,
Config $config
) {
if (array_key_exists($this->getIndexKey($indexUUID), $this->indices)) {
throw ResourceExistsException::indexExists();
}
$this->indices[$this->getIndexKey($indexUUID)] = [
'config' => $config,
'was_reset' => false,
'was_reconfigured' => false,
];
} | php | public function createIndex(
IndexUUID $indexUUID,
Config $config
) {
if (array_key_exists($this->getIndexKey($indexUUID), $this->indices)) {
throw ResourceExistsException::indexExists();
}
$this->indices[$this->getIndexKey($indexUUID)] = [
'config' => $config,
'was_reset' => false,
'was_reconfigured' => false,
];
} | [
"public",
"function",
"createIndex",
"(",
"IndexUUID",
"$",
"indexUUID",
",",
"Config",
"$",
"config",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"this",
"->",
"getIndexKey",
"(",
"$",
"indexUUID",
")",
",",
"$",
"this",
"->",
"indices",
")",
")",
"{",
"throw",
"ResourceExistsException",
"::",
"indexExists",
"(",
")",
";",
"}",
"$",
"this",
"->",
"indices",
"[",
"$",
"this",
"->",
"getIndexKey",
"(",
"$",
"indexUUID",
")",
"]",
"=",
"[",
"'config'",
"=>",
"$",
"config",
",",
"'was_reset'",
"=>",
"false",
",",
"'was_reconfigured'",
"=>",
"false",
",",
"]",
";",
"}"
] | Create an index.
@param IndexUUID $indexUUID
@param Config $config
@throws ResourceExistsException | [
"Create",
"an",
"index",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/App/InMemoryAppRepository.php#L84-L97 |
apisearch-io/php-client | App/InMemoryAppRepository.php | InMemoryAppRepository.deleteIndex | public function deleteIndex(IndexUUID $indexUUID)
{
if (!array_key_exists($this->getIndexKey($indexUUID), $this->indices)) {
throw ResourceNotAvailableException::indexNotAvailable('Index not available in InMemoryRepository');
}
unset($this->indices[$this->getIndexKey($indexUUID)]);
} | php | public function deleteIndex(IndexUUID $indexUUID)
{
if (!array_key_exists($this->getIndexKey($indexUUID), $this->indices)) {
throw ResourceNotAvailableException::indexNotAvailable('Index not available in InMemoryRepository');
}
unset($this->indices[$this->getIndexKey($indexUUID)]);
} | [
"public",
"function",
"deleteIndex",
"(",
"IndexUUID",
"$",
"indexUUID",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"this",
"->",
"getIndexKey",
"(",
"$",
"indexUUID",
")",
",",
"$",
"this",
"->",
"indices",
")",
")",
"{",
"throw",
"ResourceNotAvailableException",
"::",
"indexNotAvailable",
"(",
"'Index not available in InMemoryRepository'",
")",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"indices",
"[",
"$",
"this",
"->",
"getIndexKey",
"(",
"$",
"indexUUID",
")",
"]",
")",
";",
"}"
] | Delete an index.
@param IndexUUID $indexUUID | [
"Delete",
"an",
"index",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/App/InMemoryAppRepository.php#L104-L111 |
apisearch-io/php-client | App/InMemoryAppRepository.php | InMemoryAppRepository.resetIndex | public function resetIndex(IndexUUID $indexUUID)
{
if (!array_key_exists($this->getIndexKey($indexUUID), $this->indices)) {
throw ResourceNotAvailableException::indexNotAvailable('Index not available in InMemoryRepository');
}
$this->indices[$this->getIndexKey($indexUUID)]['was_reset'] = true;
} | php | public function resetIndex(IndexUUID $indexUUID)
{
if (!array_key_exists($this->getIndexKey($indexUUID), $this->indices)) {
throw ResourceNotAvailableException::indexNotAvailable('Index not available in InMemoryRepository');
}
$this->indices[$this->getIndexKey($indexUUID)]['was_reset'] = true;
} | [
"public",
"function",
"resetIndex",
"(",
"IndexUUID",
"$",
"indexUUID",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"this",
"->",
"getIndexKey",
"(",
"$",
"indexUUID",
")",
",",
"$",
"this",
"->",
"indices",
")",
")",
"{",
"throw",
"ResourceNotAvailableException",
"::",
"indexNotAvailable",
"(",
"'Index not available in InMemoryRepository'",
")",
";",
"}",
"$",
"this",
"->",
"indices",
"[",
"$",
"this",
"->",
"getIndexKey",
"(",
"$",
"indexUUID",
")",
"]",
"[",
"'was_reset'",
"]",
"=",
"true",
";",
"}"
] | Reset the index.
@param IndexUUID $indexUUID | [
"Reset",
"the",
"index",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/App/InMemoryAppRepository.php#L118-L125 |
apisearch-io/php-client | App/InMemoryAppRepository.php | InMemoryAppRepository.checkIndex | public function checkIndex(IndexUUID $indexUUID): bool
{
return array_key_exists($this->getIndexKey($indexUUID), $this->indices);
} | php | public function checkIndex(IndexUUID $indexUUID): bool
{
return array_key_exists($this->getIndexKey($indexUUID), $this->indices);
} | [
"public",
"function",
"checkIndex",
"(",
"IndexUUID",
"$",
"indexUUID",
")",
":",
"bool",
"{",
"return",
"array_key_exists",
"(",
"$",
"this",
"->",
"getIndexKey",
"(",
"$",
"indexUUID",
")",
",",
"$",
"this",
"->",
"indices",
")",
";",
"}"
] | Checks the index.
@param IndexUUID $indexUUID
@return bool | [
"Checks",
"the",
"index",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/App/InMemoryAppRepository.php#L134-L137 |
apisearch-io/php-client | App/InMemoryAppRepository.php | InMemoryAppRepository.configureIndex | public function configureIndex(
IndexUUID $indexUUID,
Config $config
) {
if (!array_key_exists($this->getIndexKey($indexUUID), $this->indices)) {
throw ResourceNotAvailableException::indexNotAvailable('Index not available in InMemoryRepository');
}
$this->indices[$this->getIndexKey($indexUUID)]['was_reconfigured'] = true;
} | php | public function configureIndex(
IndexUUID $indexUUID,
Config $config
) {
if (!array_key_exists($this->getIndexKey($indexUUID), $this->indices)) {
throw ResourceNotAvailableException::indexNotAvailable('Index not available in InMemoryRepository');
}
$this->indices[$this->getIndexKey($indexUUID)]['was_reconfigured'] = true;
} | [
"public",
"function",
"configureIndex",
"(",
"IndexUUID",
"$",
"indexUUID",
",",
"Config",
"$",
"config",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"this",
"->",
"getIndexKey",
"(",
"$",
"indexUUID",
")",
",",
"$",
"this",
"->",
"indices",
")",
")",
"{",
"throw",
"ResourceNotAvailableException",
"::",
"indexNotAvailable",
"(",
"'Index not available in InMemoryRepository'",
")",
";",
"}",
"$",
"this",
"->",
"indices",
"[",
"$",
"this",
"->",
"getIndexKey",
"(",
"$",
"indexUUID",
")",
"]",
"[",
"'was_reconfigured'",
"]",
"=",
"true",
";",
"}"
] | Config the index.
@param IndexUUID $indexUUID
@param Config $config
@throws ResourceNotAvailableException | [
"Config",
"the",
"index",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/App/InMemoryAppRepository.php#L147-L156 |
apisearch-io/php-client | App/InMemoryAppRepository.php | InMemoryAppRepository.addToken | public function addToken(Token $token)
{
$this->tokens[$this->getAppKey()][$token->getTokenUUID()->composeUUID()] = $token;
} | php | public function addToken(Token $token)
{
$this->tokens[$this->getAppKey()][$token->getTokenUUID()->composeUUID()] = $token;
} | [
"public",
"function",
"addToken",
"(",
"Token",
"$",
"token",
")",
"{",
"$",
"this",
"->",
"tokens",
"[",
"$",
"this",
"->",
"getAppKey",
"(",
")",
"]",
"[",
"$",
"token",
"->",
"getTokenUUID",
"(",
")",
"->",
"composeUUID",
"(",
")",
"]",
"=",
"$",
"token",
";",
"}"
] | Add token.
@param Token $token | [
"Add",
"token",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/App/InMemoryAppRepository.php#L163-L166 |
apisearch-io/php-client | App/InMemoryAppRepository.php | InMemoryAppRepository.getAppKey | private function getAppKey(): string
{
$appUUID = $this
->getRepositoryReference()
->getAppUUID();
return $appUUID instanceof AppUUID
? $appUUID->getId()
: '';
} | php | private function getAppKey(): string
{
$appUUID = $this
->getRepositoryReference()
->getAppUUID();
return $appUUID instanceof AppUUID
? $appUUID->getId()
: '';
} | [
"private",
"function",
"getAppKey",
"(",
")",
":",
"string",
"{",
"$",
"appUUID",
"=",
"$",
"this",
"->",
"getRepositoryReference",
"(",
")",
"->",
"getAppUUID",
"(",
")",
";",
"return",
"$",
"appUUID",
"instanceof",
"AppUUID",
"?",
"$",
"appUUID",
"->",
"getId",
"(",
")",
":",
"''",
";",
"}"
] | Get app position by credentials.
@return string | [
"Get",
"app",
"position",
"by",
"credentials",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/App/InMemoryAppRepository.php#L213-L222 |
apisearch-io/php-client | Repository/InMemoryRepository.php | InMemoryRepository.query | public function query(
Query $query,
array $parameters = []
): Result {
$resultingItems = $this->items[$this->getIndexKey()] ?? [];
if (!empty($query->getFilters())) {
foreach ($query->getFilters() as $filter) {
if (Filter::TYPE_QUERY === $filter->getFilterType() && $filter->getValues() === ['']) {
continue;
}
if ('_id' !== $filter->getField()) {
throw new LogicException('Queries by field different than UUID not allowed in InMemoryRepository. Only for testing purposes.');
}
$resultingItems = [];
$itemUUIDs = $filter->getValues();
foreach ($itemUUIDs as $itemUUID) {
$resultingItems[$itemUUID] = $this->items[$this->getIndexKey()][$itemUUID] ?? null;
}
}
}
$resultingItems = array_values(
array_slice(
array_filter($resultingItems),
$query->getFrom(),
$query->getSize()
)
);
$items = $this->items[$this->getIndexKey()] ?? [];
$result = new Result($query->getUUID(), count($items), count($resultingItems));
foreach ($resultingItems as $resultingItem) {
$result->addItem($resultingItem);
}
return $result;
} | php | public function query(
Query $query,
array $parameters = []
): Result {
$resultingItems = $this->items[$this->getIndexKey()] ?? [];
if (!empty($query->getFilters())) {
foreach ($query->getFilters() as $filter) {
if (Filter::TYPE_QUERY === $filter->getFilterType() && $filter->getValues() === ['']) {
continue;
}
if ('_id' !== $filter->getField()) {
throw new LogicException('Queries by field different than UUID not allowed in InMemoryRepository. Only for testing purposes.');
}
$resultingItems = [];
$itemUUIDs = $filter->getValues();
foreach ($itemUUIDs as $itemUUID) {
$resultingItems[$itemUUID] = $this->items[$this->getIndexKey()][$itemUUID] ?? null;
}
}
}
$resultingItems = array_values(
array_slice(
array_filter($resultingItems),
$query->getFrom(),
$query->getSize()
)
);
$items = $this->items[$this->getIndexKey()] ?? [];
$result = new Result($query->getUUID(), count($items), count($resultingItems));
foreach ($resultingItems as $resultingItem) {
$result->addItem($resultingItem);
}
return $result;
} | [
"public",
"function",
"query",
"(",
"Query",
"$",
"query",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
":",
"Result",
"{",
"$",
"resultingItems",
"=",
"$",
"this",
"->",
"items",
"[",
"$",
"this",
"->",
"getIndexKey",
"(",
")",
"]",
"??",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"query",
"->",
"getFilters",
"(",
")",
")",
")",
"{",
"foreach",
"(",
"$",
"query",
"->",
"getFilters",
"(",
")",
"as",
"$",
"filter",
")",
"{",
"if",
"(",
"Filter",
"::",
"TYPE_QUERY",
"===",
"$",
"filter",
"->",
"getFilterType",
"(",
")",
"&&",
"$",
"filter",
"->",
"getValues",
"(",
")",
"===",
"[",
"''",
"]",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"'_id'",
"!==",
"$",
"filter",
"->",
"getField",
"(",
")",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"'Queries by field different than UUID not allowed in InMemoryRepository. Only for testing purposes.'",
")",
";",
"}",
"$",
"resultingItems",
"=",
"[",
"]",
";",
"$",
"itemUUIDs",
"=",
"$",
"filter",
"->",
"getValues",
"(",
")",
";",
"foreach",
"(",
"$",
"itemUUIDs",
"as",
"$",
"itemUUID",
")",
"{",
"$",
"resultingItems",
"[",
"$",
"itemUUID",
"]",
"=",
"$",
"this",
"->",
"items",
"[",
"$",
"this",
"->",
"getIndexKey",
"(",
")",
"]",
"[",
"$",
"itemUUID",
"]",
"??",
"null",
";",
"}",
"}",
"}",
"$",
"resultingItems",
"=",
"array_values",
"(",
"array_slice",
"(",
"array_filter",
"(",
"$",
"resultingItems",
")",
",",
"$",
"query",
"->",
"getFrom",
"(",
")",
",",
"$",
"query",
"->",
"getSize",
"(",
")",
")",
")",
";",
"$",
"items",
"=",
"$",
"this",
"->",
"items",
"[",
"$",
"this",
"->",
"getIndexKey",
"(",
")",
"]",
"??",
"[",
"]",
";",
"$",
"result",
"=",
"new",
"Result",
"(",
"$",
"query",
"->",
"getUUID",
"(",
")",
",",
"count",
"(",
"$",
"items",
")",
",",
"count",
"(",
"$",
"resultingItems",
")",
")",
";",
"foreach",
"(",
"$",
"resultingItems",
"as",
"$",
"resultingItem",
")",
"{",
"$",
"result",
"->",
"addItem",
"(",
"$",
"resultingItem",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Search across the index types.
@param Query $query
@param array $parameters
@return Result | [
"Search",
"across",
"the",
"index",
"types",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Repository/InMemoryRepository.php#L46-L85 |
apisearch-io/php-client | Repository/InMemoryRepository.php | InMemoryRepository.flushItems | protected function flushItems(
array $itemsToUpdate,
array $itemsToDelete
) {
foreach ($itemsToUpdate as $itemToUpdate) {
$this->items[$this->getIndexKey()][$itemToUpdate->getUUID()->composeUUID()] = $itemToUpdate;
}
foreach ($itemsToDelete as $itemToDelete) {
unset($this->items[$this->getIndexKey()][$itemToDelete->composeUUID()]);
}
} | php | protected function flushItems(
array $itemsToUpdate,
array $itemsToDelete
) {
foreach ($itemsToUpdate as $itemToUpdate) {
$this->items[$this->getIndexKey()][$itemToUpdate->getUUID()->composeUUID()] = $itemToUpdate;
}
foreach ($itemsToDelete as $itemToDelete) {
unset($this->items[$this->getIndexKey()][$itemToDelete->composeUUID()]);
}
} | [
"protected",
"function",
"flushItems",
"(",
"array",
"$",
"itemsToUpdate",
",",
"array",
"$",
"itemsToDelete",
")",
"{",
"foreach",
"(",
"$",
"itemsToUpdate",
"as",
"$",
"itemToUpdate",
")",
"{",
"$",
"this",
"->",
"items",
"[",
"$",
"this",
"->",
"getIndexKey",
"(",
")",
"]",
"[",
"$",
"itemToUpdate",
"->",
"getUUID",
"(",
")",
"->",
"composeUUID",
"(",
")",
"]",
"=",
"$",
"itemToUpdate",
";",
"}",
"foreach",
"(",
"$",
"itemsToDelete",
"as",
"$",
"itemToDelete",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"this",
"->",
"getIndexKey",
"(",
")",
"]",
"[",
"$",
"itemToDelete",
"->",
"composeUUID",
"(",
")",
"]",
")",
";",
"}",
"}"
] | Flush items.
@param Item[] $itemsToUpdate
@param ItemUUID[] $itemsToDelete | [
"Flush",
"items",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Repository/InMemoryRepository.php#L116-L127 |
apisearch-io/php-client | Model/ItemUUID.php | ItemUUID.createByComposedUUID | public static function createByComposedUUID(string $composedUUID): self
{
$parts = explode('~', $composedUUID);
if (2 !== count($parts)) {
throw InvalidFormatException::composedItemUUIDNotValid($composedUUID);
}
return new self($parts[0], $parts[1]);
} | php | public static function createByComposedUUID(string $composedUUID): self
{
$parts = explode('~', $composedUUID);
if (2 !== count($parts)) {
throw InvalidFormatException::composedItemUUIDNotValid($composedUUID);
}
return new self($parts[0], $parts[1]);
} | [
"public",
"static",
"function",
"createByComposedUUID",
"(",
"string",
"$",
"composedUUID",
")",
":",
"self",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'~'",
",",
"$",
"composedUUID",
")",
";",
"if",
"(",
"2",
"!==",
"count",
"(",
"$",
"parts",
")",
")",
"{",
"throw",
"InvalidFormatException",
"::",
"composedItemUUIDNotValid",
"(",
"$",
"composedUUID",
")",
";",
"}",
"return",
"new",
"self",
"(",
"$",
"parts",
"[",
"0",
"]",
",",
"$",
"parts",
"[",
"1",
"]",
")",
";",
"}"
] | Create by composed uuid.
@param string $composedUUID
@return ItemUUID
@throws InvalidFormatException | [
"Create",
"by",
"composed",
"uuid",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Model/ItemUUID.php#L62-L70 |
apisearch-io/php-client | Http/RetryMap.php | RetryMap.addRetry | public function addRetry(Retry $retry)
{
$this->retries[$retry->getUrl().'~~'.$retry->getMethod()] = $retry;
} | php | public function addRetry(Retry $retry)
{
$this->retries[$retry->getUrl().'~~'.$retry->getMethod()] = $retry;
} | [
"public",
"function",
"addRetry",
"(",
"Retry",
"$",
"retry",
")",
"{",
"$",
"this",
"->",
"retries",
"[",
"$",
"retry",
"->",
"getUrl",
"(",
")",
".",
"'~~'",
".",
"$",
"retry",
"->",
"getMethod",
"(",
")",
"]",
"=",
"$",
"retry",
";",
"}"
] | Add retry.
@param Retry $retry | [
"Add",
"retry",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Http/RetryMap.php#L35-L38 |
apisearch-io/php-client | Http/RetryMap.php | RetryMap.createFromArray | public static function createFromArray(array $data): RetryMap
{
$retryMap = new RetryMap();
foreach ($data as $entry) {
$retryMap->addRetry(Retry::createFromArray($entry));
}
return $retryMap;
} | php | public static function createFromArray(array $data): RetryMap
{
$retryMap = new RetryMap();
foreach ($data as $entry) {
$retryMap->addRetry(Retry::createFromArray($entry));
}
return $retryMap;
} | [
"public",
"static",
"function",
"createFromArray",
"(",
"array",
"$",
"data",
")",
":",
"RetryMap",
"{",
"$",
"retryMap",
"=",
"new",
"RetryMap",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"entry",
")",
"{",
"$",
"retryMap",
"->",
"addRetry",
"(",
"Retry",
"::",
"createFromArray",
"(",
"$",
"entry",
")",
")",
";",
"}",
"return",
"$",
"retryMap",
";",
"}"
] | Create from array.
@param array $data
@return RetryMap | [
"Create",
"from",
"array",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Http/RetryMap.php#L47-L55 |
apisearch-io/php-client | Http/RetryMap.php | RetryMap.getRetry | public function getRetry(
string $url,
string $method
): ? Retry {
$url = trim(trim(strtolower($url)), '/');
$method = trim(strtolower($method));
if (isset($this->retries[$url.'~~'.$method])) {
return $this->retries[$url.'~~'.$method];
}
if (isset($this->retries['*~~'.$method])) {
return $this->retries['*~~'.$method];
}
if (isset($this->retries[$url.'~~*'])) {
return $this->retries[$url.'~~*'];
}
if (isset($this->retries['*~~*'])) {
return $this->retries['*~~*'];
}
return null;
} | php | public function getRetry(
string $url,
string $method
): ? Retry {
$url = trim(trim(strtolower($url)), '/');
$method = trim(strtolower($method));
if (isset($this->retries[$url.'~~'.$method])) {
return $this->retries[$url.'~~'.$method];
}
if (isset($this->retries['*~~'.$method])) {
return $this->retries['*~~'.$method];
}
if (isset($this->retries[$url.'~~*'])) {
return $this->retries[$url.'~~*'];
}
if (isset($this->retries['*~~*'])) {
return $this->retries['*~~*'];
}
return null;
} | [
"public",
"function",
"getRetry",
"(",
"string",
"$",
"url",
",",
"string",
"$",
"method",
")",
":",
"?",
"Retry",
"{",
"$",
"url",
"=",
"trim",
"(",
"trim",
"(",
"strtolower",
"(",
"$",
"url",
")",
")",
",",
"'/'",
")",
";",
"$",
"method",
"=",
"trim",
"(",
"strtolower",
"(",
"$",
"method",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"retries",
"[",
"$",
"url",
".",
"'~~'",
".",
"$",
"method",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"retries",
"[",
"$",
"url",
".",
"'~~'",
".",
"$",
"method",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"retries",
"[",
"'*~~'",
".",
"$",
"method",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"retries",
"[",
"'*~~'",
".",
"$",
"method",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"retries",
"[",
"$",
"url",
".",
"'~~*'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"retries",
"[",
"$",
"url",
".",
"'~~*'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"retries",
"[",
"'*~~*'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"retries",
"[",
"'*~~*'",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Check retry.
@param string $url
@param string $method
@return Retry|null | [
"Check",
"retry",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Http/RetryMap.php#L65-L89 |
apisearch-io/php-client | Model/Metadata.php | Metadata.fromMetadata | public static function fromMetadata(string $metadata): ? array
{
$values = [];
$splittedParts = explode('~~', $metadata);
foreach ($splittedParts as $part) {
$parts = explode('##', $part);
if (count($parts) > 1) {
$values[$parts[0]] = $parts[1];
} else {
$values[] = $part;
}
}
if (1 == count($values)) {
$firstAndUniqueElement = reset($values);
$values = [
'id' => $firstAndUniqueElement,
'name' => $firstAndUniqueElement,
];
}
if (!array_key_exists('id', $values)) {
return null;
}
return $values;
} | php | public static function fromMetadata(string $metadata): ? array
{
$values = [];
$splittedParts = explode('~~', $metadata);
foreach ($splittedParts as $part) {
$parts = explode('##', $part);
if (count($parts) > 1) {
$values[$parts[0]] = $parts[1];
} else {
$values[] = $part;
}
}
if (1 == count($values)) {
$firstAndUniqueElement = reset($values);
$values = [
'id' => $firstAndUniqueElement,
'name' => $firstAndUniqueElement,
];
}
if (!array_key_exists('id', $values)) {
return null;
}
return $values;
} | [
"public",
"static",
"function",
"fromMetadata",
"(",
"string",
"$",
"metadata",
")",
":",
"?",
"array",
"{",
"$",
"values",
"=",
"[",
"]",
";",
"$",
"splittedParts",
"=",
"explode",
"(",
"'~~'",
",",
"$",
"metadata",
")",
";",
"foreach",
"(",
"$",
"splittedParts",
"as",
"$",
"part",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'##'",
",",
"$",
"part",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
">",
"1",
")",
"{",
"$",
"values",
"[",
"$",
"parts",
"[",
"0",
"]",
"]",
"=",
"$",
"parts",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"$",
"values",
"[",
"]",
"=",
"$",
"part",
";",
"}",
"}",
"if",
"(",
"1",
"==",
"count",
"(",
"$",
"values",
")",
")",
"{",
"$",
"firstAndUniqueElement",
"=",
"reset",
"(",
"$",
"values",
")",
";",
"$",
"values",
"=",
"[",
"'id'",
"=>",
"$",
"firstAndUniqueElement",
",",
"'name'",
"=>",
"$",
"firstAndUniqueElement",
",",
"]",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'id'",
",",
"$",
"values",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"values",
";",
"}"
] | metadata format to array.
Allowed these formats
"simpletext"
"id##1234~~name##Marc
First format should cover both id and name with the desired value.
@param string $metadata
@return array|null | [
"metadata",
"format",
"to",
"array",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Model/Metadata.php#L59-L86 |
apisearch-io/php-client | Query/Range.php | Range.stringToArray | public static function stringToArray(string $string): array
{
list($from, $to) = explode(self::SEPARATOR, $string);
$from = empty($from)
? self::ZERO
: (is_numeric($from)
? (int) $from
: $from);
$to = empty($to)
? self::INFINITE
: (is_numeric($to)
? (int) $to
: $to);
return [$from, $to];
} | php | public static function stringToArray(string $string): array
{
list($from, $to) = explode(self::SEPARATOR, $string);
$from = empty($from)
? self::ZERO
: (is_numeric($from)
? (int) $from
: $from);
$to = empty($to)
? self::INFINITE
: (is_numeric($to)
? (int) $to
: $to);
return [$from, $to];
} | [
"public",
"static",
"function",
"stringToArray",
"(",
"string",
"$",
"string",
")",
":",
"array",
"{",
"list",
"(",
"$",
"from",
",",
"$",
"to",
")",
"=",
"explode",
"(",
"self",
"::",
"SEPARATOR",
",",
"$",
"string",
")",
";",
"$",
"from",
"=",
"empty",
"(",
"$",
"from",
")",
"?",
"self",
"::",
"ZERO",
":",
"(",
"is_numeric",
"(",
"$",
"from",
")",
"?",
"(",
"int",
")",
"$",
"from",
":",
"$",
"from",
")",
";",
"$",
"to",
"=",
"empty",
"(",
"$",
"to",
")",
"?",
"self",
"::",
"INFINITE",
":",
"(",
"is_numeric",
"(",
"$",
"to",
")",
"?",
"(",
"int",
")",
"$",
"to",
":",
"$",
"to",
")",
";",
"return",
"[",
"$",
"from",
",",
"$",
"to",
"]",
";",
"}"
] | Get values given string.
@param string $string
@return array | [
"Get",
"values",
"given",
"string",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Range.php#L51-L67 |
apisearch-io/php-client | Query/Range.php | Range.arrayToString | public static function arrayToString(array $values): string
{
if (self::ZERO == $values[0]) {
$values[0] = '';
}
if (self::INFINITE == $values[1]) {
$values[1] = '';
}
return implode(self::SEPARATOR, $values);
} | php | public static function arrayToString(array $values): string
{
if (self::ZERO == $values[0]) {
$values[0] = '';
}
if (self::INFINITE == $values[1]) {
$values[1] = '';
}
return implode(self::SEPARATOR, $values);
} | [
"public",
"static",
"function",
"arrayToString",
"(",
"array",
"$",
"values",
")",
":",
"string",
"{",
"if",
"(",
"self",
"::",
"ZERO",
"==",
"$",
"values",
"[",
"0",
"]",
")",
"{",
"$",
"values",
"[",
"0",
"]",
"=",
"''",
";",
"}",
"if",
"(",
"self",
"::",
"INFINITE",
"==",
"$",
"values",
"[",
"1",
"]",
")",
"{",
"$",
"values",
"[",
"1",
"]",
"=",
"''",
";",
"}",
"return",
"implode",
"(",
"self",
"::",
"SEPARATOR",
",",
"$",
"values",
")",
";",
"}"
] | Get string given values.
@param array $values
@return string | [
"Get",
"string",
"given",
"values",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Range.php#L76-L86 |
apisearch-io/php-client | Query/Range.php | Range.createRanges | public static function createRanges(
int $from,
int $to,
int $incremental
): array {
$ranges = [];
while ($from < $to) {
$nextTo = $from + $incremental;
$ranges[] = $from.self::SEPARATOR.$nextTo;
$from = $nextTo;
}
return $ranges;
} | php | public static function createRanges(
int $from,
int $to,
int $incremental
): array {
$ranges = [];
while ($from < $to) {
$nextTo = $from + $incremental;
$ranges[] = $from.self::SEPARATOR.$nextTo;
$from = $nextTo;
}
return $ranges;
} | [
"public",
"static",
"function",
"createRanges",
"(",
"int",
"$",
"from",
",",
"int",
"$",
"to",
",",
"int",
"$",
"incremental",
")",
":",
"array",
"{",
"$",
"ranges",
"=",
"[",
"]",
";",
"while",
"(",
"$",
"from",
"<",
"$",
"to",
")",
"{",
"$",
"nextTo",
"=",
"$",
"from",
"+",
"$",
"incremental",
";",
"$",
"ranges",
"[",
"]",
"=",
"$",
"from",
".",
"self",
"::",
"SEPARATOR",
".",
"$",
"nextTo",
";",
"$",
"from",
"=",
"$",
"nextTo",
";",
"}",
"return",
"$",
"ranges",
";",
"}"
] | Create a set of ranges given a minimum, a maximum and an incremental.
@param int $from
@param int $to
@param int $incremental
@return array | [
"Create",
"a",
"set",
"of",
"ranges",
"given",
"a",
"minimum",
"a",
"maximum",
"and",
"an",
"incremental",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Query/Range.php#L97-L110 |
apisearch-io/php-client | Http/Http.php | Http.getApisearchHeaders | public static function getApisearchHeaders(RepositoryWithCredentials $repository): array
{
return [
self::APP_ID_HEADER => $repository->getAppUUID()->composeUUID(),
self::TOKEN_ID_HEADER => $repository->getTokenUUID()->composeUUID(),
];
} | php | public static function getApisearchHeaders(RepositoryWithCredentials $repository): array
{
return [
self::APP_ID_HEADER => $repository->getAppUUID()->composeUUID(),
self::TOKEN_ID_HEADER => $repository->getTokenUUID()->composeUUID(),
];
} | [
"public",
"static",
"function",
"getApisearchHeaders",
"(",
"RepositoryWithCredentials",
"$",
"repository",
")",
":",
"array",
"{",
"return",
"[",
"self",
"::",
"APP_ID_HEADER",
"=>",
"$",
"repository",
"->",
"getAppUUID",
"(",
")",
"->",
"composeUUID",
"(",
")",
",",
"self",
"::",
"TOKEN_ID_HEADER",
"=>",
"$",
"repository",
"->",
"getTokenUUID",
"(",
")",
"->",
"composeUUID",
"(",
")",
",",
"]",
";",
"}"
] | Get common query values.
@param RepositoryWithCredentials $repository
@return string[] | [
"Get",
"common",
"query",
"values",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Http/Http.php#L67-L73 |
apisearch-io/php-client | Geo/Polygon.php | Polygon.fromFilterArray | public static function fromFilterArray(array $array): LocationRange
{
$coordinates = array_map(function (array $coordinate) {
return Coordinate::createFromArray($coordinate);
}, $array['coordinates']);
return new Polygon($coordinates);
} | php | public static function fromFilterArray(array $array): LocationRange
{
$coordinates = array_map(function (array $coordinate) {
return Coordinate::createFromArray($coordinate);
}, $array['coordinates']);
return new Polygon($coordinates);
} | [
"public",
"static",
"function",
"fromFilterArray",
"(",
"array",
"$",
"array",
")",
":",
"LocationRange",
"{",
"$",
"coordinates",
"=",
"array_map",
"(",
"function",
"(",
"array",
"$",
"coordinate",
")",
"{",
"return",
"Coordinate",
"::",
"createFromArray",
"(",
"$",
"coordinate",
")",
";",
"}",
",",
"$",
"array",
"[",
"'coordinates'",
"]",
")",
";",
"return",
"new",
"Polygon",
"(",
"$",
"coordinates",
")",
";",
"}"
] | From filter array.
@param array $array
@return LocationRange | [
"From",
"filter",
"array",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Geo/Polygon.php#L61-L68 |
apisearch-io/php-client | Repository/RepositoryWithCredentials.php | RepositoryWithCredentials.setCredentials | public function setCredentials(
RepositoryReference $repositoryReference,
TokenUUID $tokenUUID
) {
$this->tokenUUID = $tokenUUID;
$this->setRepositoryReference($repositoryReference);
} | php | public function setCredentials(
RepositoryReference $repositoryReference,
TokenUUID $tokenUUID
) {
$this->tokenUUID = $tokenUUID;
$this->setRepositoryReference($repositoryReference);
} | [
"public",
"function",
"setCredentials",
"(",
"RepositoryReference",
"$",
"repositoryReference",
",",
"TokenUUID",
"$",
"tokenUUID",
")",
"{",
"$",
"this",
"->",
"tokenUUID",
"=",
"$",
"tokenUUID",
";",
"$",
"this",
"->",
"setRepositoryReference",
"(",
"$",
"repositoryReference",
")",
";",
"}"
] | Set credentials.
@param RepositoryReference $repositoryReference
@param TokenUUID $tokenUUID | [
"Set",
"credentials",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Repository/RepositoryWithCredentials.php#L40-L46 |
apisearch-io/php-client | App/HttpAppRepository.php | HttpAppRepository.addToken | public function addToken(Token $token)
{
$response = $this
->httpClient
->get(
sprintf('/%s/tokens', $this->getAppUUID()->getId()),
'put',
[],
$token->toArray(),
Http::getApisearchHeaders($this)
);
self::throwTransportableExceptionIfNeeded($response);
} | php | public function addToken(Token $token)
{
$response = $this
->httpClient
->get(
sprintf('/%s/tokens', $this->getAppUUID()->getId()),
'put',
[],
$token->toArray(),
Http::getApisearchHeaders($this)
);
self::throwTransportableExceptionIfNeeded($response);
} | [
"public",
"function",
"addToken",
"(",
"Token",
"$",
"token",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"httpClient",
"->",
"get",
"(",
"sprintf",
"(",
"'/%s/tokens'",
",",
"$",
"this",
"->",
"getAppUUID",
"(",
")",
"->",
"getId",
"(",
")",
")",
",",
"'put'",
",",
"[",
"]",
",",
"$",
"token",
"->",
"toArray",
"(",
")",
",",
"Http",
"::",
"getApisearchHeaders",
"(",
"$",
"this",
")",
")",
";",
"self",
"::",
"throwTransportableExceptionIfNeeded",
"(",
"$",
"response",
")",
";",
"}"
] | Add token.
@param Token $token | [
"Add",
"token",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/App/HttpAppRepository.php#L38-L51 |
apisearch-io/php-client | App/HttpAppRepository.php | HttpAppRepository.deleteToken | public function deleteToken(TokenUUID $tokenUUID)
{
$response = $this
->httpClient
->get(
sprintf(
'/%s/tokens/%s',
$this->getAppUUID()->composeUUID(),
$tokenUUID->composeUUID()
),
'delete',
[],
[],
Http::getApisearchHeaders($this)
);
self::throwTransportableExceptionIfNeeded($response);
} | php | public function deleteToken(TokenUUID $tokenUUID)
{
$response = $this
->httpClient
->get(
sprintf(
'/%s/tokens/%s',
$this->getAppUUID()->composeUUID(),
$tokenUUID->composeUUID()
),
'delete',
[],
[],
Http::getApisearchHeaders($this)
);
self::throwTransportableExceptionIfNeeded($response);
} | [
"public",
"function",
"deleteToken",
"(",
"TokenUUID",
"$",
"tokenUUID",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"httpClient",
"->",
"get",
"(",
"sprintf",
"(",
"'/%s/tokens/%s'",
",",
"$",
"this",
"->",
"getAppUUID",
"(",
")",
"->",
"composeUUID",
"(",
")",
",",
"$",
"tokenUUID",
"->",
"composeUUID",
"(",
")",
")",
",",
"'delete'",
",",
"[",
"]",
",",
"[",
"]",
",",
"Http",
"::",
"getApisearchHeaders",
"(",
"$",
"this",
")",
")",
";",
"self",
"::",
"throwTransportableExceptionIfNeeded",
"(",
"$",
"response",
")",
";",
"}"
] | Delete token.
@param TokenUUID $tokenUUID | [
"Delete",
"token",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/App/HttpAppRepository.php#L58-L75 |
apisearch-io/php-client | App/HttpAppRepository.php | HttpAppRepository.getTokens | public function getTokens(): array
{
$response = $this
->httpClient
->get(
sprintf(
'/%s/tokens',
$this->getAppUUID()->getId()
),
'get',
[],
[],
Http::getApisearchHeaders($this)
);
self::throwTransportableExceptionIfNeeded($response);
return array_map(function (array $token) {
return Token::createFromArray($token);
}, $response['body']);
} | php | public function getTokens(): array
{
$response = $this
->httpClient
->get(
sprintf(
'/%s/tokens',
$this->getAppUUID()->getId()
),
'get',
[],
[],
Http::getApisearchHeaders($this)
);
self::throwTransportableExceptionIfNeeded($response);
return array_map(function (array $token) {
return Token::createFromArray($token);
}, $response['body']);
} | [
"public",
"function",
"getTokens",
"(",
")",
":",
"array",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"httpClient",
"->",
"get",
"(",
"sprintf",
"(",
"'/%s/tokens'",
",",
"$",
"this",
"->",
"getAppUUID",
"(",
")",
"->",
"getId",
"(",
")",
")",
",",
"'get'",
",",
"[",
"]",
",",
"[",
"]",
",",
"Http",
"::",
"getApisearchHeaders",
"(",
"$",
"this",
")",
")",
";",
"self",
"::",
"throwTransportableExceptionIfNeeded",
"(",
"$",
"response",
")",
";",
"return",
"array_map",
"(",
"function",
"(",
"array",
"$",
"token",
")",
"{",
"return",
"Token",
"::",
"createFromArray",
"(",
"$",
"token",
")",
";",
"}",
",",
"$",
"response",
"[",
"'body'",
"]",
")",
";",
"}"
] | Get tokens.
@return Token[] | [
"Get",
"tokens",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/App/HttpAppRepository.php#L82-L102 |
apisearch-io/php-client | App/HttpAppRepository.php | HttpAppRepository.deleteTokens | public function deleteTokens()
{
$response = $this
->httpClient
->get(
sprintf(
'/%s/tokens',
$this->getAppUUID()->getId()
),
'delete',
[],
[],
Http::getApisearchHeaders($this)
);
self::throwTransportableExceptionIfNeeded($response);
} | php | public function deleteTokens()
{
$response = $this
->httpClient
->get(
sprintf(
'/%s/tokens',
$this->getAppUUID()->getId()
),
'delete',
[],
[],
Http::getApisearchHeaders($this)
);
self::throwTransportableExceptionIfNeeded($response);
} | [
"public",
"function",
"deleteTokens",
"(",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"httpClient",
"->",
"get",
"(",
"sprintf",
"(",
"'/%s/tokens'",
",",
"$",
"this",
"->",
"getAppUUID",
"(",
")",
"->",
"getId",
"(",
")",
")",
",",
"'delete'",
",",
"[",
"]",
",",
"[",
"]",
",",
"Http",
"::",
"getApisearchHeaders",
"(",
"$",
"this",
")",
")",
";",
"self",
"::",
"throwTransportableExceptionIfNeeded",
"(",
"$",
"response",
")",
";",
"}"
] | Delete all tokens. | [
"Delete",
"all",
"tokens",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/App/HttpAppRepository.php#L107-L123 |
apisearch-io/php-client | App/HttpAppRepository.php | HttpAppRepository.getIndices | public function getIndices(): array
{
$response = $this
->httpClient
->get(
sprintf(
'/%s/indices',
$this->getAppUUID()->getId()
),
'get',
[],
[],
Http::getApisearchHeaders($this)
);
self::throwTransportableExceptionIfNeeded($response);
$result = [];
foreach ($response['body'] as $index) {
$result[] = Index::createFromArray($index);
}
return $result;
} | php | public function getIndices(): array
{
$response = $this
->httpClient
->get(
sprintf(
'/%s/indices',
$this->getAppUUID()->getId()
),
'get',
[],
[],
Http::getApisearchHeaders($this)
);
self::throwTransportableExceptionIfNeeded($response);
$result = [];
foreach ($response['body'] as $index) {
$result[] = Index::createFromArray($index);
}
return $result;
} | [
"public",
"function",
"getIndices",
"(",
")",
":",
"array",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"httpClient",
"->",
"get",
"(",
"sprintf",
"(",
"'/%s/indices'",
",",
"$",
"this",
"->",
"getAppUUID",
"(",
")",
"->",
"getId",
"(",
")",
")",
",",
"'get'",
",",
"[",
"]",
",",
"[",
"]",
",",
"Http",
"::",
"getApisearchHeaders",
"(",
"$",
"this",
")",
")",
";",
"self",
"::",
"throwTransportableExceptionIfNeeded",
"(",
"$",
"response",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"response",
"[",
"'body'",
"]",
"as",
"$",
"index",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"Index",
"::",
"createFromArray",
"(",
"$",
"index",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get indices.
@return Index[] | [
"Get",
"indices",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/App/HttpAppRepository.php#L130-L153 |
apisearch-io/php-client | App/HttpAppRepository.php | HttpAppRepository.deleteIndex | public function deleteIndex(IndexUUID $indexUUID)
{
$response = $this
->httpClient
->get(
sprintf(
'/%s/indices/%s',
$this->getAppUUID()->composeUUID(),
$indexUUID->composeUUID()
),
'delete',
[],
[],
Http::getApisearchHeaders($this)
);
self::throwTransportableExceptionIfNeeded($response);
} | php | public function deleteIndex(IndexUUID $indexUUID)
{
$response = $this
->httpClient
->get(
sprintf(
'/%s/indices/%s',
$this->getAppUUID()->composeUUID(),
$indexUUID->composeUUID()
),
'delete',
[],
[],
Http::getApisearchHeaders($this)
);
self::throwTransportableExceptionIfNeeded($response);
} | [
"public",
"function",
"deleteIndex",
"(",
"IndexUUID",
"$",
"indexUUID",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"httpClient",
"->",
"get",
"(",
"sprintf",
"(",
"'/%s/indices/%s'",
",",
"$",
"this",
"->",
"getAppUUID",
"(",
")",
"->",
"composeUUID",
"(",
")",
",",
"$",
"indexUUID",
"->",
"composeUUID",
"(",
")",
")",
",",
"'delete'",
",",
"[",
"]",
",",
"[",
"]",
",",
"Http",
"::",
"getApisearchHeaders",
"(",
"$",
"this",
")",
")",
";",
"self",
"::",
"throwTransportableExceptionIfNeeded",
"(",
"$",
"response",
")",
";",
"}"
] | Delete an index.
@param IndexUUID $indexUUID
@throws ResourceNotAvailableException | [
"Delete",
"an",
"index",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/App/HttpAppRepository.php#L191-L208 |
apisearch-io/php-client | App/HttpAppRepository.php | HttpAppRepository.checkIndex | public function checkIndex(IndexUUID $indexUUID): bool
{
$response = $this
->httpClient
->get(
sprintf(
'/%s/indices/%s',
$this->getAppUUID()->composeUUID(),
$indexUUID->composeUUID()
),
'head',
[],
[],
Http::getApisearchHeaders($this)
);
if (null === $response) {
return false;
}
return 200 === $response['code'];
} | php | public function checkIndex(IndexUUID $indexUUID): bool
{
$response = $this
->httpClient
->get(
sprintf(
'/%s/indices/%s',
$this->getAppUUID()->composeUUID(),
$indexUUID->composeUUID()
),
'head',
[],
[],
Http::getApisearchHeaders($this)
);
if (null === $response) {
return false;
}
return 200 === $response['code'];
} | [
"public",
"function",
"checkIndex",
"(",
"IndexUUID",
"$",
"indexUUID",
")",
":",
"bool",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"httpClient",
"->",
"get",
"(",
"sprintf",
"(",
"'/%s/indices/%s'",
",",
"$",
"this",
"->",
"getAppUUID",
"(",
")",
"->",
"composeUUID",
"(",
")",
",",
"$",
"indexUUID",
"->",
"composeUUID",
"(",
")",
")",
",",
"'head'",
",",
"[",
"]",
",",
"[",
"]",
",",
"Http",
"::",
"getApisearchHeaders",
"(",
"$",
"this",
")",
")",
";",
"if",
"(",
"null",
"===",
"$",
"response",
")",
"{",
"return",
"false",
";",
"}",
"return",
"200",
"===",
"$",
"response",
"[",
"'code'",
"]",
";",
"}"
] | Checks the index.
@param IndexUUID $indexUUID
@return bool | [
"Checks",
"the",
"index",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/App/HttpAppRepository.php#L243-L264 |
apisearch-io/php-client | App/HttpAppRepository.php | HttpAppRepository.configureIndex | public function configureIndex(
IndexUUID $indexUUID,
Config $config
) {
$response = $this
->httpClient
->get(
sprintf(
'/%s/indices/%s/configure',
$this->getAppUUID()->composeUUID(),
$indexUUID->composeUUID()
),
'post',
[],
$config->toArray(),
Http::getApisearchHeaders($this)
);
if (null === $response) {
return;
}
self::throwTransportableExceptionIfNeeded($response);
} | php | public function configureIndex(
IndexUUID $indexUUID,
Config $config
) {
$response = $this
->httpClient
->get(
sprintf(
'/%s/indices/%s/configure',
$this->getAppUUID()->composeUUID(),
$indexUUID->composeUUID()
),
'post',
[],
$config->toArray(),
Http::getApisearchHeaders($this)
);
if (null === $response) {
return;
}
self::throwTransportableExceptionIfNeeded($response);
} | [
"public",
"function",
"configureIndex",
"(",
"IndexUUID",
"$",
"indexUUID",
",",
"Config",
"$",
"config",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"httpClient",
"->",
"get",
"(",
"sprintf",
"(",
"'/%s/indices/%s/configure'",
",",
"$",
"this",
"->",
"getAppUUID",
"(",
")",
"->",
"composeUUID",
"(",
")",
",",
"$",
"indexUUID",
"->",
"composeUUID",
"(",
")",
")",
",",
"'post'",
",",
"[",
"]",
",",
"$",
"config",
"->",
"toArray",
"(",
")",
",",
"Http",
"::",
"getApisearchHeaders",
"(",
"$",
"this",
")",
")",
";",
"if",
"(",
"null",
"===",
"$",
"response",
")",
"{",
"return",
";",
"}",
"self",
"::",
"throwTransportableExceptionIfNeeded",
"(",
"$",
"response",
")",
";",
"}"
] | Config the index.
@param IndexUUID $indexUUID
@param Config $config
@throws ResourceNotAvailableException | [
"Config",
"the",
"index",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/App/HttpAppRepository.php#L274-L297 |
apisearch-io/php-client | Repository/Repository.php | Repository.addItem | public function addItem(Item $item)
{
$itemUUID = $item->composeUUID();
$this->elementsToUpdate[$itemUUID] = $item;
unset($this->elementsToDelete[$itemUUID]);
} | php | public function addItem(Item $item)
{
$itemUUID = $item->composeUUID();
$this->elementsToUpdate[$itemUUID] = $item;
unset($this->elementsToDelete[$itemUUID]);
} | [
"public",
"function",
"addItem",
"(",
"Item",
"$",
"item",
")",
"{",
"$",
"itemUUID",
"=",
"$",
"item",
"->",
"composeUUID",
"(",
")",
";",
"$",
"this",
"->",
"elementsToUpdate",
"[",
"$",
"itemUUID",
"]",
"=",
"$",
"item",
";",
"unset",
"(",
"$",
"this",
"->",
"elementsToDelete",
"[",
"$",
"itemUUID",
"]",
")",
";",
"}"
] | Generate item document.
@param Item $item | [
"Generate",
"item",
"document",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Repository/Repository.php#L67-L73 |
apisearch-io/php-client | Repository/Repository.php | Repository.deleteItem | public function deleteItem(ItemUUID $uuid)
{
$itemUUID = $uuid->composeUUID();
$this->elementsToDelete[$itemUUID] = $uuid;
unset($this->elementsToUpdate[$itemUUID]);
} | php | public function deleteItem(ItemUUID $uuid)
{
$itemUUID = $uuid->composeUUID();
$this->elementsToDelete[$itemUUID] = $uuid;
unset($this->elementsToUpdate[$itemUUID]);
} | [
"public",
"function",
"deleteItem",
"(",
"ItemUUID",
"$",
"uuid",
")",
"{",
"$",
"itemUUID",
"=",
"$",
"uuid",
"->",
"composeUUID",
"(",
")",
";",
"$",
"this",
"->",
"elementsToDelete",
"[",
"$",
"itemUUID",
"]",
"=",
"$",
"uuid",
";",
"unset",
"(",
"$",
"this",
"->",
"elementsToUpdate",
"[",
"$",
"itemUUID",
"]",
")",
";",
"}"
] | Delete item document by uuid.
@param ItemUUID $uuid | [
"Delete",
"item",
"document",
"by",
"uuid",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Repository/Repository.php#L92-L97 |
apisearch-io/php-client | Repository/Repository.php | Repository.flush | public function flush(
int $bulkNumber = 500,
bool $skipIfLess = false
) {
if (
$skipIfLess &&
count($this->elementsToUpdate) < $bulkNumber
) {
return;
}
$offset = 0;
try {
while (true) {
$items = array_slice(
$this->elementsToUpdate,
$offset,
$bulkNumber
);
if (empty($items)) {
break;
}
$this->flushItems($items, []);
$offset += $bulkNumber;
}
$this->flushItems([], $this->elementsToDelete);
} catch (Exception $exception) {
/*
* No matter the exception is thrown, cached elements should be
* deleted
*/
$this->resetCachedElements();
throw $exception;
}
$this->resetCachedElements();
} | php | public function flush(
int $bulkNumber = 500,
bool $skipIfLess = false
) {
if (
$skipIfLess &&
count($this->elementsToUpdate) < $bulkNumber
) {
return;
}
$offset = 0;
try {
while (true) {
$items = array_slice(
$this->elementsToUpdate,
$offset,
$bulkNumber
);
if (empty($items)) {
break;
}
$this->flushItems($items, []);
$offset += $bulkNumber;
}
$this->flushItems([], $this->elementsToDelete);
} catch (Exception $exception) {
/*
* No matter the exception is thrown, cached elements should be
* deleted
*/
$this->resetCachedElements();
throw $exception;
}
$this->resetCachedElements();
} | [
"public",
"function",
"flush",
"(",
"int",
"$",
"bulkNumber",
"=",
"500",
",",
"bool",
"$",
"skipIfLess",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"skipIfLess",
"&&",
"count",
"(",
"$",
"this",
"->",
"elementsToUpdate",
")",
"<",
"$",
"bulkNumber",
")",
"{",
"return",
";",
"}",
"$",
"offset",
"=",
"0",
";",
"try",
"{",
"while",
"(",
"true",
")",
"{",
"$",
"items",
"=",
"array_slice",
"(",
"$",
"this",
"->",
"elementsToUpdate",
",",
"$",
"offset",
",",
"$",
"bulkNumber",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"items",
")",
")",
"{",
"break",
";",
"}",
"$",
"this",
"->",
"flushItems",
"(",
"$",
"items",
",",
"[",
"]",
")",
";",
"$",
"offset",
"+=",
"$",
"bulkNumber",
";",
"}",
"$",
"this",
"->",
"flushItems",
"(",
"[",
"]",
",",
"$",
"this",
"->",
"elementsToDelete",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"exception",
")",
"{",
"/*\n * No matter the exception is thrown, cached elements should be\n * deleted\n */",
"$",
"this",
"->",
"resetCachedElements",
"(",
")",
";",
"throw",
"$",
"exception",
";",
"}",
"$",
"this",
"->",
"resetCachedElements",
"(",
")",
";",
"}"
] | Flush all.
This flush can be avoided if not enough items have been generated by
setting $skipIfLess = true
@param int $bulkNumber
@param bool $skipIfLess
@throws ResourceNotAvailableException
@throws Exception | [
"Flush",
"all",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Repository/Repository.php#L123-L164 |
apisearch-io/php-client | Result/Aggregations.php | Aggregations.hasNotEmptyAggregation | public function hasNotEmptyAggregation(string $name): bool
{
return
!is_null($this->getAggregation($name)) &&
!$this
->getAggregation($name)
->isEmpty();
} | php | public function hasNotEmptyAggregation(string $name): bool
{
return
!is_null($this->getAggregation($name)) &&
!$this
->getAggregation($name)
->isEmpty();
} | [
"public",
"function",
"hasNotEmptyAggregation",
"(",
"string",
"$",
"name",
")",
":",
"bool",
"{",
"return",
"!",
"is_null",
"(",
"$",
"this",
"->",
"getAggregation",
"(",
"$",
"name",
")",
")",
"&&",
"!",
"$",
"this",
"->",
"getAggregation",
"(",
"$",
"name",
")",
"->",
"isEmpty",
"(",
")",
";",
"}"
] | Return if the needed aggregation exists and if is not empty.
@param string $name
@return bool | [
"Return",
"if",
"the",
"needed",
"aggregation",
"exists",
"and",
"if",
"is",
"not",
"empty",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Result/Aggregations.php#L94-L101 |
apisearch-io/php-client | Result/Aggregations.php | Aggregations.toArray | public function toArray(): array
{
return array_filter([
'aggregations' => array_map(function (Aggregation $aggregation) {
return $aggregation->toArray();
}, $this->getAggregations()),
'total_elements' => $this->getTotalElements(),
]);
} | php | public function toArray(): array
{
return array_filter([
'aggregations' => array_map(function (Aggregation $aggregation) {
return $aggregation->toArray();
}, $this->getAggregations()),
'total_elements' => $this->getTotalElements(),
]);
} | [
"public",
"function",
"toArray",
"(",
")",
":",
"array",
"{",
"return",
"array_filter",
"(",
"[",
"'aggregations'",
"=>",
"array_map",
"(",
"function",
"(",
"Aggregation",
"$",
"aggregation",
")",
"{",
"return",
"$",
"aggregation",
"->",
"toArray",
"(",
")",
";",
"}",
",",
"$",
"this",
"->",
"getAggregations",
"(",
")",
")",
",",
"'total_elements'",
"=>",
"$",
"this",
"->",
"getTotalElements",
"(",
")",
",",
"]",
")",
";",
"}"
] | To array.
@return array | [
"To",
"array",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Result/Aggregations.php#L133-L141 |
apisearch-io/php-client | Result/Aggregations.php | Aggregations.createFromArray | public static function createFromArray(array $array): self
{
$aggregations = new self(
$array['total_elements'] ?? 0
);
if (isset($array['aggregations'])) {
foreach ($array['aggregations'] as $aggregationName => $aggregation) {
$aggregations->addAggregation(
$aggregationName,
Aggregation::createFromArray($aggregation)
);
}
}
return $aggregations;
} | php | public static function createFromArray(array $array): self
{
$aggregations = new self(
$array['total_elements'] ?? 0
);
if (isset($array['aggregations'])) {
foreach ($array['aggregations'] as $aggregationName => $aggregation) {
$aggregations->addAggregation(
$aggregationName,
Aggregation::createFromArray($aggregation)
);
}
}
return $aggregations;
} | [
"public",
"static",
"function",
"createFromArray",
"(",
"array",
"$",
"array",
")",
":",
"self",
"{",
"$",
"aggregations",
"=",
"new",
"self",
"(",
"$",
"array",
"[",
"'total_elements'",
"]",
"??",
"0",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"array",
"[",
"'aggregations'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"array",
"[",
"'aggregations'",
"]",
"as",
"$",
"aggregationName",
"=>",
"$",
"aggregation",
")",
"{",
"$",
"aggregations",
"->",
"addAggregation",
"(",
"$",
"aggregationName",
",",
"Aggregation",
"::",
"createFromArray",
"(",
"$",
"aggregation",
")",
")",
";",
"}",
"}",
"return",
"$",
"aggregations",
";",
"}"
] | Create from array.
@param array $array
@return self | [
"Create",
"from",
"array",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Result/Aggregations.php#L150-L166 |
apisearch-io/php-client | Http/TCPClient.php | TCPClient.get | public function get(
string $url,
string $method,
array $query = [],
array $body = [],
array $server = []
): array {
$method = strtolower($method);
$requestParts = $this->buildRequestParts(
$url,
$query,
$body,
$server
);
return $this->tryRequest(function () use ($method, $requestParts) {
return $this
->httpAdapter
->getByRequestParts(
$this->host,
$method,
$requestParts
);
}, $this
->retryMap
->getRetry(
$url,
$method
)
);
} | php | public function get(
string $url,
string $method,
array $query = [],
array $body = [],
array $server = []
): array {
$method = strtolower($method);
$requestParts = $this->buildRequestParts(
$url,
$query,
$body,
$server
);
return $this->tryRequest(function () use ($method, $requestParts) {
return $this
->httpAdapter
->getByRequestParts(
$this->host,
$method,
$requestParts
);
}, $this
->retryMap
->getRetry(
$url,
$method
)
);
} | [
"public",
"function",
"get",
"(",
"string",
"$",
"url",
",",
"string",
"$",
"method",
",",
"array",
"$",
"query",
"=",
"[",
"]",
",",
"array",
"$",
"body",
"=",
"[",
"]",
",",
"array",
"$",
"server",
"=",
"[",
"]",
")",
":",
"array",
"{",
"$",
"method",
"=",
"strtolower",
"(",
"$",
"method",
")",
";",
"$",
"requestParts",
"=",
"$",
"this",
"->",
"buildRequestParts",
"(",
"$",
"url",
",",
"$",
"query",
",",
"$",
"body",
",",
"$",
"server",
")",
";",
"return",
"$",
"this",
"->",
"tryRequest",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"method",
",",
"$",
"requestParts",
")",
"{",
"return",
"$",
"this",
"->",
"httpAdapter",
"->",
"getByRequestParts",
"(",
"$",
"this",
"->",
"host",
",",
"$",
"method",
",",
"$",
"requestParts",
")",
";",
"}",
",",
"$",
"this",
"->",
"retryMap",
"->",
"getRetry",
"(",
"$",
"url",
",",
"$",
"method",
")",
")",
";",
"}"
] | Get a response given some parameters.
Return an array with the status code and the body.
@param string $url
@param string $method
@param array $query
@param array $body
@param array $server
@return array
@throws ConnectionException | [
"Get",
"a",
"response",
"given",
"some",
"parameters",
".",
"Return",
"an",
"array",
"with",
"the",
"status",
"code",
"and",
"the",
"body",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Http/TCPClient.php#L77-L107 |
apisearch-io/php-client | Http/TCPClient.php | TCPClient.tryRequest | private function tryRequest(
callable $callable,
?Retry $retry
): array {
$tries = $retry instanceof Retry
? $retry->getRetries()
: 0;
while (true) {
try {
return $callable();
} catch (\Exception $e) {
if ($tries-- <= 0) {
throw $e;
}
usleep($retry->getMicrosecondsBetweenRetries());
}
}
} | php | private function tryRequest(
callable $callable,
?Retry $retry
): array {
$tries = $retry instanceof Retry
? $retry->getRetries()
: 0;
while (true) {
try {
return $callable();
} catch (\Exception $e) {
if ($tries-- <= 0) {
throw $e;
}
usleep($retry->getMicrosecondsBetweenRetries());
}
}
} | [
"private",
"function",
"tryRequest",
"(",
"callable",
"$",
"callable",
",",
"?",
"Retry",
"$",
"retry",
")",
":",
"array",
"{",
"$",
"tries",
"=",
"$",
"retry",
"instanceof",
"Retry",
"?",
"$",
"retry",
"->",
"getRetries",
"(",
")",
":",
"0",
";",
"while",
"(",
"true",
")",
"{",
"try",
"{",
"return",
"$",
"callable",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"tries",
"--",
"<=",
"0",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"usleep",
"(",
"$",
"retry",
"->",
"getMicrosecondsBetweenRetries",
"(",
")",
")",
";",
"}",
"}",
"}"
] | Try connection and return result.
Retry n times this connection before returning response.
@param callable $callable
@param Retry|null $retry
@return array
@throws Exception | [
"Try",
"connection",
"and",
"return",
"result",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Http/TCPClient.php#L121-L140 |
apisearch-io/php-client | Result/Aggregation.php | Aggregation.addCounter | public function addCounter(
string $name,
int $counter
) {
if (0 == $counter) {
return;
}
$counterInstance = Counter::createByActiveElements(
$name,
$counter,
$this->activeElements
);
if (!$counterInstance instanceof Counter) {
return;
}
/*
* The entry is used.
* This block should take in account when the filter is of type
* levels, but only levels.
*/
if (
$this->applicationType & Filter::MUST_ALL_WITH_LEVELS &&
$this->applicationType & ~Filter::MUST_ALL &&
$counterInstance->isUsed()
) {
$this->activeElements[$counterInstance->getId()] = $counterInstance;
$this->highestActiveLevel = max(
$counterInstance->getLevel(),
$this->highestActiveLevel
);
return;
}
$this->counters[$counterInstance->getId()] = $counterInstance;
} | php | public function addCounter(
string $name,
int $counter
) {
if (0 == $counter) {
return;
}
$counterInstance = Counter::createByActiveElements(
$name,
$counter,
$this->activeElements
);
if (!$counterInstance instanceof Counter) {
return;
}
/*
* The entry is used.
* This block should take in account when the filter is of type
* levels, but only levels.
*/
if (
$this->applicationType & Filter::MUST_ALL_WITH_LEVELS &&
$this->applicationType & ~Filter::MUST_ALL &&
$counterInstance->isUsed()
) {
$this->activeElements[$counterInstance->getId()] = $counterInstance;
$this->highestActiveLevel = max(
$counterInstance->getLevel(),
$this->highestActiveLevel
);
return;
}
$this->counters[$counterInstance->getId()] = $counterInstance;
} | [
"public",
"function",
"addCounter",
"(",
"string",
"$",
"name",
",",
"int",
"$",
"counter",
")",
"{",
"if",
"(",
"0",
"==",
"$",
"counter",
")",
"{",
"return",
";",
"}",
"$",
"counterInstance",
"=",
"Counter",
"::",
"createByActiveElements",
"(",
"$",
"name",
",",
"$",
"counter",
",",
"$",
"this",
"->",
"activeElements",
")",
";",
"if",
"(",
"!",
"$",
"counterInstance",
"instanceof",
"Counter",
")",
"{",
"return",
";",
"}",
"/*\n * The entry is used.\n * This block should take in account when the filter is of type\n * levels, but only levels.\n */",
"if",
"(",
"$",
"this",
"->",
"applicationType",
"&",
"Filter",
"::",
"MUST_ALL_WITH_LEVELS",
"&&",
"$",
"this",
"->",
"applicationType",
"&",
"~",
"Filter",
"::",
"MUST_ALL",
"&&",
"$",
"counterInstance",
"->",
"isUsed",
"(",
")",
")",
"{",
"$",
"this",
"->",
"activeElements",
"[",
"$",
"counterInstance",
"->",
"getId",
"(",
")",
"]",
"=",
"$",
"counterInstance",
";",
"$",
"this",
"->",
"highestActiveLevel",
"=",
"max",
"(",
"$",
"counterInstance",
"->",
"getLevel",
"(",
")",
",",
"$",
"this",
"->",
"highestActiveLevel",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"counters",
"[",
"$",
"counterInstance",
"->",
"getId",
"(",
")",
"]",
"=",
"$",
"counterInstance",
";",
"}"
] | Add aggregation counter.
@param string $name
@param int $counter | [
"Add",
"aggregation",
"counter",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Result/Aggregation.php#L100-L138 |
apisearch-io/php-client | Result/Aggregation.php | Aggregation.getActiveElements | public function getActiveElements(): array
{
if (empty($this->activeElements)) {
return [];
}
if (Filter::MUST_ALL_WITH_LEVELS === $this->applicationType) {
$value = [array_reduce(
$this->activeElements,
function ($carry, $counter) {
if (!$counter instanceof Counter) {
return $carry;
}
if (!$carry instanceof Counter) {
return $counter;
}
return $carry->getLevel() > $counter->getLevel()
? $carry
: $counter;
}, null)];
return is_null($value)
? []
: $value;
}
return $this->activeElements;
} | php | public function getActiveElements(): array
{
if (empty($this->activeElements)) {
return [];
}
if (Filter::MUST_ALL_WITH_LEVELS === $this->applicationType) {
$value = [array_reduce(
$this->activeElements,
function ($carry, $counter) {
if (!$counter instanceof Counter) {
return $carry;
}
if (!$carry instanceof Counter) {
return $counter;
}
return $carry->getLevel() > $counter->getLevel()
? $carry
: $counter;
}, null)];
return is_null($value)
? []
: $value;
}
return $this->activeElements;
} | [
"public",
"function",
"getActiveElements",
"(",
")",
":",
"array",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"activeElements",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"if",
"(",
"Filter",
"::",
"MUST_ALL_WITH_LEVELS",
"===",
"$",
"this",
"->",
"applicationType",
")",
"{",
"$",
"value",
"=",
"[",
"array_reduce",
"(",
"$",
"this",
"->",
"activeElements",
",",
"function",
"(",
"$",
"carry",
",",
"$",
"counter",
")",
"{",
"if",
"(",
"!",
"$",
"counter",
"instanceof",
"Counter",
")",
"{",
"return",
"$",
"carry",
";",
"}",
"if",
"(",
"!",
"$",
"carry",
"instanceof",
"Counter",
")",
"{",
"return",
"$",
"counter",
";",
"}",
"return",
"$",
"carry",
"->",
"getLevel",
"(",
")",
">",
"$",
"counter",
"->",
"getLevel",
"(",
")",
"?",
"$",
"carry",
":",
"$",
"counter",
";",
"}",
",",
"null",
")",
"]",
";",
"return",
"is_null",
"(",
"$",
"value",
")",
"?",
"[",
"]",
":",
"$",
"value",
";",
"}",
"return",
"$",
"this",
"->",
"activeElements",
";",
"}"
] | Get active elements.
@return array | [
"Get",
"active",
"elements",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Result/Aggregation.php#L217-L246 |
apisearch-io/php-client | Result/Aggregation.php | Aggregation.cleanCountersByLevel | public function cleanCountersByLevel()
{
foreach ($this->counters as $pos => $counter) {
if ($counter->getLevel() !== $this->highestActiveLevel + 1) {
unset($this->counters[$pos]);
}
}
} | php | public function cleanCountersByLevel()
{
foreach ($this->counters as $pos => $counter) {
if ($counter->getLevel() !== $this->highestActiveLevel + 1) {
unset($this->counters[$pos]);
}
}
} | [
"public",
"function",
"cleanCountersByLevel",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"counters",
"as",
"$",
"pos",
"=>",
"$",
"counter",
")",
"{",
"if",
"(",
"$",
"counter",
"->",
"getLevel",
"(",
")",
"!==",
"$",
"this",
"->",
"highestActiveLevel",
"+",
"1",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"counters",
"[",
"$",
"pos",
"]",
")",
";",
"}",
"}",
"}"
] | Clean results by level and remove all levels higher than the lowest. | [
"Clean",
"results",
"by",
"level",
"and",
"remove",
"all",
"levels",
"higher",
"than",
"the",
"lowest",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Result/Aggregation.php#L251-L258 |
apisearch-io/php-client | Result/Aggregation.php | Aggregation.toArray | public function toArray(): array
{
return array_filter([
'name' => $this->name,
'counters' => array_values(array_map(function (Counter $counter) {
return $counter->toArray();
}, $this->counters)),
'application_type' => Filter::AT_LEAST_ONE === $this->applicationType
? null
: $this->applicationType,
'total_elements' => 0 === $this->totalElements
? null
: $this->totalElements,
'active_elements' => array_values(array_map(function ($counter) {
return ($counter instanceof Counter)
? $counter->toArray()
: $counter;
}, $this->activeElements)),
'highest_active_level' => 0 === $this->highestActiveLevel
? null
: $this->highestActiveLevel,
], function ($element) {
return
!(
is_null($element) ||
(is_array($element) && empty($element))
);
});
} | php | public function toArray(): array
{
return array_filter([
'name' => $this->name,
'counters' => array_values(array_map(function (Counter $counter) {
return $counter->toArray();
}, $this->counters)),
'application_type' => Filter::AT_LEAST_ONE === $this->applicationType
? null
: $this->applicationType,
'total_elements' => 0 === $this->totalElements
? null
: $this->totalElements,
'active_elements' => array_values(array_map(function ($counter) {
return ($counter instanceof Counter)
? $counter->toArray()
: $counter;
}, $this->activeElements)),
'highest_active_level' => 0 === $this->highestActiveLevel
? null
: $this->highestActiveLevel,
], function ($element) {
return
!(
is_null($element) ||
(is_array($element) && empty($element))
);
});
} | [
"public",
"function",
"toArray",
"(",
")",
":",
"array",
"{",
"return",
"array_filter",
"(",
"[",
"'name'",
"=>",
"$",
"this",
"->",
"name",
",",
"'counters'",
"=>",
"array_values",
"(",
"array_map",
"(",
"function",
"(",
"Counter",
"$",
"counter",
")",
"{",
"return",
"$",
"counter",
"->",
"toArray",
"(",
")",
";",
"}",
",",
"$",
"this",
"->",
"counters",
")",
")",
",",
"'application_type'",
"=>",
"Filter",
"::",
"AT_LEAST_ONE",
"===",
"$",
"this",
"->",
"applicationType",
"?",
"null",
":",
"$",
"this",
"->",
"applicationType",
",",
"'total_elements'",
"=>",
"0",
"===",
"$",
"this",
"->",
"totalElements",
"?",
"null",
":",
"$",
"this",
"->",
"totalElements",
",",
"'active_elements'",
"=>",
"array_values",
"(",
"array_map",
"(",
"function",
"(",
"$",
"counter",
")",
"{",
"return",
"(",
"$",
"counter",
"instanceof",
"Counter",
")",
"?",
"$",
"counter",
"->",
"toArray",
"(",
")",
":",
"$",
"counter",
";",
"}",
",",
"$",
"this",
"->",
"activeElements",
")",
")",
",",
"'highest_active_level'",
"=>",
"0",
"===",
"$",
"this",
"->",
"highestActiveLevel",
"?",
"null",
":",
"$",
"this",
"->",
"highestActiveLevel",
",",
"]",
",",
"function",
"(",
"$",
"element",
")",
"{",
"return",
"!",
"(",
"is_null",
"(",
"$",
"element",
")",
"||",
"(",
"is_array",
"(",
"$",
"element",
")",
"&&",
"empty",
"(",
"$",
"element",
")",
")",
")",
";",
"}",
")",
";",
"}"
] | To array.
@return array | [
"To",
"array",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Result/Aggregation.php#L292-L320 |
apisearch-io/php-client | Result/Aggregation.php | Aggregation.createFromArray | public static function createFromArray(array $array): self
{
$activeElements = [];
foreach (($array['active_elements'] ?? []) as $activeElement) {
$activeElements[] = is_array($activeElement)
? Counter::createFromArray($activeElement)
: $activeElement;
}
$aggregation = new self(
$array['name'],
(int) ($array['application_type'] ?? Filter::AT_LEAST_ONE),
(int) ($array['total_elements'] ?? 0),
[]
);
$aggregation->activeElements = $activeElements;
$counters = array_map(function (array $counter) {
return Counter::createFromArray($counter);
}, $array['counters'] ?? []);
foreach ($counters as $counter) {
$aggregation->counters[$counter->getId()] = $counter;
}
$aggregation->highestActiveLevel = $array['highest_active_level'] ?? 0;
return $aggregation;
} | php | public static function createFromArray(array $array): self
{
$activeElements = [];
foreach (($array['active_elements'] ?? []) as $activeElement) {
$activeElements[] = is_array($activeElement)
? Counter::createFromArray($activeElement)
: $activeElement;
}
$aggregation = new self(
$array['name'],
(int) ($array['application_type'] ?? Filter::AT_LEAST_ONE),
(int) ($array['total_elements'] ?? 0),
[]
);
$aggregation->activeElements = $activeElements;
$counters = array_map(function (array $counter) {
return Counter::createFromArray($counter);
}, $array['counters'] ?? []);
foreach ($counters as $counter) {
$aggregation->counters[$counter->getId()] = $counter;
}
$aggregation->highestActiveLevel = $array['highest_active_level'] ?? 0;
return $aggregation;
} | [
"public",
"static",
"function",
"createFromArray",
"(",
"array",
"$",
"array",
")",
":",
"self",
"{",
"$",
"activeElements",
"=",
"[",
"]",
";",
"foreach",
"(",
"(",
"$",
"array",
"[",
"'active_elements'",
"]",
"??",
"[",
"]",
")",
"as",
"$",
"activeElement",
")",
"{",
"$",
"activeElements",
"[",
"]",
"=",
"is_array",
"(",
"$",
"activeElement",
")",
"?",
"Counter",
"::",
"createFromArray",
"(",
"$",
"activeElement",
")",
":",
"$",
"activeElement",
";",
"}",
"$",
"aggregation",
"=",
"new",
"self",
"(",
"$",
"array",
"[",
"'name'",
"]",
",",
"(",
"int",
")",
"(",
"$",
"array",
"[",
"'application_type'",
"]",
"??",
"Filter",
"::",
"AT_LEAST_ONE",
")",
",",
"(",
"int",
")",
"(",
"$",
"array",
"[",
"'total_elements'",
"]",
"??",
"0",
")",
",",
"[",
"]",
")",
";",
"$",
"aggregation",
"->",
"activeElements",
"=",
"$",
"activeElements",
";",
"$",
"counters",
"=",
"array_map",
"(",
"function",
"(",
"array",
"$",
"counter",
")",
"{",
"return",
"Counter",
"::",
"createFromArray",
"(",
"$",
"counter",
")",
";",
"}",
",",
"$",
"array",
"[",
"'counters'",
"]",
"??",
"[",
"]",
")",
";",
"foreach",
"(",
"$",
"counters",
"as",
"$",
"counter",
")",
"{",
"$",
"aggregation",
"->",
"counters",
"[",
"$",
"counter",
"->",
"getId",
"(",
")",
"]",
"=",
"$",
"counter",
";",
"}",
"$",
"aggregation",
"->",
"highestActiveLevel",
"=",
"$",
"array",
"[",
"'highest_active_level'",
"]",
"??",
"0",
";",
"return",
"$",
"aggregation",
";",
"}"
] | Create from array.
@param array $array
@return self | [
"Create",
"from",
"array",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Result/Aggregation.php#L329-L355 |
apisearch-io/php-client | User/HttpUserRepository.php | HttpUserRepository.addInteraction | public function addInteraction(Interaction $interaction)
{
$response = $this
->httpClient
->get(
sprintf(
'/%s/interactions',
$this->getAppUUID()->composeUUID()
),
'post',
[],
$interaction->toArray(),
Http::getApisearchHeaders($this)
);
self::throwTransportableExceptionIfNeeded($response);
} | php | public function addInteraction(Interaction $interaction)
{
$response = $this
->httpClient
->get(
sprintf(
'/%s/interactions',
$this->getAppUUID()->composeUUID()
),
'post',
[],
$interaction->toArray(),
Http::getApisearchHeaders($this)
);
self::throwTransportableExceptionIfNeeded($response);
} | [
"public",
"function",
"addInteraction",
"(",
"Interaction",
"$",
"interaction",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"httpClient",
"->",
"get",
"(",
"sprintf",
"(",
"'/%s/interactions'",
",",
"$",
"this",
"->",
"getAppUUID",
"(",
")",
"->",
"composeUUID",
"(",
")",
")",
",",
"'post'",
",",
"[",
"]",
",",
"$",
"interaction",
"->",
"toArray",
"(",
")",
",",
"Http",
"::",
"getApisearchHeaders",
"(",
"$",
"this",
")",
")",
";",
"self",
"::",
"throwTransportableExceptionIfNeeded",
"(",
"$",
"response",
")",
";",
"}"
] | Add interaction.
@param Interaction $interaction | [
"Add",
"interaction",
"."
] | train | https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/User/HttpUserRepository.php#L31-L47 |
palantirnet/the-build | src/TheBuild/ForeachKeyTask.php | ForeachKeyTask.main | public function main() {
$this->validate();
$this->callee->setTarget($this->target);
$this->callee->setInheritAll(true);
$this->callee->setInheritRefs(true);
// Extract matching keys from the properties array.
$keys = [];
$project = $this->getProject();
foreach ($project->getProperties() as $name => $value) {
if (strpos($name, $this->prefix) === 0) {
$property_children = substr($name, strlen($this->prefix));
list($key, $property_grandchildren) = explode('.', $property_children, 2);
$keys[$key] = $key;
}
}
// Remove keys based on the 'omitKeys' attribute.
$keys = array_diff($keys, $this->omitKeys);
// Iterate over each extracted key.
foreach ($keys as $key => $prefix) {
$prop = $this->callee->createProperty();
$prop->setOverride(true);
$prop->setName($this->keyParam);
$prop->setValue($key);
$prop = $this->callee->createProperty();
$prop->setOverride(true);
$prop->setName($this->prefixParam);
$prop->setValue($this->prefix);
$this->callee->main();
}
} | php | public function main() {
$this->validate();
$this->callee->setTarget($this->target);
$this->callee->setInheritAll(true);
$this->callee->setInheritRefs(true);
// Extract matching keys from the properties array.
$keys = [];
$project = $this->getProject();
foreach ($project->getProperties() as $name => $value) {
if (strpos($name, $this->prefix) === 0) {
$property_children = substr($name, strlen($this->prefix));
list($key, $property_grandchildren) = explode('.', $property_children, 2);
$keys[$key] = $key;
}
}
// Remove keys based on the 'omitKeys' attribute.
$keys = array_diff($keys, $this->omitKeys);
// Iterate over each extracted key.
foreach ($keys as $key => $prefix) {
$prop = $this->callee->createProperty();
$prop->setOverride(true);
$prop->setName($this->keyParam);
$prop->setValue($key);
$prop = $this->callee->createProperty();
$prop->setOverride(true);
$prop->setName($this->prefixParam);
$prop->setValue($this->prefix);
$this->callee->main();
}
} | [
"public",
"function",
"main",
"(",
")",
"{",
"$",
"this",
"->",
"validate",
"(",
")",
";",
"$",
"this",
"->",
"callee",
"->",
"setTarget",
"(",
"$",
"this",
"->",
"target",
")",
";",
"$",
"this",
"->",
"callee",
"->",
"setInheritAll",
"(",
"true",
")",
";",
"$",
"this",
"->",
"callee",
"->",
"setInheritRefs",
"(",
"true",
")",
";",
"// Extract matching keys from the properties array.",
"$",
"keys",
"=",
"[",
"]",
";",
"$",
"project",
"=",
"$",
"this",
"->",
"getProject",
"(",
")",
";",
"foreach",
"(",
"$",
"project",
"->",
"getProperties",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"prefix",
")",
"===",
"0",
")",
"{",
"$",
"property_children",
"=",
"substr",
"(",
"$",
"name",
",",
"strlen",
"(",
"$",
"this",
"->",
"prefix",
")",
")",
";",
"list",
"(",
"$",
"key",
",",
"$",
"property_grandchildren",
")",
"=",
"explode",
"(",
"'.'",
",",
"$",
"property_children",
",",
"2",
")",
";",
"$",
"keys",
"[",
"$",
"key",
"]",
"=",
"$",
"key",
";",
"}",
"}",
"// Remove keys based on the 'omitKeys' attribute.",
"$",
"keys",
"=",
"array_diff",
"(",
"$",
"keys",
",",
"$",
"this",
"->",
"omitKeys",
")",
";",
"// Iterate over each extracted key.",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
"=>",
"$",
"prefix",
")",
"{",
"$",
"prop",
"=",
"$",
"this",
"->",
"callee",
"->",
"createProperty",
"(",
")",
";",
"$",
"prop",
"->",
"setOverride",
"(",
"true",
")",
";",
"$",
"prop",
"->",
"setName",
"(",
"$",
"this",
"->",
"keyParam",
")",
";",
"$",
"prop",
"->",
"setValue",
"(",
"$",
"key",
")",
";",
"$",
"prop",
"=",
"$",
"this",
"->",
"callee",
"->",
"createProperty",
"(",
")",
";",
"$",
"prop",
"->",
"setOverride",
"(",
"true",
")",
";",
"$",
"prop",
"->",
"setName",
"(",
"$",
"this",
"->",
"prefixParam",
")",
";",
"$",
"prop",
"->",
"setValue",
"(",
"$",
"this",
"->",
"prefix",
")",
";",
"$",
"this",
"->",
"callee",
"->",
"main",
"(",
")",
";",
"}",
"}"
] | Copy properties. | [
"Copy",
"properties",
"."
] | train | https://github.com/palantirnet/the-build/blob/5d38721bf14c2db482acc731c012e9c8ba248c7d/src/TheBuild/ForeachKeyTask.php#L72-L107 |
palantirnet/the-build | src/TheBuild/CopyPropertiesTask.php | CopyPropertiesTask.main | public function main() {
$this->validate();
// Use either Project::setProperty() or Project::setNewProperty() based on
// whether we're overriding values or not.
$this->propertyMethod = $this->override ? 'setProperty' : 'setNewProperty';
$project = $this->getProject();
foreach ($project->getProperties() as $name => $value) {
if (strpos($name, $this->fromPrefix) === 0) {
$new_name = $this->toPrefix . substr($name, strlen($this->fromPrefix));
$project->{$this->propertyMethod}($new_name, $value);
}
}
} | php | public function main() {
$this->validate();
// Use either Project::setProperty() or Project::setNewProperty() based on
// whether we're overriding values or not.
$this->propertyMethod = $this->override ? 'setProperty' : 'setNewProperty';
$project = $this->getProject();
foreach ($project->getProperties() as $name => $value) {
if (strpos($name, $this->fromPrefix) === 0) {
$new_name = $this->toPrefix . substr($name, strlen($this->fromPrefix));
$project->{$this->propertyMethod}($new_name, $value);
}
}
} | [
"public",
"function",
"main",
"(",
")",
"{",
"$",
"this",
"->",
"validate",
"(",
")",
";",
"// Use either Project::setProperty() or Project::setNewProperty() based on",
"// whether we're overriding values or not.",
"$",
"this",
"->",
"propertyMethod",
"=",
"$",
"this",
"->",
"override",
"?",
"'setProperty'",
":",
"'setNewProperty'",
";",
"$",
"project",
"=",
"$",
"this",
"->",
"getProject",
"(",
")",
";",
"foreach",
"(",
"$",
"project",
"->",
"getProperties",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"fromPrefix",
")",
"===",
"0",
")",
"{",
"$",
"new_name",
"=",
"$",
"this",
"->",
"toPrefix",
".",
"substr",
"(",
"$",
"name",
",",
"strlen",
"(",
"$",
"this",
"->",
"fromPrefix",
")",
")",
";",
"$",
"project",
"->",
"{",
"$",
"this",
"->",
"propertyMethod",
"}",
"(",
"$",
"new_name",
",",
"$",
"value",
")",
";",
"}",
"}",
"}"
] | Copy properties. | [
"Copy",
"properties",
"."
] | train | https://github.com/palantirnet/the-build/blob/5d38721bf14c2db482acc731c012e9c8ba248c7d/src/TheBuild/CopyPropertiesTask.php#L49-L63 |
palantirnet/the-build | src/TheBuild/CopyPropertiesTask.php | CopyPropertiesTask.validate | public function validate() {
if (empty($this->fromPrefix)) {
throw new BuildException("fromPrefix attribute is required.", $this->location);
}
if (empty($this->toPrefix)) {
throw new BuildException("toPrefix attribute is required.", $this->location);
}
} | php | public function validate() {
if (empty($this->fromPrefix)) {
throw new BuildException("fromPrefix attribute is required.", $this->location);
}
if (empty($this->toPrefix)) {
throw new BuildException("toPrefix attribute is required.", $this->location);
}
} | [
"public",
"function",
"validate",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"fromPrefix",
")",
")",
"{",
"throw",
"new",
"BuildException",
"(",
"\"fromPrefix attribute is required.\"",
",",
"$",
"this",
"->",
"location",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"toPrefix",
")",
")",
"{",
"throw",
"new",
"BuildException",
"(",
"\"toPrefix attribute is required.\"",
",",
"$",
"this",
"->",
"location",
")",
";",
"}",
"}"
] | Verify that the required attributes are set. | [
"Verify",
"that",
"the",
"required",
"attributes",
"are",
"set",
"."
] | train | https://github.com/palantirnet/the-build/blob/5d38721bf14c2db482acc731c012e9c8ba248c7d/src/TheBuild/CopyPropertiesTask.php#L69-L77 |
palantirnet/the-build | src/TheBuild/SelectPropertyKeyTask.php | SelectPropertyKeyTask.main | public function main() {
$this->validate();
$project = $this->getProject();
if ($existing_value = $this->project->getProperty($this->propertyName)) {
$this->log("Using {$this->propertyName} = '{$existing_value}' (existing value)", Project::MSG_INFO);
return;
}
// Extract matching keys from the properties array.
$keys = [];
foreach ($project->getProperties() as $name => $value) {
if (strpos($name, $this->prefix) === 0) {
$property_children = substr($name, strlen($this->prefix));
list($key, $property_grandchildren) = explode('.', $property_children, 2);
$keys[$key] = $key;
}
}
// Remove keys based on the 'omitKeys' attribute.
$keys = array_diff($keys, $this->omitKeys);
if (count($keys) > 1) {
// Prompt for input.
$request = new MenuInputRequest($this->message);
$request->setOptions($keys);
$this->project->getInputHandler()->handleInput($request);
$value = $request->getInput();
}
elseif (count($keys) == 1) {
$value = current($keys);
$this->log("Using {$this->propertyName} = '{$value}' (one value found)", Project::MSG_INFO);
}
else {
$this->log("No properties found with prefix '{$this->prefix}'", Project::MSG_WARN);
}
if ($value) {
$project->setNewProperty($this->propertyName, $value);
}
} | php | public function main() {
$this->validate();
$project = $this->getProject();
if ($existing_value = $this->project->getProperty($this->propertyName)) {
$this->log("Using {$this->propertyName} = '{$existing_value}' (existing value)", Project::MSG_INFO);
return;
}
// Extract matching keys from the properties array.
$keys = [];
foreach ($project->getProperties() as $name => $value) {
if (strpos($name, $this->prefix) === 0) {
$property_children = substr($name, strlen($this->prefix));
list($key, $property_grandchildren) = explode('.', $property_children, 2);
$keys[$key] = $key;
}
}
// Remove keys based on the 'omitKeys' attribute.
$keys = array_diff($keys, $this->omitKeys);
if (count($keys) > 1) {
// Prompt for input.
$request = new MenuInputRequest($this->message);
$request->setOptions($keys);
$this->project->getInputHandler()->handleInput($request);
$value = $request->getInput();
}
elseif (count($keys) == 1) {
$value = current($keys);
$this->log("Using {$this->propertyName} = '{$value}' (one value found)", Project::MSG_INFO);
}
else {
$this->log("No properties found with prefix '{$this->prefix}'", Project::MSG_WARN);
}
if ($value) {
$project->setNewProperty($this->propertyName, $value);
}
} | [
"public",
"function",
"main",
"(",
")",
"{",
"$",
"this",
"->",
"validate",
"(",
")",
";",
"$",
"project",
"=",
"$",
"this",
"->",
"getProject",
"(",
")",
";",
"if",
"(",
"$",
"existing_value",
"=",
"$",
"this",
"->",
"project",
"->",
"getProperty",
"(",
"$",
"this",
"->",
"propertyName",
")",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"\"Using {$this->propertyName} = '{$existing_value}' (existing value)\"",
",",
"Project",
"::",
"MSG_INFO",
")",
";",
"return",
";",
"}",
"// Extract matching keys from the properties array.",
"$",
"keys",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"project",
"->",
"getProperties",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"prefix",
")",
"===",
"0",
")",
"{",
"$",
"property_children",
"=",
"substr",
"(",
"$",
"name",
",",
"strlen",
"(",
"$",
"this",
"->",
"prefix",
")",
")",
";",
"list",
"(",
"$",
"key",
",",
"$",
"property_grandchildren",
")",
"=",
"explode",
"(",
"'.'",
",",
"$",
"property_children",
",",
"2",
")",
";",
"$",
"keys",
"[",
"$",
"key",
"]",
"=",
"$",
"key",
";",
"}",
"}",
"// Remove keys based on the 'omitKeys' attribute.",
"$",
"keys",
"=",
"array_diff",
"(",
"$",
"keys",
",",
"$",
"this",
"->",
"omitKeys",
")",
";",
"if",
"(",
"count",
"(",
"$",
"keys",
")",
">",
"1",
")",
"{",
"// Prompt for input.",
"$",
"request",
"=",
"new",
"MenuInputRequest",
"(",
"$",
"this",
"->",
"message",
")",
";",
"$",
"request",
"->",
"setOptions",
"(",
"$",
"keys",
")",
";",
"$",
"this",
"->",
"project",
"->",
"getInputHandler",
"(",
")",
"->",
"handleInput",
"(",
"$",
"request",
")",
";",
"$",
"value",
"=",
"$",
"request",
"->",
"getInput",
"(",
")",
";",
"}",
"elseif",
"(",
"count",
"(",
"$",
"keys",
")",
"==",
"1",
")",
"{",
"$",
"value",
"=",
"current",
"(",
"$",
"keys",
")",
";",
"$",
"this",
"->",
"log",
"(",
"\"Using {$this->propertyName} = '{$value}' (one value found)\"",
",",
"Project",
"::",
"MSG_INFO",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"log",
"(",
"\"No properties found with prefix '{$this->prefix}'\"",
",",
"Project",
"::",
"MSG_WARN",
")",
";",
"}",
"if",
"(",
"$",
"value",
")",
"{",
"$",
"project",
"->",
"setNewProperty",
"(",
"$",
"this",
"->",
"propertyName",
",",
"$",
"value",
")",
";",
"}",
"}"
] | Copy properties. | [
"Copy",
"properties",
"."
] | train | https://github.com/palantirnet/the-build/blob/5d38721bf14c2db482acc731c012e9c8ba248c7d/src/TheBuild/SelectPropertyKeyTask.php#L57-L99 |
palantirnet/the-build | src/TheBuild/IncludeResourceTask.php | IncludeResourceTask.init | public function init() {
$mode = $this->getProject()->getProperty('includeresource.mode');
if (!is_null($mode)) {
$this->setMode($mode);
}
} | php | public function init() {
$mode = $this->getProject()->getProperty('includeresource.mode');
if (!is_null($mode)) {
$this->setMode($mode);
}
} | [
"public",
"function",
"init",
"(",
")",
"{",
"$",
"mode",
"=",
"$",
"this",
"->",
"getProject",
"(",
")",
"->",
"getProperty",
"(",
"'includeresource.mode'",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"mode",
")",
")",
"{",
"$",
"this",
"->",
"setMode",
"(",
"$",
"mode",
")",
";",
"}",
"}"
] | Init tasks.
Inherits the mode from the project's includeresource.mode property. This
can be overridden by setting the "mode" attribute. | [
"Init",
"tasks",
"."
] | train | https://github.com/palantirnet/the-build/blob/5d38721bf14c2db482acc731c012e9c8ba248c7d/src/TheBuild/IncludeResourceTask.php#L42-L47 |
palantirnet/the-build | src/TheBuild/IncludeResourceTask.php | IncludeResourceTask.main | public function main() {
$this->validate();
// Remove existing destination first.
if ($this->dest->exists()) {
$this->log("Replacing existing resource '" . $this->dest->getPath() . "'");
if ($this->dest->delete(TRUE) === FALSE) {
throw new BuildException("Failed to delete existing destination '$this->dest'");
}
}
// Link or copy the source artifact.
$this->dest->getParentFile()->mkdirs();
if ($this->mode == 'copy') {
$this->log(sprintf("Copying '%s' to '%s'", $this->source->getPath(), $this->dest->getPath()));
$this->source->copyTo($this->dest);
}
else {
$this->log(sprintf("Linking '%s' to '%s'", $this->source->getPath(), $this->dest->getPath()));
FileSystem::getFileSystem()->symlink($this->source->getPath(), $this->dest->getPath());
}
} | php | public function main() {
$this->validate();
// Remove existing destination first.
if ($this->dest->exists()) {
$this->log("Replacing existing resource '" . $this->dest->getPath() . "'");
if ($this->dest->delete(TRUE) === FALSE) {
throw new BuildException("Failed to delete existing destination '$this->dest'");
}
}
// Link or copy the source artifact.
$this->dest->getParentFile()->mkdirs();
if ($this->mode == 'copy') {
$this->log(sprintf("Copying '%s' to '%s'", $this->source->getPath(), $this->dest->getPath()));
$this->source->copyTo($this->dest);
}
else {
$this->log(sprintf("Linking '%s' to '%s'", $this->source->getPath(), $this->dest->getPath()));
FileSystem::getFileSystem()->symlink($this->source->getPath(), $this->dest->getPath());
}
} | [
"public",
"function",
"main",
"(",
")",
"{",
"$",
"this",
"->",
"validate",
"(",
")",
";",
"// Remove existing destination first.",
"if",
"(",
"$",
"this",
"->",
"dest",
"->",
"exists",
"(",
")",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"\"Replacing existing resource '\"",
".",
"$",
"this",
"->",
"dest",
"->",
"getPath",
"(",
")",
".",
"\"'\"",
")",
";",
"if",
"(",
"$",
"this",
"->",
"dest",
"->",
"delete",
"(",
"TRUE",
")",
"===",
"FALSE",
")",
"{",
"throw",
"new",
"BuildException",
"(",
"\"Failed to delete existing destination '$this->dest'\"",
")",
";",
"}",
"}",
"// Link or copy the source artifact.",
"$",
"this",
"->",
"dest",
"->",
"getParentFile",
"(",
")",
"->",
"mkdirs",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"mode",
"==",
"'copy'",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"sprintf",
"(",
"\"Copying '%s' to '%s'\"",
",",
"$",
"this",
"->",
"source",
"->",
"getPath",
"(",
")",
",",
"$",
"this",
"->",
"dest",
"->",
"getPath",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"source",
"->",
"copyTo",
"(",
"$",
"this",
"->",
"dest",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"log",
"(",
"sprintf",
"(",
"\"Linking '%s' to '%s'\"",
",",
"$",
"this",
"->",
"source",
"->",
"getPath",
"(",
")",
",",
"$",
"this",
"->",
"dest",
"->",
"getPath",
"(",
")",
")",
")",
";",
"FileSystem",
"::",
"getFileSystem",
"(",
")",
"->",
"symlink",
"(",
"$",
"this",
"->",
"source",
"->",
"getPath",
"(",
")",
",",
"$",
"this",
"->",
"dest",
"->",
"getPath",
"(",
")",
")",
";",
"}",
"}"
] | Copy or link the resource. | [
"Copy",
"or",
"link",
"the",
"resource",
"."
] | train | https://github.com/palantirnet/the-build/blob/5d38721bf14c2db482acc731c012e9c8ba248c7d/src/TheBuild/IncludeResourceTask.php#L53-L75 |
palantirnet/the-build | src/TheBuild/IncludeResourceTask.php | IncludeResourceTask.validate | public function validate() {
if (!in_array($this->mode, ['symlink', 'copy'])) {
throw new BuildException("mode attribute must be either 'symlink' or 'copy'", $this->location);
}
if (empty($this->source) || empty($this->dest)) {
throw new BuildException("Both the 'source' and 'dest' attributes are required.");
}
} | php | public function validate() {
if (!in_array($this->mode, ['symlink', 'copy'])) {
throw new BuildException("mode attribute must be either 'symlink' or 'copy'", $this->location);
}
if (empty($this->source) || empty($this->dest)) {
throw new BuildException("Both the 'source' and 'dest' attributes are required.");
}
} | [
"public",
"function",
"validate",
"(",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"this",
"->",
"mode",
",",
"[",
"'symlink'",
",",
"'copy'",
"]",
")",
")",
"{",
"throw",
"new",
"BuildException",
"(",
"\"mode attribute must be either 'symlink' or 'copy'\"",
",",
"$",
"this",
"->",
"location",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"source",
")",
"||",
"empty",
"(",
"$",
"this",
"->",
"dest",
")",
")",
"{",
"throw",
"new",
"BuildException",
"(",
"\"Both the 'source' and 'dest' attributes are required.\"",
")",
";",
"}",
"}"
] | Verify that the required attributes are set. | [
"Verify",
"that",
"the",
"required",
"attributes",
"are",
"set",
"."
] | train | https://github.com/palantirnet/the-build/blob/5d38721bf14c2db482acc731c012e9c8ba248c7d/src/TheBuild/IncludeResourceTask.php#L81-L89 |
palantirnet/the-build | src/TheBuild/Acquia/AcquiaTask.php | AcquiaTask.loadCredentials | protected function loadCredentials() {
if (empty($this->mail) || empty($this->key)) {
if (empty($this->credentialsFile)) {
$this->credentialsFile = new PhingFile($_SERVER['HOME'] . '/.acquia/cloudapi.conf');
}
if (!file_exists($this->credentialsFile) || !is_readable($this->credentialsFile)) {
throw new BuildException("Acquia Cloud credentials file '{$this->credentialsFile}' is not available.");
}
$contents = file_get_contents($this->credentialsFile);
$creds = json_decode($contents, TRUE);
$this->mail = $creds['mail'];
$this->key = $creds['key'];
}
if (empty($this->mail) || empty($this->key)) {
throw new BuildException('Missing Acquia Cloud API credentials.');
}
} | php | protected function loadCredentials() {
if (empty($this->mail) || empty($this->key)) {
if (empty($this->credentialsFile)) {
$this->credentialsFile = new PhingFile($_SERVER['HOME'] . '/.acquia/cloudapi.conf');
}
if (!file_exists($this->credentialsFile) || !is_readable($this->credentialsFile)) {
throw new BuildException("Acquia Cloud credentials file '{$this->credentialsFile}' is not available.");
}
$contents = file_get_contents($this->credentialsFile);
$creds = json_decode($contents, TRUE);
$this->mail = $creds['mail'];
$this->key = $creds['key'];
}
if (empty($this->mail) || empty($this->key)) {
throw new BuildException('Missing Acquia Cloud API credentials.');
}
} | [
"protected",
"function",
"loadCredentials",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"mail",
")",
"||",
"empty",
"(",
"$",
"this",
"->",
"key",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"credentialsFile",
")",
")",
"{",
"$",
"this",
"->",
"credentialsFile",
"=",
"new",
"PhingFile",
"(",
"$",
"_SERVER",
"[",
"'HOME'",
"]",
".",
"'/.acquia/cloudapi.conf'",
")",
";",
"}",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"credentialsFile",
")",
"||",
"!",
"is_readable",
"(",
"$",
"this",
"->",
"credentialsFile",
")",
")",
"{",
"throw",
"new",
"BuildException",
"(",
"\"Acquia Cloud credentials file '{$this->credentialsFile}' is not available.\"",
")",
";",
"}",
"$",
"contents",
"=",
"file_get_contents",
"(",
"$",
"this",
"->",
"credentialsFile",
")",
";",
"$",
"creds",
"=",
"json_decode",
"(",
"$",
"contents",
",",
"TRUE",
")",
";",
"$",
"this",
"->",
"mail",
"=",
"$",
"creds",
"[",
"'mail'",
"]",
";",
"$",
"this",
"->",
"key",
"=",
"$",
"creds",
"[",
"'key'",
"]",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"mail",
")",
"||",
"empty",
"(",
"$",
"this",
"->",
"key",
")",
")",
"{",
"throw",
"new",
"BuildException",
"(",
"'Missing Acquia Cloud API credentials.'",
")",
";",
"}",
"}"
] | Load the Acquia Cloud credentials from the cloudapi.conf JSON file.
@throws \IOException
@throws \NullPointerException | [
"Load",
"the",
"Acquia",
"Cloud",
"credentials",
"from",
"the",
"cloudapi",
".",
"conf",
"JSON",
"file",
"."
] | train | https://github.com/palantirnet/the-build/blob/5d38721bf14c2db482acc731c012e9c8ba248c7d/src/TheBuild/Acquia/AcquiaTask.php#L65-L85 |
palantirnet/the-build | src/TheBuild/Acquia/AcquiaTask.php | AcquiaTask.createRequest | protected function createRequest($path) {
$this->loadCredentials();
$uri = $this->endpoint . '/' . ltrim($path, '/');
$request = new HTTP_Request2($uri);
$request->setConfig('follow_redirects', TRUE);
$request->setAuth($this->mail, $this->key);
return $request;
} | php | protected function createRequest($path) {
$this->loadCredentials();
$uri = $this->endpoint . '/' . ltrim($path, '/');
$request = new HTTP_Request2($uri);
$request->setConfig('follow_redirects', TRUE);
$request->setAuth($this->mail, $this->key);
return $request;
} | [
"protected",
"function",
"createRequest",
"(",
"$",
"path",
")",
"{",
"$",
"this",
"->",
"loadCredentials",
"(",
")",
";",
"$",
"uri",
"=",
"$",
"this",
"->",
"endpoint",
".",
"'/'",
".",
"ltrim",
"(",
"$",
"path",
",",
"'/'",
")",
";",
"$",
"request",
"=",
"new",
"HTTP_Request2",
"(",
"$",
"uri",
")",
";",
"$",
"request",
"->",
"setConfig",
"(",
"'follow_redirects'",
",",
"TRUE",
")",
";",
"$",
"request",
"->",
"setAuth",
"(",
"$",
"this",
"->",
"mail",
",",
"$",
"this",
"->",
"key",
")",
";",
"return",
"$",
"request",
";",
"}"
] | Build an HTTP request object against the Acquia Cloud API.
@param $path
@return HTTP_Request2 | [
"Build",
"an",
"HTTP",
"request",
"object",
"against",
"the",
"Acquia",
"Cloud",
"API",
"."
] | train | https://github.com/palantirnet/the-build/blob/5d38721bf14c2db482acc731c012e9c8ba248c7d/src/TheBuild/Acquia/AcquiaTask.php#L93-L103 |
palantirnet/the-build | src/TheBuild/Acquia/AcquiaTask.php | AcquiaTask.getApiResponseBody | protected function getApiResponseBody($path) {
$request = $this->createRequest($path);
$this->log('GET ' . $request->getUrl());
$response = $request->send();
return $response->getBody();
} | php | protected function getApiResponseBody($path) {
$request = $this->createRequest($path);
$this->log('GET ' . $request->getUrl());
$response = $request->send();
return $response->getBody();
} | [
"protected",
"function",
"getApiResponseBody",
"(",
"$",
"path",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"createRequest",
"(",
"$",
"path",
")",
";",
"$",
"this",
"->",
"log",
"(",
"'GET '",
".",
"$",
"request",
"->",
"getUrl",
"(",
")",
")",
";",
"$",
"response",
"=",
"$",
"request",
"->",
"send",
"(",
")",
";",
"return",
"$",
"response",
"->",
"getBody",
"(",
")",
";",
"}"
] | Example of how to query the Acquia Cloud API.
@param $path
@return string
@throws \HTTP_Request2_Exception | [
"Example",
"of",
"how",
"to",
"query",
"the",
"Acquia",
"Cloud",
"API",
"."
] | train | https://github.com/palantirnet/the-build/blob/5d38721bf14c2db482acc731c012e9c8ba248c7d/src/TheBuild/Acquia/AcquiaTask.php#L112-L118 |
palantirnet/the-build | src/TheBuild/SelectOneTask.php | SelectOneTask.main | public function main() {
$this->validate();
$project = $this->getProject();
if ($existing_value = $this->project->getProperty($this->propertyName)) {
$this->log("Using {$this->propertyName} = '{$existing_value}' (existing value)", Project::MSG_INFO);
return;
}
$keys = array_map('trim', explode($this->delimiter, $this->list));
if (count($keys) > 1) {
// Prompt for input.
$request = new MenuInputRequest($this->message);
$request->setOptions($keys);
$this->project->getInputHandler()->handleInput($request);
$value = $request->getInput();
}
elseif (count($keys) == 1) {
$value = current($keys);
$this->log("Using {$this->propertyName} = '{$value}' (one value found)", Project::MSG_INFO);
}
if ($value) {
$project->setNewProperty($this->propertyName, $value);
}
} | php | public function main() {
$this->validate();
$project = $this->getProject();
if ($existing_value = $this->project->getProperty($this->propertyName)) {
$this->log("Using {$this->propertyName} = '{$existing_value}' (existing value)", Project::MSG_INFO);
return;
}
$keys = array_map('trim', explode($this->delimiter, $this->list));
if (count($keys) > 1) {
// Prompt for input.
$request = new MenuInputRequest($this->message);
$request->setOptions($keys);
$this->project->getInputHandler()->handleInput($request);
$value = $request->getInput();
}
elseif (count($keys) == 1) {
$value = current($keys);
$this->log("Using {$this->propertyName} = '{$value}' (one value found)", Project::MSG_INFO);
}
if ($value) {
$project->setNewProperty($this->propertyName, $value);
}
} | [
"public",
"function",
"main",
"(",
")",
"{",
"$",
"this",
"->",
"validate",
"(",
")",
";",
"$",
"project",
"=",
"$",
"this",
"->",
"getProject",
"(",
")",
";",
"if",
"(",
"$",
"existing_value",
"=",
"$",
"this",
"->",
"project",
"->",
"getProperty",
"(",
"$",
"this",
"->",
"propertyName",
")",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"\"Using {$this->propertyName} = '{$existing_value}' (existing value)\"",
",",
"Project",
"::",
"MSG_INFO",
")",
";",
"return",
";",
"}",
"$",
"keys",
"=",
"array_map",
"(",
"'trim'",
",",
"explode",
"(",
"$",
"this",
"->",
"delimiter",
",",
"$",
"this",
"->",
"list",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"keys",
")",
">",
"1",
")",
"{",
"// Prompt for input.",
"$",
"request",
"=",
"new",
"MenuInputRequest",
"(",
"$",
"this",
"->",
"message",
")",
";",
"$",
"request",
"->",
"setOptions",
"(",
"$",
"keys",
")",
";",
"$",
"this",
"->",
"project",
"->",
"getInputHandler",
"(",
")",
"->",
"handleInput",
"(",
"$",
"request",
")",
";",
"$",
"value",
"=",
"$",
"request",
"->",
"getInput",
"(",
")",
";",
"}",
"elseif",
"(",
"count",
"(",
"$",
"keys",
")",
"==",
"1",
")",
"{",
"$",
"value",
"=",
"current",
"(",
"$",
"keys",
")",
";",
"$",
"this",
"->",
"log",
"(",
"\"Using {$this->propertyName} = '{$value}' (one value found)\"",
",",
"Project",
"::",
"MSG_INFO",
")",
";",
"}",
"if",
"(",
"$",
"value",
")",
"{",
"$",
"project",
"->",
"setNewProperty",
"(",
"$",
"this",
"->",
"propertyName",
",",
"$",
"value",
")",
";",
"}",
"}"
] | Select menu. | [
"Select",
"menu",
"."
] | train | https://github.com/palantirnet/the-build/blob/5d38721bf14c2db482acc731c012e9c8ba248c7d/src/TheBuild/SelectOneTask.php#L58-L87 |
cartalyst/collections | src/Collection.php | Collection.first | public function first(Closure $callback = null, $default = null)
{
return count($this->items) > 0 ? reset($this->items) : null;
} | php | public function first(Closure $callback = null, $default = null)
{
return count($this->items) > 0 ? reset($this->items) : null;
} | [
"public",
"function",
"first",
"(",
"Closure",
"$",
"callback",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"return",
"count",
"(",
"$",
"this",
"->",
"items",
")",
">",
"0",
"?",
"reset",
"(",
"$",
"this",
"->",
"items",
")",
":",
"null",
";",
"}"
] | Get the first item from the collection.
@param \Closure $callback
@param mixed $default
@return mixed|null | [
"Get",
"the",
"first",
"item",
"from",
"the",
"collection",
"."
] | train | https://github.com/cartalyst/collections/blob/1a457cac7689386ca0fa09ee13e12a2fc9e370c6/src/Collection.php#L88-L91 |
cartalyst/collections | src/Collection.php | Collection.lists | public function lists($value)
{
return array_map(function ($item) use ($value) {
return isset($item[$value]) ? $item[$value] : null;
}, $this->items);
} | php | public function lists($value)
{
return array_map(function ($item) use ($value) {
return isset($item[$value]) ? $item[$value] : null;
}, $this->items);
} | [
"public",
"function",
"lists",
"(",
"$",
"value",
")",
"{",
"return",
"array_map",
"(",
"function",
"(",
"$",
"item",
")",
"use",
"(",
"$",
"value",
")",
"{",
"return",
"isset",
"(",
"$",
"item",
"[",
"$",
"value",
"]",
")",
"?",
"$",
"item",
"[",
"$",
"value",
"]",
":",
"null",
";",
"}",
",",
"$",
"this",
"->",
"items",
")",
";",
"}"
] | Get an array with the values of a given key.
@param string $value
@return array | [
"Get",
"an",
"array",
"with",
"the",
"values",
"of",
"a",
"given",
"key",
"."
] | train | https://github.com/cartalyst/collections/blob/1a457cac7689386ca0fa09ee13e12a2fc9e370c6/src/Collection.php#L157-L162 |
cartalyst/collections | src/Collection.php | Collection.pull | public function pull($key, $default = null)
{
$value = $this->offsetGet($key);
$this->offsetUnset($key);
return $value ?: $default;
} | php | public function pull($key, $default = null)
{
$value = $this->offsetGet($key);
$this->offsetUnset($key);
return $value ?: $default;
} | [
"public",
"function",
"pull",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"offsetGet",
"(",
"$",
"key",
")",
";",
"$",
"this",
"->",
"offsetUnset",
"(",
"$",
"key",
")",
";",
"return",
"$",
"value",
"?",
":",
"$",
"default",
";",
"}"
] | Pulls an item from the collection.
@param mixed $key
@param mixed $default
@return mixed | [
"Pulls",
"an",
"item",
"from",
"the",
"collection",
"."
] | train | https://github.com/cartalyst/collections/blob/1a457cac7689386ca0fa09ee13e12a2fc9e370c6/src/Collection.php#L192-L199 |
cartalyst/collections | src/Collection.php | Collection.sum | public function sum($callback = null)
{
if (is_null($callback)) {
return array_sum($this->items);
}
return array_reduce($this->items, function ($result, $item) use ($callback) {
if (is_string($callback)) {
return $result += $item->{$callback}();
}
return $result += $callback($item);
}, 0);
} | php | public function sum($callback = null)
{
if (is_null($callback)) {
return array_sum($this->items);
}
return array_reduce($this->items, function ($result, $item) use ($callback) {
if (is_string($callback)) {
return $result += $item->{$callback}();
}
return $result += $callback($item);
}, 0);
} | [
"public",
"function",
"sum",
"(",
"$",
"callback",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"callback",
")",
")",
"{",
"return",
"array_sum",
"(",
"$",
"this",
"->",
"items",
")",
";",
"}",
"return",
"array_reduce",
"(",
"$",
"this",
"->",
"items",
",",
"function",
"(",
"$",
"result",
",",
"$",
"item",
")",
"use",
"(",
"$",
"callback",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"callback",
")",
")",
"{",
"return",
"$",
"result",
"+=",
"$",
"item",
"->",
"{",
"$",
"callback",
"}",
"(",
")",
";",
"}",
"return",
"$",
"result",
"+=",
"$",
"callback",
"(",
"$",
"item",
")",
";",
"}",
",",
"0",
")",
";",
"}"
] | Get the sum of the collection items.
@param mixed $callback
@return mixed | [
"Get",
"the",
"sum",
"of",
"the",
"collection",
"items",
"."
] | train | https://github.com/cartalyst/collections/blob/1a457cac7689386ca0fa09ee13e12a2fc9e370c6/src/Collection.php#L302-L315 |
yajra/laravel-datatables-buttons | src/Services/DataTable.php | DataTable.render | public function render($view, $data = [], $mergeData = [])
{
if ($this->request()->ajax() && $this->request()->wantsJson()) {
return app()->call([$this, 'ajax']);
}
if ($action = $this->request()->get('action') and in_array($action, $this->actions)) {
if ($action == 'print') {
return app()->call([$this, 'printPreview']);
}
return app()->call([$this, $action]);
}
return view($view, $data, $mergeData)->with($this->dataTableVariable, $this->getHtmlBuilder());
} | php | public function render($view, $data = [], $mergeData = [])
{
if ($this->request()->ajax() && $this->request()->wantsJson()) {
return app()->call([$this, 'ajax']);
}
if ($action = $this->request()->get('action') and in_array($action, $this->actions)) {
if ($action == 'print') {
return app()->call([$this, 'printPreview']);
}
return app()->call([$this, $action]);
}
return view($view, $data, $mergeData)->with($this->dataTableVariable, $this->getHtmlBuilder());
} | [
"public",
"function",
"render",
"(",
"$",
"view",
",",
"$",
"data",
"=",
"[",
"]",
",",
"$",
"mergeData",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"request",
"(",
")",
"->",
"ajax",
"(",
")",
"&&",
"$",
"this",
"->",
"request",
"(",
")",
"->",
"wantsJson",
"(",
")",
")",
"{",
"return",
"app",
"(",
")",
"->",
"call",
"(",
"[",
"$",
"this",
",",
"'ajax'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"action",
"=",
"$",
"this",
"->",
"request",
"(",
")",
"->",
"get",
"(",
"'action'",
")",
"and",
"in_array",
"(",
"$",
"action",
",",
"$",
"this",
"->",
"actions",
")",
")",
"{",
"if",
"(",
"$",
"action",
"==",
"'print'",
")",
"{",
"return",
"app",
"(",
")",
"->",
"call",
"(",
"[",
"$",
"this",
",",
"'printPreview'",
"]",
")",
";",
"}",
"return",
"app",
"(",
")",
"->",
"call",
"(",
"[",
"$",
"this",
",",
"$",
"action",
"]",
")",
";",
"}",
"return",
"view",
"(",
"$",
"view",
",",
"$",
"data",
",",
"$",
"mergeData",
")",
"->",
"with",
"(",
"$",
"this",
"->",
"dataTableVariable",
",",
"$",
"this",
"->",
"getHtmlBuilder",
"(",
")",
")",
";",
"}"
] | Process dataTables needed render output.
@param string $view
@param array $data
@param array $mergeData
@return mixed | [
"Process",
"dataTables",
"needed",
"render",
"output",
"."
] | train | https://github.com/yajra/laravel-datatables-buttons/blob/291c129ab9db63e5ec5353336181e8c6a95e3e19/src/Services/DataTable.php#L155-L170 |
yajra/laravel-datatables-buttons | src/Services/DataTable.php | DataTable.ajax | public function ajax()
{
$source = null;
if (method_exists($this, 'query')) {
$source = app()->call([$this, 'query']);
$source = $this->applyScopes($source);
}
/** @var \Yajra\DataTables\DataTableAbstract $dataTable */
$dataTable = app()->call([$this, 'dataTable'], compact('source'));
if ($callback = $this->beforeCallback) {
$callback($dataTable);
}
if ($callback = $this->responseCallback) {
$data = new Collection($dataTable->toArray());
return new JsonResponse($callback($data));
}
return $dataTable->toJson();
} | php | public function ajax()
{
$source = null;
if (method_exists($this, 'query')) {
$source = app()->call([$this, 'query']);
$source = $this->applyScopes($source);
}
/** @var \Yajra\DataTables\DataTableAbstract $dataTable */
$dataTable = app()->call([$this, 'dataTable'], compact('source'));
if ($callback = $this->beforeCallback) {
$callback($dataTable);
}
if ($callback = $this->responseCallback) {
$data = new Collection($dataTable->toArray());
return new JsonResponse($callback($data));
}
return $dataTable->toJson();
} | [
"public",
"function",
"ajax",
"(",
")",
"{",
"$",
"source",
"=",
"null",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"'query'",
")",
")",
"{",
"$",
"source",
"=",
"app",
"(",
")",
"->",
"call",
"(",
"[",
"$",
"this",
",",
"'query'",
"]",
")",
";",
"$",
"source",
"=",
"$",
"this",
"->",
"applyScopes",
"(",
"$",
"source",
")",
";",
"}",
"/** @var \\Yajra\\DataTables\\DataTableAbstract $dataTable */",
"$",
"dataTable",
"=",
"app",
"(",
")",
"->",
"call",
"(",
"[",
"$",
"this",
",",
"'dataTable'",
"]",
",",
"compact",
"(",
"'source'",
")",
")",
";",
"if",
"(",
"$",
"callback",
"=",
"$",
"this",
"->",
"beforeCallback",
")",
"{",
"$",
"callback",
"(",
"$",
"dataTable",
")",
";",
"}",
"if",
"(",
"$",
"callback",
"=",
"$",
"this",
"->",
"responseCallback",
")",
"{",
"$",
"data",
"=",
"new",
"Collection",
"(",
"$",
"dataTable",
"->",
"toArray",
"(",
")",
")",
";",
"return",
"new",
"JsonResponse",
"(",
"$",
"callback",
"(",
"$",
"data",
")",
")",
";",
"}",
"return",
"$",
"dataTable",
"->",
"toJson",
"(",
")",
";",
"}"
] | Display ajax response.
@return \Illuminate\Http\JsonResponse | [
"Display",
"ajax",
"response",
"."
] | train | https://github.com/yajra/laravel-datatables-buttons/blob/291c129ab9db63e5ec5353336181e8c6a95e3e19/src/Services/DataTable.php#L187-L209 |
yajra/laravel-datatables-buttons | src/Services/DataTable.php | DataTable.printColumns | protected function printColumns()
{
return is_array($this->printColumns) ? $this->toColumnsCollection($this->printColumns) : $this->getPrintColumnsFromBuilder();
} | php | protected function printColumns()
{
return is_array($this->printColumns) ? $this->toColumnsCollection($this->printColumns) : $this->getPrintColumnsFromBuilder();
} | [
"protected",
"function",
"printColumns",
"(",
")",
"{",
"return",
"is_array",
"(",
"$",
"this",
"->",
"printColumns",
")",
"?",
"$",
"this",
"->",
"toColumnsCollection",
"(",
"$",
"this",
"->",
"printColumns",
")",
":",
"$",
"this",
"->",
"getPrintColumnsFromBuilder",
"(",
")",
";",
"}"
] | Get printable columns.
@return array|string | [
"Get",
"printable",
"columns",
"."
] | train | https://github.com/yajra/laravel-datatables-buttons/blob/291c129ab9db63e5ec5353336181e8c6a95e3e19/src/Services/DataTable.php#L240-L243 |
yajra/laravel-datatables-buttons | src/Services/DataTable.php | DataTable.mapResponseToColumns | protected function mapResponseToColumns($columns, $type)
{
$transformer = new DataArrayTransformer;
return array_map(function ($row) use ($columns, $type, $transformer) {
return $transformer->transform($row, $columns, $type);
}, $this->getAjaxResponseData());
} | php | protected function mapResponseToColumns($columns, $type)
{
$transformer = new DataArrayTransformer;
return array_map(function ($row) use ($columns, $type, $transformer) {
return $transformer->transform($row, $columns, $type);
}, $this->getAjaxResponseData());
} | [
"protected",
"function",
"mapResponseToColumns",
"(",
"$",
"columns",
",",
"$",
"type",
")",
"{",
"$",
"transformer",
"=",
"new",
"DataArrayTransformer",
";",
"return",
"array_map",
"(",
"function",
"(",
"$",
"row",
")",
"use",
"(",
"$",
"columns",
",",
"$",
"type",
",",
"$",
"transformer",
")",
"{",
"return",
"$",
"transformer",
"->",
"transform",
"(",
"$",
"row",
",",
"$",
"columns",
",",
"$",
"type",
")",
";",
"}",
",",
"$",
"this",
"->",
"getAjaxResponseData",
"(",
")",
")",
";",
"}"
] | Map ajax response to columns definition.
@param mixed $columns
@param string $type
@return array | [
"Map",
"ajax",
"response",
"to",
"columns",
"definition",
"."
] | train | https://github.com/yajra/laravel-datatables-buttons/blob/291c129ab9db63e5ec5353336181e8c6a95e3e19/src/Services/DataTable.php#L302-L309 |
yajra/laravel-datatables-buttons | src/Services/DataTable.php | DataTable.getAjaxResponseData | protected function getAjaxResponseData()
{
$this->request()->merge(['length' => -1]);
$response = app()->call([$this, 'ajax']);
$data = $response->getData(true);
return $data['data'];
} | php | protected function getAjaxResponseData()
{
$this->request()->merge(['length' => -1]);
$response = app()->call([$this, 'ajax']);
$data = $response->getData(true);
return $data['data'];
} | [
"protected",
"function",
"getAjaxResponseData",
"(",
")",
"{",
"$",
"this",
"->",
"request",
"(",
")",
"->",
"merge",
"(",
"[",
"'length'",
"=>",
"-",
"1",
"]",
")",
";",
"$",
"response",
"=",
"app",
"(",
")",
"->",
"call",
"(",
"[",
"$",
"this",
",",
"'ajax'",
"]",
")",
";",
"$",
"data",
"=",
"$",
"response",
"->",
"getData",
"(",
"true",
")",
";",
"return",
"$",
"data",
"[",
"'data'",
"]",
";",
"}"
] | Get decorated data as defined in datatables ajax response.
@return array | [
"Get",
"decorated",
"data",
"as",
"defined",
"in",
"datatables",
"ajax",
"response",
"."
] | train | https://github.com/yajra/laravel-datatables-buttons/blob/291c129ab9db63e5ec5353336181e8c6a95e3e19/src/Services/DataTable.php#L316-L324 |
yajra/laravel-datatables-buttons | src/Services/DataTable.php | DataTable.excel | public function excel()
{
$ext = '.' . strtolower($this->excelWriter);
return $this->buildExcelFile()->download($this->getFilename() . $ext, $this->excelWriter);
} | php | public function excel()
{
$ext = '.' . strtolower($this->excelWriter);
return $this->buildExcelFile()->download($this->getFilename() . $ext, $this->excelWriter);
} | [
"public",
"function",
"excel",
"(",
")",
"{",
"$",
"ext",
"=",
"'.'",
".",
"strtolower",
"(",
"$",
"this",
"->",
"excelWriter",
")",
";",
"return",
"$",
"this",
"->",
"buildExcelFile",
"(",
")",
"->",
"download",
"(",
"$",
"this",
"->",
"getFilename",
"(",
")",
".",
"$",
"ext",
",",
"$",
"this",
"->",
"excelWriter",
")",
";",
"}"
] | Export results to Excel file.
@return void | [
"Export",
"results",
"to",
"Excel",
"file",
"."
] | train | https://github.com/yajra/laravel-datatables-buttons/blob/291c129ab9db63e5ec5353336181e8c6a95e3e19/src/Services/DataTable.php#L383-L388 |
yajra/laravel-datatables-buttons | src/Services/DataTable.php | DataTable.exportColumns | private function exportColumns()
{
return is_array($this->exportColumns) ? $this->toColumnsCollection($this->exportColumns) : $this->getExportColumnsFromBuilder();
} | php | private function exportColumns()
{
return is_array($this->exportColumns) ? $this->toColumnsCollection($this->exportColumns) : $this->getExportColumnsFromBuilder();
} | [
"private",
"function",
"exportColumns",
"(",
")",
"{",
"return",
"is_array",
"(",
"$",
"this",
"->",
"exportColumns",
")",
"?",
"$",
"this",
"->",
"toColumnsCollection",
"(",
"$",
"this",
"->",
"exportColumns",
")",
":",
"$",
"this",
"->",
"getExportColumnsFromBuilder",
"(",
")",
";",
"}"
] | Get export columns definition.
@return array|string | [
"Get",
"export",
"columns",
"definition",
"."
] | train | https://github.com/yajra/laravel-datatables-buttons/blob/291c129ab9db63e5ec5353336181e8c6a95e3e19/src/Services/DataTable.php#L452-L455 |
yajra/laravel-datatables-buttons | src/Services/DataTable.php | DataTable.toColumnsCollection | private function toColumnsCollection(array $columns)
{
$collection = collect();
foreach ($columns as $column) {
if (isset($column['data'])) {
$column['title'] = $column['title'] ?? $column['data'];
$collection->push(new Column($column));
} else {
$data = [];
$data['data'] = $column;
$data['title'] = $column;
$collection->push(new Column($data));
}
}
return $collection;
} | php | private function toColumnsCollection(array $columns)
{
$collection = collect();
foreach ($columns as $column) {
if (isset($column['data'])) {
$column['title'] = $column['title'] ?? $column['data'];
$collection->push(new Column($column));
} else {
$data = [];
$data['data'] = $column;
$data['title'] = $column;
$collection->push(new Column($data));
}
}
return $collection;
} | [
"private",
"function",
"toColumnsCollection",
"(",
"array",
"$",
"columns",
")",
"{",
"$",
"collection",
"=",
"collect",
"(",
")",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"column",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"column",
"[",
"'data'",
"]",
")",
")",
"{",
"$",
"column",
"[",
"'title'",
"]",
"=",
"$",
"column",
"[",
"'title'",
"]",
"??",
"$",
"column",
"[",
"'data'",
"]",
";",
"$",
"collection",
"->",
"push",
"(",
"new",
"Column",
"(",
"$",
"column",
")",
")",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"$",
"data",
"[",
"'data'",
"]",
"=",
"$",
"column",
";",
"$",
"data",
"[",
"'title'",
"]",
"=",
"$",
"column",
";",
"$",
"collection",
"->",
"push",
"(",
"new",
"Column",
"(",
"$",
"data",
")",
")",
";",
"}",
"}",
"return",
"$",
"collection",
";",
"}"
] | Convert array to collection of Column class.
@param array $columns
@return Collection | [
"Convert",
"array",
"to",
"collection",
"of",
"Column",
"class",
"."
] | train | https://github.com/yajra/laravel-datatables-buttons/blob/291c129ab9db63e5ec5353336181e8c6a95e3e19/src/Services/DataTable.php#L463-L479 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.