-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(php): Add Retry Strategy & cache for the PHP client #95
Merged
damcou
merged 9 commits into
feat/APIC-238/add-php-client
from
feat/APIC-238/add-retry-strategy
Jan 24, 2022
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c2291b4
fix: php client generation
damcou 868b1bf
feat: add all needed files for retry strategy
damcou 0b26249
feat: Make the calls with the retry strategy API wrapper + cleanup
damcou 73abcba
fix: use function to send the request
damcou 441e6b4
fix: updating post gen script
damcou 4113b8f
fix: updates after review
damcou f8ab3ec
fix: template error
damcou 5387edc
feat: update build script
damcou c168f38
fix: script
damcou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
|
||
namespace Algolia\AlgoliaSearch; | ||
|
||
use Algolia\AlgoliaSearch\Cache\NullCacheDriver; | ||
use Algolia\AlgoliaSearch\Http\HttpClientInterface; | ||
use Algolia\AlgoliaSearch\Log\DebugLogger; | ||
use Psr\Log\LoggerInterface; | ||
use Psr\SimpleCache\CacheInterface; | ||
|
||
final class Algolia | ||
{ | ||
const VERSION = '0.0.0'; | ||
|
||
/** | ||
* Holds an instance of the simple cache repository (PSR-16). | ||
* | ||
* @var \Psr\SimpleCache\CacheInterface|null | ||
*/ | ||
private static $cache; | ||
|
||
/** | ||
* Holds an instance of the logger (PSR-3). | ||
* | ||
* @var \Psr\Log\LoggerInterface|null | ||
*/ | ||
private static $logger; | ||
|
||
/** | ||
* @var \Algolia\AlgoliaSearch\Http\HttpClientInterface | ||
*/ | ||
private static $httpClient; | ||
|
||
public static function isCacheEnabled() | ||
{ | ||
if (null === self::$cache) { | ||
return false; | ||
} | ||
|
||
return !self::getCache() instanceof NullCacheDriver; | ||
} | ||
|
||
/** | ||
* Gets the cache instance. | ||
* | ||
* @return \Psr\SimpleCache\CacheInterface | ||
*/ | ||
public static function getCache() | ||
{ | ||
if (null === self::$cache) { | ||
self::setCache(new NullCacheDriver()); | ||
} | ||
|
||
return self::$cache; | ||
} | ||
|
||
/** | ||
* Sets the cache instance. | ||
*/ | ||
public static function setCache(CacheInterface $cache) | ||
{ | ||
self::$cache = $cache; | ||
} | ||
|
||
/** | ||
* Gets the logger instance. | ||
* | ||
* @return \Psr\Log\LoggerInterface | ||
*/ | ||
public static function getLogger() | ||
{ | ||
if (null === self::$logger) { | ||
self::setLogger(new DebugLogger()); | ||
} | ||
|
||
return self::$logger; | ||
} | ||
|
||
/** | ||
* Sets the logger instance. | ||
*/ | ||
public static function setLogger(LoggerInterface $logger) | ||
{ | ||
self::$logger = $logger; | ||
} | ||
|
||
public static function getHttpClient() | ||
{ | ||
$guzzleVersion = null; | ||
if (interface_exists('\GuzzleHttp\ClientInterface')) { | ||
if (defined('\GuzzleHttp\ClientInterface::VERSION')) { | ||
$guzzleVersion = (int) mb_substr(\GuzzleHttp\Client::VERSION, 0, 1); | ||
} else { | ||
$guzzleVersion = \GuzzleHttp\ClientInterface::MAJOR_VERSION; | ||
} | ||
} | ||
|
||
if (null === self::$httpClient) { | ||
if (class_exists('\GuzzleHttp\Client') && 6 <= $guzzleVersion) { | ||
self::setHttpClient(new \Algolia\AlgoliaSearch\Http\GuzzleHttpClient()); | ||
} else { | ||
self::setHttpClient(new \Algolia\AlgoliaSearch\Http\CurlHttpClient()); | ||
} | ||
} | ||
|
||
return self::$httpClient; | ||
} | ||
|
||
public static function setHttpClient(HttpClientInterface $httpClient) | ||
{ | ||
self::$httpClient = $httpClient; | ||
} | ||
|
||
public static function resetHttpClient() | ||
{ | ||
self::$httpClient = null; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you pin the last version for all deps pls ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this has been recently set this way on the PHP repo to ensure the compatibility with latest PHP versions : https://github.com/algolia/algoliasearch-client-php/pull/696/files . So I'd keep it this way for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we keep having issue with support for old version of software maybe now is a good time to get rid of them and force clients to update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With PHP, multiple version (from 7.4 to 8.1) are coexisting, that's why we have such config in the composer.json . We can discuss it later with some PHP experts but for now, as it's not really related to the retry strategy itself, I would postpone this potential decision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added to APIC-271