From 32bf9c5674e87ea0001d25ecc12d5921a95ec64a Mon Sep 17 00:00:00 2001 From: Lukas Bestle Date: Fri, 25 Aug 2017 21:53:30 +0200 Subject: [PATCH] Update Algolia library to v1.18.0 --- vendor/algolia-client/algoliasearch.php | 3 + .../src/AlgoliaSearch/Client.php | 103 ++++++-- .../src/AlgoliaSearch/ClientContext.php | 51 ++-- .../src/AlgoliaSearch/FailingHostsCache.php | 23 ++ .../AlgoliaSearch/FileFailingHostsCache.php | 192 ++++++++++++++ .../InMemoryFailingHostsCache.php | 76 ++++++ .../src/AlgoliaSearch/Index.php | 244 ++++++++++++++++-- .../src/AlgoliaSearch/Version.php | 20 +- 8 files changed, 655 insertions(+), 57 deletions(-) create mode 100755 vendor/algolia-client/src/AlgoliaSearch/FailingHostsCache.php create mode 100755 vendor/algolia-client/src/AlgoliaSearch/FileFailingHostsCache.php create mode 100755 vendor/algolia-client/src/AlgoliaSearch/InMemoryFailingHostsCache.php diff --git a/vendor/algolia-client/algoliasearch.php b/vendor/algolia-client/algoliasearch.php index 5e061d8..382e8b7 100755 --- a/vendor/algolia-client/algoliasearch.php +++ b/vendor/algolia-client/algoliasearch.php @@ -33,3 +33,6 @@ require_once 'src/AlgoliaSearch/SynonymType.php'; require_once 'src/AlgoliaSearch/Version.php'; require_once 'src/AlgoliaSearch/Json.php'; +require_once 'src/AlgoliaSearch/FailingHostsCache.php'; +require_once 'src/AlgoliaSearch/FileFailingHostsCache.php'; +require_once 'src/AlgoliaSearch/InMemoryFailingHostsCache.php'; diff --git a/vendor/algolia-client/src/AlgoliaSearch/Client.php b/vendor/algolia-client/src/AlgoliaSearch/Client.php index 6c20e72..92599b3 100755 --- a/vendor/algolia-client/src/AlgoliaSearch/Client.php +++ b/vendor/algolia-client/src/AlgoliaSearch/Client.php @@ -37,6 +37,7 @@ class Client const CAINFO = 'cainfo'; const CURLOPT = 'curloptions'; const PLACES_ENABLED = 'placesEnabled'; + const FAILING_HOSTS_CACHE = 'failingHostsCache'; /** * @var ClientContext @@ -94,12 +95,18 @@ public function __construct($applicationID, $apiKey, $hostsArray = null, $option case self::PLACES_ENABLED: $this->placesEnabled = (bool) $value; break; + case self::FAILING_HOSTS_CACHE: + if (! $value instanceof FailingHostsCache) { + throw new \InvalidArgumentException('failingHostsCache must be an instance of \AlgoliaSearch\FailingHostsCache.'); + } + break; default: throw new \Exception('Unknown option: '.$option); } } - $this->context = new ClientContext($applicationID, $apiKey, $hostsArray, $this->placesEnabled); + $failingHostsCache = isset($options[self::FAILING_HOSTS_CACHE]) ? $options[self::FAILING_HOSTS_CACHE] : null; + $this->context = new ClientContext($applicationID, $apiKey, $hostsArray, $this->placesEnabled, $failingHostsCache); } /** @@ -408,13 +415,13 @@ public function initIndex($indexName) } /** - * List all existing user keys with their associated ACLs. + * List all existing API keys with their associated ACLs. * * @return mixed * * @throws AlgoliaException */ - public function listUserKeys() + public function listApiKeys() { return $this->request( $this->context, @@ -429,13 +436,22 @@ public function listUserKeys() } /** - * Get ACL of a user key. + * @return mixed + * @deprecated use listApiKeys instead + */ + public function listUserKeys() + { + return $this->listApiKeys(); + } + + /** + * Get ACL of a API key. * * @param string $key * * @return mixed */ - public function getUserKeyACL($key) + public function getApiKey($key) { return $this->request( $this->context, @@ -450,13 +466,23 @@ public function getUserKeyACL($key) } /** - * Delete an existing user key. + * @param $key + * @return mixed + * @deprecated use getApiKey instead + */ + public function getUserKeyACL($key) + { + return $this->getApiKey($key); + } + + /** + * Delete an existing API key. * * @param string $key * * @return mixed */ - public function deleteUserKey($key) + public function deleteApiKey($key) { return $this->request( $this->context, @@ -471,7 +497,17 @@ public function deleteUserKey($key) } /** - * Create a new user key. + * @param $key + * @return mixed + * @deprecated use deleteApiKey instead + */ + public function deleteUserKey($key) + { + return $this->deleteApiKey($key); + } + + /** + * Create a new API key. * * @param array $obj can be two different parameters: * The list of parameters for this key. Defined by an array that @@ -504,7 +540,7 @@ public function deleteUserKey($key) * * @throws AlgoliaException */ - public function addUserKey($obj, $validity = 0, $maxQueriesPerIPPerHour = 0, $maxHitsPerQuery = 0, $indexes = null) + public function addApiKey($obj, $validity = 0, $maxQueriesPerIPPerHour = 0, $maxHitsPerQuery = 0, $indexes = null) { if ($obj !== array_values($obj)) { // is dict of value $params = $obj; @@ -537,7 +573,21 @@ public function addUserKey($obj, $validity = 0, $maxQueriesPerIPPerHour = 0, $ma } /** - * Update a user key. + * @param $obj + * @param int $validity + * @param int $maxQueriesPerIPPerHour + * @param int $maxHitsPerQuery + * @param null $indexes + * @return mixed + * @deprecated use addApiKey instead + */ + public function addUserKey($obj, $validity = 0, $maxQueriesPerIPPerHour = 0, $maxHitsPerQuery = 0, $indexes = null) + { + return $this->addApiKey($obj, $validity, $maxQueriesPerIPPerHour, $maxHitsPerQuery, $indexes); + } + + /** + * Update an API key. * * @param string $key * @param array $obj can be two different parameters: @@ -571,7 +621,7 @@ public function addUserKey($obj, $validity = 0, $maxQueriesPerIPPerHour = 0, $ma * * @throws AlgoliaException */ - public function updateUserKey( + public function updateApiKey( $key, $obj, $validity = 0, @@ -608,6 +658,27 @@ public function updateUserKey( ); } + /** + * @param $key + * @param $obj + * @param int $validity + * @param int $maxQueriesPerIPPerHour + * @param int $maxHitsPerQuery + * @param null $indexes + * @return mixed + * @deprecated use updateApiKey instead + */ + public function updateUserKey( + $key, + $obj, + $validity = 0, + $maxQueriesPerIPPerHour = 0, + $maxHitsPerQuery = 0, + $indexes = null + ) { + return $this->updateApiKey($key, $obj, $validity, $maxQueriesPerIPPerHour, $maxHitsPerQuery, $indexes); + } + /** * Send a batch request targeting multiple indices. * @@ -1013,14 +1084,14 @@ private function getPlacesIndex() } /** - * @param string $appId - * @param string $apiKey - * @param array $hostsArray - * @param array $options + * @param string|null $appId + * @param string|null $apiKey + * @param array|null $hostsArray + * @param array $options * * @return PlacesIndex */ - public static function initPlaces($appId, $apiKey, $hostsArray = null, $options = array()) + public static function initPlaces($appId = null, $apiKey = null, $hostsArray = null, $options = array()) { $options['placesEnabled'] = true; $client = new static($appId, $apiKey, $hostsArray, $options); diff --git a/vendor/algolia-client/src/AlgoliaSearch/ClientContext.php b/vendor/algolia-client/src/AlgoliaSearch/ClientContext.php index b7da89e..08c01ec 100755 --- a/vendor/algolia-client/src/AlgoliaSearch/ClientContext.php +++ b/vendor/algolia-client/src/AlgoliaSearch/ClientContext.php @@ -77,21 +77,20 @@ class ClientContext public $connectTimeout; /** - * @var array + * @var FailingHostsCache */ - private static $failingHosts = array(); + private $failingHostsCache; /** - * ClientContext constructor. - * - * @param string $applicationID - * @param string $apiKey - * @param array $hostsArray - * @param bool $placesEnabled + * @param string|null $applicationID + * @param string|null $apiKey + * @param array|null $hostsArray + * @param bool $placesEnabled + * @param FailingHostsCache|null $failingHostsCache * * @throws Exception */ - public function __construct($applicationID, $apiKey, $hostsArray, $placesEnabled = false) + public function __construct($applicationID = null, $apiKey = null, $hostsArray = null, $placesEnabled = false, FailingHostsCache $failingHostsCache = null) { // connect timeout of 1s by default $this->connectTimeout = 1; @@ -113,13 +112,11 @@ public function __construct($applicationID, $apiKey, $hostsArray, $placesEnabled $this->writeHostsArray = $this->getDefaultWriteHosts(); } - $this->rotateHosts(); - - if ($this->applicationID == null || mb_strlen($this->applicationID) == 0) { + if (($this->applicationID == null || mb_strlen($this->applicationID) == 0) && $placesEnabled === false) { throw new Exception('AlgoliaSearch requires an applicationID.'); } - if ($this->apiKey == null || mb_strlen($this->apiKey) == 0) { + if (($this->apiKey == null || mb_strlen($this->apiKey) == 0) && $placesEnabled === false) { throw new Exception('AlgoliaSearch requires an apiKey.'); } @@ -129,6 +126,14 @@ public function __construct($applicationID, $apiKey, $hostsArray, $placesEnabled $this->algoliaUserToken = null; $this->rateLimitAPIKey = null; $this->headers = array(); + + if ($failingHostsCache === null) { + $this->failingHostsCache = new InMemoryFailingHostsCache(); + } else { + $this->failingHostsCache = $failingHostsCache; + } + + $this->rotateHosts(); } /** @@ -258,15 +263,20 @@ public function setExtraHeader($key, $value) } /** - * @param $host + * @param string $host */ - public static function addFailingHost($host) + public function addFailingHost($host) { - if (!in_array($host, self::$failingHosts)) { - self::$failingHosts[] = $host; - } + $this->failingHostsCache->addFailingHost($host); } + /** + * @return FailingHostsCache + */ + public function getFailingHostsCache() + { + return $this->failingHostsCache; + } /** * This method is called to pass on failing hosts. * If the host is first either in the failingHosts array, we @@ -276,14 +286,15 @@ public static function addFailingHost($host) */ public function rotateHosts() { + $failingHosts = $this->failingHostsCache->getFailingHosts(); $i = 0; - while ($i <= count($this->readHostsArray) && in_array($this->readHostsArray[0], self::$failingHosts)) { + while ($i <= count($this->readHostsArray) && in_array($this->readHostsArray[0], $failingHosts)) { $i++; $this->readHostsArray[] = array_shift($this->readHostsArray); } $i = 0; - while ($i <= count($this->writeHostsArray) && in_array($this->writeHostsArray[0], self::$failingHosts)) { + while ($i <= count($this->writeHostsArray) && in_array($this->writeHostsArray[0], $failingHosts)) { $i++; $this->writeHostsArray[] = array_shift($this->writeHostsArray); } diff --git a/vendor/algolia-client/src/AlgoliaSearch/FailingHostsCache.php b/vendor/algolia-client/src/AlgoliaSearch/FailingHostsCache.php new file mode 100755 index 0000000..17ab336 --- /dev/null +++ b/vendor/algolia-client/src/AlgoliaSearch/FailingHostsCache.php @@ -0,0 +1,23 @@ +failingHostsCacheFile = $this->getDefaultCacheFile(); + } else { + $this->failingHostsCacheFile = (string) $file; + } + + $this->assertCacheFileIsValid($this->failingHostsCacheFile); + + if ($ttl === null) { + $ttl = 60 * 5; // 5 minutes + } + + $this->ttl = (int) $ttl; + } + + /** + * @return int + */ + public function getTtl() + { + return $this->ttl; + } + + /** + * @param $file + */ + private function assertCacheFileIsValid($file) + { + $fileDirectory = dirname($file); + + if (! is_writable($fileDirectory)) { + throw new \RuntimeException(sprintf('Cache file directory "%s" is not writable.', $fileDirectory)); + } + + if (! file_exists($file)) { + // The dir being writable, the file will be created when needed. + return; + } + + if (! is_readable($file)) { + throw new \RuntimeException(sprintf('Cache file "%s" is not readable.', $file)); + } + + if (! is_writable($file)) { + throw new \RuntimeException(sprintf('Cache file "%s" is not writable.', $file)); + } + } + + /** + * @return string + */ + private function getDefaultCacheFile() + { + return sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'algolia-failing-hosts'; + } + + /** + * @param string $host + */ + public function addFailingHost($host) + { + $cache = $this->loadFailingHostsCacheFromDisk(); + + if (isset($cache[self::TIMESTAMP]) && isset($cache[self::FAILING_HOSTS])) { + // Update failing hosts cache. + // Here we don't take care of invalidating. We do that on retrieval. + if (!in_array($host, $cache[self::FAILING_HOSTS])) { + $cache[self::FAILING_HOSTS][] = $host; + $this->writeFailingHostsCacheFile($cache); + } + } else { + $cache[self::TIMESTAMP] = time(); + $cache[self::FAILING_HOSTS] = array($host); + $this->writeFailingHostsCacheFile($cache); + } + } + + /** + * Get failing hosts from cache. This method should also handle cache invalidation if required. + * The TTL of the failed hosts cache should be 5mins. + * + * @return array + */ + public function getFailingHosts() + { + $cache = $this->loadFailingHostsCacheFromDisk(); + + return isset($cache[self::FAILING_HOSTS]) ? $cache[self::FAILING_HOSTS] : array(); + } + + /** + * Removes the file storing the failing hosts. + */ + public function flushFailingHostsCache() + { + if (file_exists($this->failingHostsCacheFile)) { + unlink($this->failingHostsCacheFile); + } + } + + /** + * @return array + */ + private function loadFailingHostsCacheFromDisk() + { + if (! file_exists($this->failingHostsCacheFile)) { + return array(); + } + + $json = file_get_contents($this->failingHostsCacheFile); + if ($json === false) { + return array(); + } + + $data = json_decode($json, true); + + if (json_last_error() !== JSON_ERROR_NONE) { + return array(); + } + + // Some basic checks. + if ( + !isset($data[self::TIMESTAMP]) + || !isset($data[self::FAILING_HOSTS]) + || !is_int($data[self::TIMESTAMP]) + || !is_array($data[self::FAILING_HOSTS]) + ) { + return array(); + } + + // Validate the hosts array. + foreach ($data[self::FAILING_HOSTS] as $host) { + if (!is_string($host)) { + return array(); + } + } + + $elapsed = time() - $data[self::TIMESTAMP]; // Number of seconds elapsed. + + if ($elapsed > $this->ttl) { + $this->flushFailingHostsCache(); + + return array(); + } + + return $data; + } + + /** + * @param array $data + */ + private function writeFailingHostsCacheFile(array $data) + { + $json = json_encode($data); + if ($json !== false) { + file_put_contents($this->failingHostsCacheFile, $json); + } + } +} diff --git a/vendor/algolia-client/src/AlgoliaSearch/InMemoryFailingHostsCache.php b/vendor/algolia-client/src/AlgoliaSearch/InMemoryFailingHostsCache.php new file mode 100755 index 0000000..a4cea21 --- /dev/null +++ b/vendor/algolia-client/src/AlgoliaSearch/InMemoryFailingHostsCache.php @@ -0,0 +1,76 @@ +ttl = (int) $ttl; + } + + + /** + * @param string $host + */ + public function addFailingHost($host) + { + if (! in_array($host, self::$failingHosts)) { + // Keep a local cache of failed hosts in case the file based strategy doesn't work out. + self::$failingHosts[] = $host; + + if (self::$timestamp === null) { + self::$timestamp = time(); + } + } + } + + /** + * Get failing hosts from cache. This method should also handle cache invalidation if required. + * The TTL of the failed hosts cache should be 5mins. + * + * @return array + */ + public function getFailingHosts() + { + if (self::$timestamp === null) { + return self::$failingHosts; + } + + $elapsed = time() - self::$timestamp; + if ($elapsed > $this->ttl) { + $this->flushFailingHostsCache(); + } + + return self::$failingHosts; + } + + public function flushFailingHostsCache() + { + self::$failingHosts = array(); + self::$timestamp = null; + } +} diff --git a/vendor/algolia-client/src/AlgoliaSearch/Index.php b/vendor/algolia-client/src/AlgoliaSearch/Index.php index b0f29e4..ca4fe6c 100755 --- a/vendor/algolia-client/src/AlgoliaSearch/Index.php +++ b/vendor/algolia-client/src/AlgoliaSearch/Index.php @@ -172,9 +172,8 @@ public function addObjects($objects, $objectIDKey = 'objectID') /** * Get an object from this index. * - * @param $objectID the unique identifier of the object to retrieve - * @param $attributesToRetrieve (optional) if set, contains the list of attributes to retrieve as a string - * separated by "," + * @param string $objectID the unique identifier of the object to retrieve + * @param string[] $attributesToRetrieve (optional) if set, contains the list of attributes to retrieve * * @return mixed */ @@ -194,6 +193,10 @@ public function getObject($objectID, $attributesToRetrieve = null) ); } + if (is_array($attributesToRetrieve)) { + $attributesToRetrieve = implode(',', $attributesToRetrieve); + } + return $this->client->request( $this->context, 'GET', @@ -209,13 +212,14 @@ public function getObject($objectID, $attributesToRetrieve = null) /** * Get several objects from this index. * - * @param array $objectIDs the array of unique identifier of objects to retrieve + * @param array $objectIDs the array of unique identifier of objects to retrieve + * @param string[] $attributesToRetrieve (optional) if set, contains the list of attributes to retrieve * * @return mixed * * @throws \Exception */ - public function getObjects($objectIDs) + public function getObjects($objectIDs, $attributesToRetrieve = null) { if ($objectIDs == null) { throw new \Exception('No list of objectID provided'); @@ -224,6 +228,15 @@ public function getObjects($objectIDs) $requests = array(); foreach ($objectIDs as $object) { $req = array('indexName' => $this->indexName, 'objectID' => $object); + + if ($attributesToRetrieve) { + if (is_array($attributesToRetrieve)) { + $attributesToRetrieve = implode(',', $attributesToRetrieve); + } + + $req['attributesToRetrieve'] = $attributesToRetrieve; + } + array_push($requests, $req); } @@ -412,7 +425,7 @@ public function deleteByQuery($query, $args = array(), $waitLastCall = true) * Search inside the index. * * @param string $query the full text query - * @param mixed $args (optional) if set, contains an associative array with query parameters: + * @param mixed $args (optional) if set, contains an associative array with query parameters: * - page: (integer) Pagination parameter used to select the page to retrieve. * Page is zero-based and defaults to 0. Thus, to retrieve the 10th page you need to set page=9 * - hitsPerPage: (integer) Pagination parameter used to select the number of hits per page. @@ -488,8 +501,8 @@ public function deleteByQuery($query, $args = array(), $waitLastCall = true) * duplicate value for the attributeForDistinct attribute are removed from results. For example, * if the chosen attribute is show_name and several hits have the same value for show_name, then * only the best one is kept and others are removed. - * * @return mixed + * @throws AlgoliaException */ public function search($query, $args = null) { @@ -498,6 +511,10 @@ public function search($query, $args = null) } $args['query'] = $query; + if (isset($args['disjunctiveFacets'])) { + return $this->searchWithDisjunctiveFaceting($query, $args); + } + return $this->client->request( $this->context, 'POST', @@ -510,6 +527,138 @@ public function search($query, $args = null) ); } + /** + * @param $query + * @param $args + * @return mixed + * @throws AlgoliaException + */ + private function searchWithDisjunctiveFaceting($query, $args) + { + if (! is_array($args['disjunctiveFacets']) || count($args['disjunctiveFacets']) <= 0) { + throw new \InvalidArgumentException('disjunctiveFacets needs to be an non empty array'); + } + + if (isset($args['filters'])) { + throw new \InvalidArgumentException('You can not use disjunctive faceting and the filters parameter'); + } + + /** + * Prepare queries + */ + // Get the list of disjunctive queries to do: 1 per disjunctive facet + $disjunctiveQueries = $this->getDisjunctiveQueries($args); + + // Format disjunctive queries for multipleQueries call + foreach ($disjunctiveQueries as &$disjunctiveQuery) { + $disjunctiveQuery['indexName'] = $this->indexName; + $disjunctiveQuery['query'] = $query; + unset($disjunctiveQuery['disjunctiveFacets']); + } + + // Merge facets and disjunctiveFacets for the hits query + $facets = isset($args['facets']) ? $args['facets'] : array(); + $facets = array_merge($facets, $args['disjunctiveFacets']); + unset($args['disjunctiveFacets']); + + // format the hits query for multipleQueries call + $args['query'] = $query; + $args['indexName'] = $this->indexName; + $args['facets'] = $facets; + + // Put the hit query first + array_unshift($disjunctiveQueries, $args); + + /** + * Do all queries in one call + */ + $results = $this->client->multipleQueries(array_values($disjunctiveQueries)); + $results = $results['results']; + + /** + * Merge facets from disjunctive queries with facets from the hits query + */ + + // The first query is the hits query that the one we'll return to the user + $queryResults = array_shift($results); + + // To be able to add facets from disjunctive query we create 'facets' key in case we only have disjunctive facets + if (false === isset($queryResults['facets'])) { + $queryResults['facets'] = array(); + } + + foreach ($results as $disjunctiveResults) { + if (isset($disjunctiveResults['facets'])) { + foreach ($disjunctiveResults['facets'] as $facetName => $facetValues) { + $queryResults['facets'][$facetName] = $facetValues; + } + } + } + + return $queryResults; + } + + /** + * @param $queryParams + * @return array + */ + private function getDisjunctiveQueries($queryParams) + { + $queriesParams = array(); + + foreach ($queryParams['disjunctiveFacets'] as $facetName) { + $params = $queryParams; + $params['facets'] = array($facetName); + $facetFilters = isset($params['facetFilters']) ? $params['facetFilters']: array(); + $numericFilters = isset($params['numericFilters']) ? $params['numericFilters']: array(); + + $additionalParams = array( + 'hitsPerPage' => 1, + 'page' => 0, + 'attributesToRetrieve' => array(), + 'attributesToHighlight' => array(), + 'attributesToSnippet' => array() + ); + + $additionalParams['facetFilters'] = $this->getAlgoliaFiltersArrayWithoutCurrentRefinement($facetFilters, $facetName . ':'); + $additionalParams['numericFilters'] = $this->getAlgoliaFiltersArrayWithoutCurrentRefinement($numericFilters, $facetName); + + $queriesParams[$facetName] = array_merge($params, $additionalParams); + } + + return $queriesParams; + } + + /** + * @param $filters + * @param $needle + * @return array + */ + private function getAlgoliaFiltersArrayWithoutCurrentRefinement($filters, $needle) + { + // iterate on each filters which can be string or array and filter out every refinement matching the needle + for ($i = 0; $i < count($filters); $i++) { + if (is_array($filters[$i])) { + foreach ($filters[$i] as $filter) { + if (mb_substr($filter, 0, mb_strlen($needle)) === $needle) { + unset($filters[$i]); + $filters = array_values($filters); + $i--; + break; + } + } + } else { + if (mb_substr($filters[$i], 0, mb_strlen($needle)) === $needle) { + unset($filters[$i]); + $filters = array_values($filters); + $i--; + } + } + } + + return $filters; + } + /** * Perform a search inside facets. * @@ -548,6 +697,7 @@ public function searchForFacetValues($facetName, $facetQuery, $query = array()) * * @throws AlgoliaException * @throws \Exception + * @deprecated you should use $index->search($query, ['disjunctiveFacets' => $disjunctive_facets]]); instead */ public function searchDisjunctiveFaceting($query, $disjunctive_facets, $params = array(), $refinements = array()) { @@ -840,13 +990,13 @@ public function setSettings($settings, $forwardToReplicas = false) } /** - * List all existing user keys associated to this index with their associated ACLs. + * List all existing API keys associated to this index with their associated ACLs. * * @return mixed * * @throws AlgoliaException */ - public function listUserKeys() + public function listApiKeys() { return $this->client->request( $this->context, @@ -861,7 +1011,26 @@ public function listUserKeys() } /** - * Get ACL of a user key associated to this index. + * @deprecated use listApiKeys instead + * @return mixed + */ + public function listUserKeys() + { + return $this->listApiKeys(); + } + + /** + * @deprecated use getApiKey in + * @param $key + * @return mixed + */ + public function getUserKeyACL($key) + { + return $this->getApiKey($key); + } + + /** + * Get ACL of a API key associated to this index. * * @param string $key * @@ -869,7 +1038,7 @@ public function listUserKeys() * * @throws AlgoliaException */ - public function getUserKeyACL($key) + public function getApiKey($key) { return $this->client->request( $this->context, @@ -883,8 +1052,9 @@ public function getUserKeyACL($key) ); } + /** - * Delete an existing user key associated to this index. + * Delete an existing API key associated to this index. * * @param string $key * @@ -892,7 +1062,7 @@ public function getUserKeyACL($key) * * @throws AlgoliaException */ - public function deleteUserKey($key) + public function deleteApiKey($key) { return $this->client->request( $this->context, @@ -907,7 +1077,17 @@ public function deleteUserKey($key) } /** - * Create a new user key associated to this index. + * @param $key + * @return mixed + * @deprecated use deleteApiKey instead + */ + public function deleteUserKey($key) + { + return $this->deleteApiKey($key); + } + + /** + * Create a new API key associated to this index. * * @param array $obj can be two different parameters: * The list of parameters for this key. Defined by a array that @@ -939,7 +1119,7 @@ public function deleteUserKey($key) * * @throws AlgoliaException */ - public function addUserKey($obj, $validity = 0, $maxQueriesPerIPPerHour = 0, $maxHitsPerQuery = 0) + public function addApiKey($obj, $validity = 0, $maxQueriesPerIPPerHour = 0, $maxHitsPerQuery = 0) { // is dict of value if ($obj !== array_values($obj)) { @@ -969,7 +1149,21 @@ public function addUserKey($obj, $validity = 0, $maxQueriesPerIPPerHour = 0, $ma } /** - * Update a user key associated to this index. + * @param $obj + * @param int $validity + * @param int $maxQueriesPerIPPerHour + * @param int $maxHitsPerQuery + * @return mixed + * @deprecated use addApiKey instead + */ + public function addUserKey($obj, $validity = 0, $maxQueriesPerIPPerHour = 0, $maxHitsPerQuery = 0) + { + return $this->addApiKey($obj, $validity, $maxQueriesPerIPPerHour, $maxHitsPerQuery); + } + + + /** + * Update an API key associated to this index. * * @param string $key * @param array $obj can be two different parameters: @@ -1002,7 +1196,7 @@ public function addUserKey($obj, $validity = 0, $maxQueriesPerIPPerHour = 0, $ma * * @throws AlgoliaException */ - public function updateUserKey($key, $obj, $validity = 0, $maxQueriesPerIPPerHour = 0, $maxHitsPerQuery = 0) + public function updateApiKey($key, $obj, $validity = 0, $maxQueriesPerIPPerHour = 0, $maxHitsPerQuery = 0) { // is dict of value if ($obj !== array_values($obj)) { @@ -1031,6 +1225,20 @@ public function updateUserKey($key, $obj, $validity = 0, $maxQueriesPerIPPerHour ); } + /** + * @param $key + * @param $obj + * @param int $validity + * @param int $maxQueriesPerIPPerHour + * @param int $maxHitsPerQuery + * @return mixed + * @deprecated use updateApiKey instead + */ + public function updateUserKey($key, $obj, $validity = 0, $maxQueriesPerIPPerHour = 0, $maxHitsPerQuery = 0) + { + return $this->updateApiKey($key, $obj, $validity, $maxQueriesPerIPPerHour, $maxHitsPerQuery); + } + /** * Send a batch request. * @@ -1313,6 +1521,6 @@ public function __call($name, $arguments) return call_user_func_array(array($this, 'doBcBrowse'), $arguments); } - return; + throw new \BadMethodCallException(sprintf('No method named %s was found.', $name)); } } diff --git a/vendor/algolia-client/src/AlgoliaSearch/Version.php b/vendor/algolia-client/src/AlgoliaSearch/Version.php index 771ad76..1705f72 100755 --- a/vendor/algolia-client/src/AlgoliaSearch/Version.php +++ b/vendor/algolia-client/src/AlgoliaSearch/Version.php @@ -29,7 +29,7 @@ class Version { - const VALUE = '1.13.0'; + const VALUE = '1.18.0'; public static $custom_value = ''; @@ -54,11 +54,25 @@ public static function getUserAgent() public static function addPrefixUserAgentSegment($segment, $version) { - self::$prefixUserAgentSegments = $segment.' ('.$version.'); '.self::$prefixUserAgentSegments; + $prefix = $segment.' ('.$version.'); '; + + if (false === mb_strpos(self::getUserAgent(), $prefix)) { + self::$prefixUserAgentSegments = $prefix . self::$prefixUserAgentSegments; + } } public static function addSuffixUserAgentSegment($segment, $version) { - self::$suffixUserAgentSegments .= '; '.$segment.' ('.$version.')'; + $suffix = '; '.$segment.' ('.$version.')'; + + if (false === mb_strpos(self::getUserAgent(), $suffix)) { + self::$suffixUserAgentSegments .= $suffix; + } + } + + public static function clearUserAgentSuffixesAndPrefixes() + { + self::$suffixUserAgentSegments = ''; + self::$prefixUserAgentSegments = ''; } }