Skip to content

Commit 4e07a26

Browse files
committed
Merge branch 'master' into 3.2-merge
2 parents e0131a2 + c2c754e commit 4e07a26

6 files changed

Lines changed: 58 additions & 35 deletions

File tree

composer.json

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,28 @@
88
"hyperf"
99
],
1010
"require": {
11-
"php": ">=8.1",
11+
"php": ">=8.2",
1212
"egulias/email-validator": "^3.0",
13-
"hyperf/collection": "~3.1.0",
14-
"hyperf/conditionable": "~3.1.0",
15-
"hyperf/context": "~3.1.0",
16-
"hyperf/contract": "~3.1.0",
17-
"hyperf/di": "~3.1.0",
18-
"hyperf/framework": "~3.1.0",
19-
"hyperf/macroable": "~3.1.0",
20-
"hyperf/stringable": "~3.1.0",
21-
"hyperf/support": "~3.1.0",
22-
"hyperf/tappable": "~3.1.0",
23-
"hyperf/translation": "~3.1.0",
24-
"nesbot/carbon": "^2.21",
13+
"hyperf/collection": "~3.2.0",
14+
"hyperf/conditionable": "~3.2.0",
15+
"hyperf/context": "~3.2.0",
16+
"hyperf/contract": "~3.2.0",
17+
"hyperf/di": "~3.2.0",
18+
"hyperf/framework": "~3.2.0",
19+
"hyperf/macroable": "~3.2.0",
20+
"hyperf/stringable": "~3.2.0",
21+
"hyperf/support": "~3.2.0",
22+
"hyperf/tappable": "~3.2.0",
23+
"hyperf/translation": "~3.2.0",
24+
"nesbot/carbon": "^2.21 || ^3.0",
2525
"psr/container": "^1.0 || ^2.0",
2626
"psr/event-dispatcher": "^1.0",
27-
"psr/http-message": "^1.0 || ^2.0"
27+
"psr/http-message": "^1.0 || ^2.0",
28+
"symfony/polyfill-php83": "^1.33"
2829
},
2930
"suggest": {
30-
"hyperf/database": "Required if you want to use the database validation rule (~3.1.0).",
31-
"hyperf/http-server": "Required if you want to use the request validation rule (~3.1.0)."
31+
"hyperf/database": "Required if you want to use the database validation rule (~3.2.0).",
32+
"hyperf/http-server": "Required if you want to use the request validation rule (~3.2.0)."
3233
},
3334
"autoload": {
3435
"psr-4": {
@@ -45,7 +46,7 @@
4546
},
4647
"extra": {
4748
"branch-alias": {
48-
"dev-master": "3.1-dev"
49+
"dev-master": "3.2-dev"
4950
},
5051
"hyperf": {
5152
"config": "Hyperf\\Validation\\ConfigProvider"

src/Concerns/ValidatesAttributes.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -960,17 +960,7 @@ public function validateJson(string $attribute, $value): bool
960960
return false;
961961
}
962962

963-
if (function_exists('json_validate')) {
964-
return json_validate($value);
965-
}
966-
967-
try {
968-
json_decode($value, flags: JSON_THROW_ON_ERROR);
969-
} catch (Throwable) {
970-
return false;
971-
}
972-
973-
return true;
963+
return json_validate($value);
974964
}
975965

976966
/**

src/ValidationRuleParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ protected static function parseParameters(string $rule, string $parameter): arra
266266
return [$parameter];
267267
}
268268

269-
return str_getcsv($parameter, escape: '\\');
269+
return str_getcsv($parameter, escape: '');
270270
}
271271

272272
/**

src/Validator.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,22 +189,20 @@ public function __construct(
189189
/**
190190
* Handle dynamic calls to class methods.
191191
*
192-
* @param mixed $method
193-
* @param mixed $parameters
194192
* @throws BadMethodCallException when method does not exist
195193
*/
196-
public function __call($method, $parameters)
194+
public function __call(string $name, array $arguments): mixed
197195
{
198-
$rule = StrCache::snake(substr($method, 8));
196+
$rule = StrCache::snake(substr($name, 8));
199197

200198
if (isset($this->extensions[$rule])) {
201-
return $this->callExtension($rule, $parameters);
199+
return $this->callExtension($rule, $arguments);
202200
}
203201

204202
throw new BadMethodCallException(sprintf(
205203
'Method %s::%s does not exist.',
206204
static::class,
207-
$method
205+
$name
208206
));
209207
}
210208

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of Hyperf.
6+
*
7+
* @link https://www.hyperf.io
8+
* @document https://hyperf.wiki
9+
* @contact group@hyperf.io
10+
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11+
*/
12+
13+
namespace HyperfTest\Validation\Cases\Stub;
14+
15+
use Hyperf\Validation\ValidationRuleParser;
16+
17+
class ValidationRuleParserStub extends ValidationRuleParser
18+
{
19+
public static function parseParameters(string $rule, string $parameter): array
20+
{
21+
return parent::parseParameters($rule, $parameter);
22+
}
23+
}

tests/Cases/ValidationRuleTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace HyperfTest\Validation\Cases;
1414

1515
use Hyperf\Validation\Rule;
16+
use HyperfTest\Validation\Cases\Stub\ValidationRuleParserStub;
1617
use PHPUnit\Framework\Attributes\CoversNothing;
1718
use PHPUnit\Framework\TestCase;
1819

@@ -32,4 +33,14 @@ public function testMacroable()
3233
$c = Rule::phone();
3334
$this->assertSame('regex:/^([0-9\s\-\+\(\)]*)$/', $c);
3435
}
36+
37+
public function testParseParameters()
38+
{
39+
$res = ValidationRuleParserStub::parseParameters('in', '1,2,3,4');
40+
$this->assertSame(['1', '2', '3', '4'], $res);
41+
$res = ValidationRuleParserStub::parseParameters('in', '1,2,3,\4');
42+
$this->assertSame(['1', '2', '3', '\4'], $res);
43+
$res = ValidationRuleParserStub::parseParameters('in', '1,2,3,\\\4');
44+
$this->assertSame(['1', '2', '3', '\\\4'], $res);
45+
}
3546
}

0 commit comments

Comments
 (0)