Skip to content

Commit 63722b4

Browse files
authored
Support Hyperf 3.0 (#2)
* Support Hyperf 3.0 * Added test cases for php 8.1 8.2 and 8.3 * Added branch alias
1 parent 310c6b8 commit 63722b4

File tree

4 files changed

+53
-34
lines changed

4 files changed

+53
-34
lines changed

.github/workflows/test.yml

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
name: PHPUnit
22

3-
on: [push, pull_request]
3+
on: [ push, pull_request ]
44

55
env:
66
SWOOLE_VERSION: '4.8.0'
77
SWOW_VERSION: 'develop'
88

99
jobs:
10-
ci:
11-
name: Test PHP ${{ matrix.php-version }} on ${{ matrix.engine }}
10+
swow-ci:
11+
name: Test PHP ${{ matrix.php-version }} on Swow
1212
runs-on: "${{ matrix.os }}"
1313
strategy:
1414
matrix:
15-
os: [ubuntu-latest]
16-
php-version: ['8.0']
17-
engine: ['swoole', 'swow']
18-
max-parallel: 5
15+
os: [ ubuntu-latest ]
16+
php-version: [ '8.0', '8.1', '8.2', '8.3' ]
17+
max-parallel: 4
1918
steps:
2019
- name: Checkout
2120
uses: actions/checkout@v2
@@ -26,21 +25,6 @@ jobs:
2625
tools: phpize
2726
ini-values: opcache.enable_cli=1
2827
coverage: none
29-
- name: Setup Swoole
30-
if: ${{ matrix.engine == 'swoole' }}
31-
run: |
32-
sudo apt-get install libcurl4-openssl-dev
33-
wget https://github.com/swoole/swoole-src/archive/v${SWOOLE_VERSION}.tar.gz -O swoole.tar.gz
34-
mkdir -p swoole
35-
tar -xf swoole.tar.gz -C swoole --strip-components=1
36-
rm swoole.tar.gz
37-
cd swoole
38-
phpize
39-
./configure --enable-openssl --enable-http2 --enable-swoole-curl --enable-swoole-json
40-
make -j$(nproc)
41-
sudo make install
42-
sudo sh -c "echo extension=swoole > /etc/php/${{ matrix.php-version }}/cli/conf.d/swoole.ini"
43-
php --ri swoole
4428
- name: Setup Swow
4529
if: ${{ matrix.engine == 'swow' }}
4630
run: |
@@ -59,10 +43,35 @@ jobs:
5943
- name: Setup Redis Server
6044
run: docker run --name redis --restart always -p 6379:6379 -d redis
6145
- name: Setup Swow
62-
if: ${{ matrix.engine == 'swow' }}
6346
run: composer require hyperf/engine-swow
6447
- name: Setup Packages
6548
run: composer update -o
6649
- name: Run Test Cases
6750
run: |
6851
composer test
52+
swoole-ci:
53+
name: Test PHP ${{ matrix.php-version }} on Swoole
54+
runs-on: "${{ matrix.os }}"
55+
strategy:
56+
matrix:
57+
os: [ ubuntu-latest ]
58+
php-version: [ '8.0', '8.1', '8.2', '8.3' ]
59+
max-parallel: 4
60+
steps:
61+
- name: Checkout
62+
uses: actions/checkout@v2
63+
- name: Setup PHP
64+
uses: shivammathur/setup-php@v2
65+
with:
66+
php-version: ${{ matrix.php-version }}
67+
tools: phpize
68+
ini-values: opcache.enable_cli=1
69+
extensions: redis, pdo, pdo_mysql, bcmath, swoole
70+
coverage: none
71+
- name: Setup Redis Server
72+
run: docker run --name redis --restart always -p 6379:6379 -d redis
73+
- name: Setup Packages
74+
run: composer update -o
75+
- name: Run Test Cases
76+
run: |
77+
composer test

composer.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
"description": "KK validation library",
1212
"require": {
1313
"php": ">=8.0",
14-
"ext-mbstring": "*",
15-
"ext-ctype": "*"
14+
"ext-ctype": "*",
15+
"ext-mbstring": "*"
1616
},
1717
"require-dev": {
18-
"hyperf/utils": "^2.2",
19-
"hyperf/validation": "^2.2",
18+
"hyperf/server": "^3.0",
19+
"hyperf/utils": "^3.0",
20+
"hyperf/validation": "^3.0",
2021
"jchook/phpunit-assert-throws": "^1.0",
2122
"mockery/mockery": "^1.4",
2223
"phpunit/phpunit": "^9.5"
@@ -37,6 +38,11 @@
3738
"optimize-autoloader": true,
3839
"sort-packages": true
3940
},
41+
"extra": {
42+
"branch-alias": {
43+
"dev-master": "0.3-dev"
44+
}
45+
},
4046
"scripts": {
4147
"test": "phpunit -c phpunit.xml --colors=always"
4248
}

src/Adapter/HyperfValidator.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
use Hyperf\Contract\TranslatorInterface;
66
use Hyperf\Contract\ValidatorInterface;
7-
use Hyperf\Utils\Arr;
8-
use Hyperf\Utils\Contracts\MessageBag as MessageBagContract;
9-
use Hyperf\Utils\Fluent;
10-
use Hyperf\Utils\MessageBag;
11-
use Hyperf\Utils\Str;
7+
use Hyperf\Collection\Arr;
8+
use Hyperf\Contract\MessageBag as MessageBagContract;
9+
use Hyperf\Support\Fluent;
10+
use Hyperf\Support\MessageBag;
11+
use Hyperf\Stringable\Str;
1212
use Hyperf\Validation\Concerns;
1313
use Hyperf\Validation\Contract\PresenceVerifierInterface;
1414
use Hyperf\Validation\ValidationException;
@@ -17,6 +17,9 @@
1717
use Psr\Container\ContainerInterface;
1818
use RuntimeException;
1919

20+
use function Hyperf\Collection\data_get;
21+
use function Hyperf\Collection\collect;
22+
2023
class HyperfValidator implements ValidatorInterface
2124
{
2225
use Concerns\FormatsMessages;
@@ -337,7 +340,7 @@ public function setPresenceVerifier(PresenceVerifierInterface $presenceVerifier)
337340
/**
338341
* Get the Presence Verifier implementation.
339342
*
340-
*@throws \RuntimeException
343+
* @throws \RuntimeException
341344
*/
342345
public function getPresenceVerifier(): PresenceVerifierInterface
343346
{

src/ValidationException.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
class ValidationException extends \Exception
88
{
9-
#[Pure] public function __construct(protected array $errors)
9+
#[Pure]
10+
public function __construct(protected array $errors)
1011
{
1112
parent::__construct('The given data was invalid');
1213
}

0 commit comments

Comments
 (0)