Skip to content

feat(php): Add PHP clients init + PHP search client #78

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

Merged
merged 36 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7a9a14e
feat(php): add raw templates
damcou Jan 7, 2022
f87a1da
feat: add appid/apiKey init
damcou Jan 10, 2022
5e77ec0
feat: strippin' like crazy
damcou Jan 10, 2022
38b2e5e
feat: add PHP search client
damcou Jan 11, 2022
dca0cbf
Merge branch 'main' into feat/APIC-238/add-php-client
damcou Jan 11, 2022
4aea106
feat(php): Remove unwanted files on the php client branch (#79)
damcou Jan 11, 2022
000f0a4
fix: cleanup some files
damcou Jan 12, 2022
b02f974
Merge branch 'main' into feat/APIC-238/add-php-client
damcou Jan 12, 2022
2cdfacf
Merge branch 'main' into feat/APIC-238/add-php-client
damcou Jan 13, 2022
20e10e5
chore(php): Add PHP linting and CI workflow (#81)
damcou Jan 14, 2022
22d4aa6
Merge branch 'main' into feat/APIC-238/add-php-client
damcou Jan 14, 2022
0fc486f
feat(php): Add Retry Strategy & cache for the PHP client (#95)
damcou Jan 24, 2022
324e4d8
feat(php): Add remaining php clients (#106)
damcou Feb 1, 2022
ee1bc60
Merge branch 'main' into feat/APIC-238/add-php-client
damcou Feb 1, 2022
9153f4c
fix: store spec in CI script
millotp Feb 1, 2022
16fdef6
fix: CI
damcou Feb 1, 2022
eac80d2
Merge remote-tracking branch 'origin/fix/ci-spec-script' into feat/AP…
damcou Feb 1, 2022
11ba4ed
fix: CI
damcou Feb 1, 2022
aa06951
fix: openapitools.json
damcou Feb 1, 2022
9a5f6da
fix: update ci
damcou Feb 1, 2022
663750e
fix CI
millotp Feb 1, 2022
490bd27
fix: update ci
damcou Feb 1, 2022
55cdfb8
Merge branch 'feat/APIC-238/add-php-client' of https://github.com/alg…
damcou Feb 1, 2022
cc586f2
fix: php cmd
shortcuts Feb 1, 2022
098ebb3
regen?
shortcuts Feb 2, 2022
dbc8d81
split models per client
shortcuts Feb 2, 2022
2858be5
Merge branch 'main' into feat/APIC-238/add-php-client
damcou Feb 3, 2022
64f455f
fix: use global ModelInterface to avoid errors in CI
damcou Feb 3, 2022
a5968c6
Merge branch 'main' into feat/APIC-238/add-php-client
damcou Feb 3, 2022
acdc2ad
fix: CTS CI
damcou Feb 3, 2022
df509f8
fix: typo
damcou Feb 3, 2022
fc9dd80
fix: CI
damcou Feb 3, 2022
da8d820
fix: changes after review
damcou Feb 3, 2022
50ab7a1
Merge branch 'main' into feat/APIC-238/add-php-client
damcou Feb 3, 2022
1d69d81
fix: update CI + remove composer on playground
damcou Feb 4, 2022
f50c98a
fix: code cleaning after review
damcou Feb 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ runs:
echo "::set-output name=JAVA_CLIENT_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- clients/algoliasearch-client-java-2 | wc -l)"
echo "::set-output name=JAVA_TEMPLATE_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- templates/java | wc -l)"

echo "::set-output name=PHP_CLIENT_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- clients/algoliasearch-client-php | wc -l)"
echo "::set-output name=PHP_TEMPLATE_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- templates/php | wc -l)"

- name: Compute specs matrix
id: spec-matrix
shell: bash
Expand Down Expand Up @@ -91,6 +94,23 @@ runs:
echo "::set-output name=MATRIX::$matrix"
echo "::set-output name=RUN_CLIENT::$run"

- name: Compute the PHP client build matrix
id: php-matrix
shell: bash
run: |
base_changed=${{ github.ref == 'refs/heads/main' || steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.COMMON_SPECS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 || steps.diff.outputs.PHP_TEMPLATE_CHANGED > 0 }}

matrix=$(./scripts/ci/create-client-matrix.sh php $base_changed ${{ github.base_ref }})

if [[ $matrix == '{"client":["no-run"]}' ]]; then
run="false"
else
run="true"
fi

echo "::set-output name=MATRIX::$matrix"
echo "::set-output name=RUN_CLIENT::$run"

outputs:
RUN_SPECS:
description: Whether to run specs or not
Expand All @@ -116,6 +136,14 @@ outputs:
description: Generate the matrix for the Java client
value: ${{ steps.java-matrix.outputs.MATRIX }}

RUN_PHP:
description: Whether to run php client or not
value: ${{ steps.php-matrix.outputs.RUN_CLIENT }}

PHP_MATRIX:
description: Generate the matrix for the PHP client
value: ${{ steps.php-matrix.outputs.MATRIX }}

RUN_CTS:
description: Determine if the `cts` job should run
value: ${{ github.ref_name == 'main' || steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 || steps.diff.outputs.SPECS_CHANGED > 0 || steps.diff.outputs.TESTS_CHANGED > 0 || steps.diff.outputs.JS_CLIENT_CHANGED > 0 || steps.diff.outputs.JS_TEMPLATE_CHANGED > 0 || steps.diff.outputs.JAVA_CLIENT_CHANGED > 0 || steps.diff.outputs.JAVA_TEMPLATE_CHANGED > 0 }}
35 changes: 35 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ jobs:
RUN_JAVA: ${{ steps.setup.outputs.RUN_JAVA }}
JAVA_MATRIX: ${{ steps.setup.outputs.JAVA_MATRIX }}

RUN_PHP: ${{ steps.setup.outputs.RUN_PHP }}
PHP_MATRIX: ${{ steps.setup.outputs.PHP_MATRIX }}

RUN_CTS: ${{ steps.setup.outputs.RUN_CTS }}

specs:
Expand Down Expand Up @@ -134,11 +137,43 @@ jobs:
if: steps.cache.outputs.cache-hit != 'true'
run: yarn build:clients java ${{ matrix.client.name }}

client_php:
runs-on: ubuntu-20.04
needs:
- setup
- specs
if: ${{ always() && needs.setup.outputs.RUN_PHP == 'true' }}
strategy:
matrix: ${{ fromJSON(needs.setup.outputs.PHP_MATRIX) }}
steps:
- uses: actions/checkout@v2

- name: Restore cache
uses: ./.github/actions/cache
with:
job: client
language: php
spec: ${{ matrix.client.name }}

- name: Generate ${{ matrix.client.name }} client
if: steps.cache.outputs.cache-hit != 'true'
run: yarn generate php ${{ matrix.client.name }}

- name: Check diff with pushed client
if: steps.cache.outputs.cache-hit != 'true'
run: exit $(git status --porcelain ${{ matrix.client.folder }} | wc -l)

- name: Build ${{ matrix.client.name }} client
if: steps.cache.outputs.cache-hit != 'true'
run: yarn build:clients php ${{ matrix.client.name }}

cts:
runs-on: ubuntu-20.04
needs:
- client_javascript
- client_java
- client_php

if: ${{ always() && needs.setup.outputs.RUN_CTS == 'true' }}
steps:
- uses: actions/checkout@v2
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ ENV JAVA_HOME=/usr/lib/jvm/default-jvm
# Java formatter
ADD https://github.com/google/google-java-format/releases/download/v1.13.0/google-java-format-1.13.0-all-deps.jar /tmp/java-formatter.jar

# PHP dependencies
RUN apk add -U composer php8 php8-tokenizer

WORKDIR /app

CMD ["bash"]
13 changes: 13 additions & 0 deletions clients/algoliasearch-client-php/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# ref: https://github.com/github/gitignore/blob/master/Composer.gitignore

composer.phar
/vendor/

# php-cs-fixer cache
.php_cs.cache

# PHPUnit cache
.phpunit.result.cache

.openapi-generator/
composer.lock
16 changes: 16 additions & 0 deletions clients/algoliasearch-client-php/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

docs/**
test/**

.travis.yml
phpunit.xml.dist
README.md
git_push.sh
.php_cs

lib/HeaderSelector.php
63 changes: 63 additions & 0 deletions clients/algoliasearch-client-php/.php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

$config = new PhpCsFixer\Config();

return $config
->setUsingCache(true)
->setRules([
'array_syntax' => [ 'syntax' => 'short' ],
'blank_line_after_namespace' => false,
'blank_line_after_opening_tag' => true,
'blank_line_before_statement' => true,
'braces' => false,
'cast_spaces' => true,
'combine_consecutive_unsets' => true,
'echo_tag_syntax' => true,
'general_phpdoc_tag_rename' => true,
'mb_str_functions' => true,
'no_blank_lines_after_class_opening' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_blank_lines' => true,
'no_multiline_whitespace_around_double_arrow' => true,
'no_short_bool_cast' => true,
'no_trailing_whitespace' => true,
'no_trailing_whitespace_in_comment' => true,
'no_unneeded_control_parentheses' => true,
'no_unreachable_default_argument_value' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'no_whitespace_before_comma_in_array' => true,
'no_whitespace_in_blank_line' => true,
'normalize_index_brace' => true,
'not_operator_with_space' => false,
'object_operator_without_whitespace' => true,
'ordered_imports' => true,
'phpdoc_annotation_without_dot' => true,
'phpdoc_inline_tag_normalizer' => true,
'phpdoc_order' => true,
'phpdoc_scalar' => true,
'phpdoc_separation' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_tag_type' => true,
'protected_to_private' => true,
'@PSR2' => true,
'short_scalar_cast' => true,
'single_blank_line_at_eof' => false,
'single_blank_line_before_namespace' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'standardize_not_equals' => true,
'strict_comparison' => true,
'strict_param' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline' => true,
'trim_array_spaces' => true,
])
->setFinder(
PhpCsFixer\Finder::create()
->exclude('test')
->exclude('tests')
->in(__DIR__)
);
44 changes: 44 additions & 0 deletions clients/algoliasearch-client-php/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "algolia/algoliasearch-client-php",
"description": "API powering the features of Algolia.",
"keywords": [
"openapitools",
"openapi-generator",
"openapi",
"php",
"sdk",
"rest",
"api"
],
"homepage": "https://openapi-generator.tech",
"license": "unlicense",
"authors": [
{
"name": "OpenAPI-Generator contributors",
"homepage": "https://openapi-generator.tech"
}
],
"require": {
"php": "^7.3 || ^8.0",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"guzzlehttp/guzzle": "^7.3",
"guzzlehttp/psr7": "^2.0",
"psr/http-message": "^1.0",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"psr/simple-cache": "^1.0 || ^2.0 || ^3.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.5.0"
},
"autoload": {
"psr-4": { "Algolia\\AlgoliaSearch\\" : "lib/" },
"files": [
"lib/Http/Psr7/functions.php"
]
},
"autoload-dev": {
"psr-4": { "Algolia\\AlgoliaSearch\\Test\\" : "test/" }
}
}
105 changes: 105 additions & 0 deletions clients/algoliasearch-client-php/lib/Algolia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?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 = '1.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()
{
if (null === self::$httpClient) {
self::setHttpClient(new \Algolia\AlgoliaSearch\Http\GuzzleHttpClient());
}

return self::$httpClient;
}

public static function setHttpClient(HttpClientInterface $httpClient)
{
self::$httpClient = $httpClient;
}

public static function resetHttpClient()
{
self::$httpClient = null;
}
}
Loading