-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/DTSERWONE-1083 - V3 Support php versions (#118)
* DTSERWONE-1083 - Cherry pick f9eb75a from the branch `feature/DTSERWONE-1083 - V4 Support php versions (#117)` Summary: Enhanced the PHP-SDK to support PHP version build from 5.6 to 8.1 Introduce Hyperwallet URI Template Introduce GitHubAction to test PHP version from 5.6 to latest Address PHP Unit test compatibility * DTSERWONE-1083 - Fix file name to match with the class content
- Loading branch information
1 parent
c98c1c0
commit 9e039e4
Showing
21 changed files
with
265 additions
and
52 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
name: PHP SDK CI | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- master | ||
- support/SDK-V3 | ||
- feature/** | ||
- bugfix/** | ||
pull_request: | ||
branches: | ||
- master | ||
- support/SDK-V3 | ||
- feature/** | ||
- bugfix/** | ||
|
||
jobs: | ||
tests: | ||
name: Tests | ||
runs-on: ${{ matrix.operating-system }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
operating-system: ['ubuntu-latest'] | ||
php-versions: ['5.6', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] | ||
|
||
steps: | ||
- uses: actions/checkout@master | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php-versions }} | ||
coverage: xdebug | ||
|
||
- name: Validate composer.json and composer.lock | ||
run: composer validate | ||
|
||
- name: Install dependencies | ||
run: composer install --prefer-dist --no-progress --no-suggest | ||
|
||
- name: Run test suite | ||
run: | | ||
php --version | ||
./vendor/bin/phpunit -v | ||
code-coverage: | ||
name: Report code coverage | ||
runs-on: ${{ matrix.operating-system }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
operating-system: [ 'ubuntu-latest' ] | ||
php-versions: [ '5.6' ] | ||
|
||
steps: | ||
- uses: actions/checkout@master | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php-versions }} | ||
coverage: xdebug | ||
|
||
- name: Validate composer.json and composer.lock | ||
run: composer validate | ||
|
||
- name: Install dependencies | ||
run: composer install --prefer-dist --no-progress --no-suggest | ||
|
||
- name: Run test suite | ||
run: | | ||
php --version | ||
./vendor/bin/phpunit -v | ||
- name: Upload coverage results to Coveralls | ||
env: | ||
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: ./vendor/bin/php-coveralls -v --exclude-no-stmt |
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
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
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
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,78 @@ | ||
<?php | ||
|
||
namespace Hyperwallet\Util; | ||
|
||
/** | ||
* A simple implementation of https://www.rfc-editor.org/rfc/rfc6570 for expanding Hyperwallet | ||
* Uniform Resource Identifier (URI) Template. | ||
* | ||
* This class was created to allow the Hyperwallet SDK to support by PHP 5.6 and latest version | ||
* @package Hyperwallet\Util | ||
*/ | ||
final class HyperwalletUriTemplate | ||
{ | ||
|
||
/** | ||
* Regex pattern to find variable identifier defined by pair of braces ('{', '}'). | ||
* e.g. {var} | ||
*/ | ||
const PATTERN = '/\{([^\}]+)\}/'; | ||
|
||
/** | ||
* Processes URI Template | ||
* | ||
* This implementation will replace simple key defined in pair of braces ('{', '}') and replaced for the associate | ||
* variable value. | ||
* | ||
* E.g. $uriTemplate = `test/{var-a}/{var-b}`, $variables = array('var-a' => 'testA', 'var-b' => 'testB') will return | ||
* test/testA/testB | ||
* | ||
* @param string $uriTemplate the URI Template is a string that | ||
* contains zero or more embedded variable expressions delimited by pair of braces ('{', '}'). | ||
* @param array $variables the variable identifiers for associating values within a template | ||
* processor | ||
* @return string | ||
*/ | ||
public function expand($uriTemplate, array $variables) | ||
{ | ||
if (!$variables || strpos($uriTemplate, '{') === false) { | ||
// skip processing | ||
return $uriTemplate; | ||
} | ||
|
||
return \preg_replace_callback( | ||
self::PATTERN, | ||
self::buildProcessMatchResult($variables), | ||
$uriTemplate | ||
); | ||
} | ||
|
||
/** | ||
* Evaluates the match result and find the associated value from the defined variables | ||
* @param array $matches the match results | ||
* @param array $variables the variable identifiers for associating values within a template | ||
* processor | ||
* @return mixed | ||
*/ | ||
private static function processMatchResult(array $matches, array $variables) | ||
{ | ||
if (!isset($variables[$matches[1]])) { | ||
// missing variable definition, return the match key | ||
return $matches[0]; | ||
} | ||
|
||
return $variables[$matches[1]]; | ||
} | ||
|
||
/** | ||
* Builds an anonymous functions to process the match result | ||
* @param array $variables | ||
* @return \Closure | ||
*/ | ||
private static function buildProcessMatchResult(array $variables) | ||
{ | ||
return static function (array $matches) use ($variables) { | ||
return self::processMatchResult($matches, $variables); | ||
}; | ||
} | ||
} |
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
Oops, something went wrong.