diff --git a/lib/IsEach.php b/lib/IsEach.php index aa462fb2e..9f8023dca 100644 --- a/lib/IsEach.php +++ b/lib/IsEach.php @@ -61,9 +61,8 @@ protected function doValidate($input) } $result = true; - $options = $this->getValidatorOptions(); - foreach ($input as $i => $row) { + $options = $this->getValidatorOptions(); $options['data'] = $row; $validator = wei()->validate($options); $this->selfValidators[$i] = $validator; diff --git a/tests/unit/IsEachTest.php b/tests/unit/IsEachTest.php index 86c1f9e4b..c8379dc32 100644 --- a/tests/unit/IsEachTest.php +++ b/tests/unit/IsEachTest.php @@ -183,6 +183,31 @@ public function testCallableParameter() $this->assertRetErr($ret, 'The 2nd 用户\'s 姓名 must have a length greater than 3'); } + public function testCreateNewInstanceEveryTime() + { + $validators = []; + $ret = V + ::key('users', '用户')->each(function (V $v) use (&$validators) { + $validators[] = $v; + $v->string('name', '姓名')->minLength(3) + ->string('email', '邮箱')->email(); + }) + ->check([ + 'users' => [ + [ + 'name' => 'test', + 'email' => 'test@example.com', + ], + [ + 'name' => 't', + 'email' => 't', + ], + ], + ]); + $this->assertRetErr($ret, 'The 2nd 用户\'s 姓名 must have a length greater than 3'); + $this->assertNotSame($validators[0], $validators[1]); + } + public function testNotArray() { $ret = V