-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
5,634 additions
and
0 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,4 @@ | ||
.github/ export-ignore | ||
vendor-bin/ export-ignore | ||
phpstan.neon export-ignore | ||
.php-cs-fixer.dist.php export-ignore |
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,38 @@ | ||
name: Coding Standards | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
tags: | ||
- 'v*' | ||
pull_request: | ||
schedule: | ||
- cron: '0 3 * * *' | ||
|
||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
php: | ||
- '8.2' | ||
fail-fast: true | ||
name: PHP ${{ matrix.php }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
coverage: none | ||
- name: Validate composer.json | ||
run: composer validate | ||
- name: Install dependencies (PHP-CS-Fixer) | ||
uses: ramsey/composer-install@v3 | ||
with: | ||
dependency-versions: locked | ||
working-directory: vendor-bin/cs | ||
- name: PHP-CS-Fixer | ||
run: | | ||
(vendor-bin/cs/vendor/bin/php-cs-fixer fix --dry-run --format checkstyle || true) | vendor-bin/cs/vendor/bin/cs2pr |
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,82 @@ | ||
name: Main | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
tags: | ||
- 'v*' | ||
pull_request: | ||
schedule: | ||
- cron: '0 3 * * *' | ||
|
||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }} | ||
continue-on-error: ${{ matrix.experimental }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
php: | ||
- '8.2' | ||
- '8.3' | ||
deps: | ||
- highest | ||
- lowest | ||
experimental: [false] | ||
include: | ||
- os: ubuntu-latest | ||
php: '8.2' | ||
phpstan: 1 | ||
- os: ubuntu-latest | ||
php: '8.3' | ||
phpstan: 1 | ||
- os: ubuntu-latest | ||
php: '8.3' | ||
coverage: 1 | ||
- os: ubuntu-latest | ||
php: 'nightly' | ||
deps: 'highest' | ||
experimental: true | ||
fail-fast: true | ||
name: PHP ${{ matrix.php }} / ${{ matrix.deps }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
- name: Install dependencies | ||
uses: ramsey/composer-install@v3 | ||
with: | ||
dependency-versions: ${{ matrix.deps }} | ||
- name: Install dependencies (PHPUnit) | ||
uses: ramsey/composer-install@v3 | ||
with: | ||
dependency-versions: locked | ||
working-directory: vendor-bin/phpunit | ||
- name: Install dependencies (PHPStan) | ||
uses: ramsey/composer-install@v3 | ||
if: matrix.phpstan == 1 | ||
with: | ||
dependency-versions: locked | ||
working-directory: vendor-bin/phpstan | ||
- name: Enable assertions | ||
run: | | ||
for dir in /etc/php/*/cli/conf.d; do | ||
echo 'zend.assertions=1' | sudo tee "${dir}/assert.ini" >/dev/null | ||
done | ||
- name: PHPUnit | ||
run: | | ||
vendor-bin/phpunit/vendor/bin/phpunit --version | head -n1 >&2 | ||
if [ "${{ matrix.coverage }}" = "1" ]; then | ||
sudo phpenmod xdebug | ||
vendor-bin/phpunit/vendor/bin/phpunit --coverage-clover=coverage.xml | ||
sudo phpdismod xdebug | ||
else | ||
vendor-bin/phpunit/vendor/bin/phpunit | ||
fi | ||
- name: PHPStan | ||
if: matrix.phpstan == 1 | ||
run: | | ||
(vendor-bin/phpstan/vendor/bin/phpstan analyse --no-progress --error-format=checkstyle || true) | vendor-bin/phpstan/vendor/bin/cs2pr |
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,4 @@ | ||
/.phpunit.cache | ||
/.php-cs-fixer.cache | ||
/vendor | ||
/vendor-bin/**/vendor |
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,25 @@ | ||
<?php | ||
|
||
$finder = (new PhpCsFixer\Finder()) | ||
->in(__DIR__) | ||
; | ||
|
||
return (new PhpCsFixer\Config()) | ||
->setRules([ | ||
'@PER-CS' => true, | ||
'header_comment' => [ | ||
'header' => <<<'EOT' | ||
This file is part of the hCaptcha API Client package. | ||
(c) Wider Plan <[email protected]> | ||
For the full copyright and license information, please view the LICENSE | ||
file that was distributed with this source code. | ||
EOT, | ||
'comment_type' => 'comment', | ||
'location' => 'after_open', | ||
'separate' => 'both' | ||
], | ||
]) | ||
->setFinder($finder) | ||
; |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Wider Plan Ltd | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,19 @@ | ||
.PHONY: ci | ||
ci: cs test phpstan | ||
|
||
.PHONY: cs | ||
cs: vendor | ||
composer validate | ||
vendor/bin/php-cs-fixer fix | ||
|
||
.PHONY: test | ||
test: vendor | ||
vendor/bin/phpunit | ||
|
||
.PHONY: phpstan | ||
phpstan: vendor | ||
vendor/bin/phpstan | ||
|
||
vendor: composer.json vendor-bin/*/composer.json vendor-bin/*/composer.lock | ||
composer update | ||
composer bin all install |
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,63 @@ | ||
hCaptcha API Client | ||
=================== | ||
|
||
|
||
Usage | ||
----- | ||
|
||
### Basic | ||
|
||
With `php-http/discovery` installed this package will be leveraged to attempt to | ||
use the most appropriate implementations of [PSR-7][] and [PSR-18][]. | ||
|
||
```sh | ||
composer require widerplan/hcaptcha php-http/discovery | ||
``` | ||
|
||
```php | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use WiderPlan\Hcaptcha\Client; | ||
|
||
$client = Client::create(getenv('HCAPTCHA_SECRET')); | ||
$result = $client->verify($_POST['h-captcha-response'], getenv('HCAPTCHA_SITE_KEY')); | ||
|
||
if ($result->success) { | ||
// Perform protected action... | ||
} | ||
``` | ||
|
||
### With custom components | ||
|
||
Instead of relying on the automatic discovery you can wire up your chosen implementations. | ||
|
||
```sh | ||
composer require widerplan/hcaptcha symfony/http-client slim/psr7 | ||
``` | ||
|
||
```php | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Slim\Psr7\Factory; | ||
use Symfony\Component\HttpClient\Psr18Client; | ||
use WiderPlan\Hcaptcha\Client; | ||
|
||
$httpClient = new Psr18Client( | ||
null, | ||
new Factory\ResponseFactory(), | ||
new Factory\StreamFactory(), | ||
); | ||
$client = Client::create(getenv('HCAPTCHA_SECRET'), $httpClient); | ||
$result = $client->verify($_POST['h-captcha-response'], getenv('HCAPTCHA_SITE_KEY')); | ||
|
||
if ($result->success) { | ||
// Perform protected action... | ||
} | ||
``` | ||
|
||
[PSR-7]: https://www.php-fig.org/psr/psr-7/ | ||
[PSR-18]: https://www.php-fig.org/psr/psr-18/ |
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,42 @@ | ||
{ | ||
"name": "widerplan/hcaptcha", | ||
"description": "hCaptcha API client", | ||
"type": "library", | ||
"license": "MIT", | ||
"autoload": { | ||
"psr-4": { | ||
"WiderPlan\\Hcaptcha\\": "src/" | ||
} | ||
}, | ||
"require": { | ||
"php": ">= 8.2", | ||
"psr/http-client": "^1.0", | ||
"psr/http-client-implementation": "*", | ||
"psr/http-factory-implementation": "*", | ||
"webmozart/assert": "^1.11" | ||
}, | ||
"require-dev": { | ||
"bamarni/composer-bin-plugin": "^1.8", | ||
"nyholm/psr7": "^1.8", | ||
"php-http/discovery": "^1.17", | ||
"symfony/http-client": "^7.1", | ||
"symfony/var-dumper": "^7.1" | ||
}, | ||
"suggest": { | ||
"php-http/discovery": "For automatic discovery and configuration of HTTP client." | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
"bamarni/composer-bin-plugin": true, | ||
"php-http/discovery": false | ||
}, | ||
"lock": false, | ||
"sort-packages": true | ||
}, | ||
"extra": { | ||
"bamarni-bin": { | ||
"bin-links": true, | ||
"forward-command": false | ||
} | ||
} | ||
} |
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,9 @@ | ||
parameters: | ||
level: max | ||
paths: | ||
- src | ||
- tests | ||
- vendor-bin/phpunit/vendor | ||
excludePaths: | ||
analyse: | ||
- vendor-bin/phpunit/vendor |
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,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.3/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
cacheDirectory=".phpunit.cache" | ||
executionOrder="depends,defects" | ||
shortenArraysForExportThreshold="10" | ||
requireCoverageMetadata="true" | ||
beStrictAboutCoverageMetadata="true" | ||
beStrictAboutOutputDuringTests="true" | ||
failOnRisky="true" | ||
failOnWarning="true" | ||
> | ||
<testsuites> | ||
<testsuite name="hCaptcha API Client"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true"> | ||
<include> | ||
<directory>src</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
Oops, something went wrong.