Skip to content

Commit f96db7a

Browse files
committed
Merge branch 'master' into 3.0-merge
# Conflicts: # src/rpn/src/Calculator.php
2 parents a53502d + d451392 commit f96db7a

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Close Pull Request
2+
3+
on:
4+
pull_request_target:
5+
types: [opened]
6+
7+
jobs:
8+
run:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: superbrothers/close-pull-request@v3
12+
with:
13+
comment: "Hi, this is a READ-ONLY repository, please submit your PR on the https://github.com/hyperf/hyperf repository.<br><br> This Pull Request will close automatically.<br><br> Thanks! "

src/Concerns/ValidatesAttributes.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,17 @@ public function validateAlphaNum(string $attribute, $value): bool
167167
*
168168
* @param mixed $value
169169
*/
170-
public function validateArray(string $attribute, $value): bool
170+
public function validateArray(string $attribute, $value, array $parameters = []): bool
171171
{
172-
return is_array($value);
172+
if (! is_array($value)) {
173+
return false;
174+
}
175+
176+
if (empty($parameters)) {
177+
return true;
178+
}
179+
180+
return empty(array_diff_key($value, array_fill_keys($parameters, '')));
173181
}
174182

175183
/**

tests/Cases/ValidationFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function testValidateMethodCanBeCalledPublicly()
110110
$translator = m::mock(TranslatorInterface::class);
111111
$factory = new ValidatorFactory($translator);
112112
$factory->extend('foo', function ($attribute, $value, $parameters, $validator) {
113-
return $validator->validateArray($attribute, $value);
113+
return $validator->validateArray($attribute, $value, $parameters);
114114
});
115115

116116
$validator = $factory->make(['bar' => ['baz']], ['bar' => 'foo']);

tests/Cases/ValidationValidatorTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,15 @@ public function testValidateArray()
650650

651651
$v = new Validator($trans, ['foo' => new SplFileInfo('/tmp/foo')], ['foo' => 'Array']);
652652
$this->assertFalse($v->passes());
653+
654+
$v = new Validator($trans, ['foo' => ['name' => 'foo', 'gender' => 1, 'vote' => 1]], ['foo' => 'Array:name,gender']);
655+
$this->assertFalse($v->passes());
656+
657+
$v = new Validator($trans, ['foo' => ['name' => 'foo', 'gender' => 1]], ['foo' => 'Array:name,gender']);
658+
$this->assertTrue($v->passes());
659+
660+
$v = new Validator($trans, ['foo' => ['name' => 'foo', 'gender' => 1]], ['foo' => 'Array:name,gender,vote']);
661+
$this->assertTrue($v->passes());
653662
}
654663

655664
public function testValidateFilled()
@@ -3468,6 +3477,22 @@ public function testValidateImplicitEachWithAsterisks()
34683477
['foo' => 'Array', 'foo.*.name' => ['Required', 'String'], 'foo.*.votes.*' => ['Required', 'Integer']]
34693478
);
34703479
$this->assertFalse($v->passes());
3480+
3481+
// multiple items fields passes
3482+
$v = new Validator(
3483+
$trans,
3484+
['foo' => [['name' => 'first'], ['name' => 'second']]],
3485+
['foo' => 'Array', 'foo.*' => 'Array:name', 'foo.*.name' => ['Required']]
3486+
);
3487+
$this->assertTrue($v->passes());
3488+
3489+
// multiple items fields fails
3490+
$v = new Validator(
3491+
$trans,
3492+
['foo' => [['name' => 'first', 'votes' => 1], ['name' => 'second', 'votes' => 2]]],
3493+
['foo' => 'Array', 'foo.*' => 'Array:name', 'foo.*.name' => ['Required']]
3494+
);
3495+
$this->assertFalse($v->passes());
34713496
}
34723497

34733498
public function testSometimesOnArraysInImplicitRules()

0 commit comments

Comments
 (0)