Пример #1
0
 public function register(Application $app)
 {
     $this->app = $app;
     $app['aiv.namespaced'] = false;
     $app['validator'] = function () use($app) {
         return $app['aiv'];
     };
     $app['aiv'] = $app->share(function (Application $app) {
         $manager = new Manager();
         if ($app['aiv.namespaced']) {
             $manager->enableNamespace();
         }
         $validators = $app['aiv.validators'];
         foreach ($validators as $name => $validatorConstraints) {
             $validator = new Validator();
             $validator->setOptions(isset($validatorConstraints['options']) ? $validatorConstraints['options'] : []);
             $validator->setConstraintResolver($this);
             $validator->setConstraints($validatorConstraints['params']);
             $manager->addValidator($name, $validator);
         }
         $manager->setInput($app['aiv.input']);
         return $manager;
     });
     $app['aiv.input'] = $app->share(function () {
         return new FormInput();
     });
 }
Пример #2
0
 /**
  * test constraint resolver is used for custom constraint config
  */
 public function testSetConstraintResolver()
 {
     $constraint = new \Symfony\Component\Validator\Constraints\NotBlank();
     $validData = ['name' => 'John Smith'];
     $mockConstraintResolver = $this->getMock('AIV\\ConstraintResolverInterface');
     $mockConstraintResolver->expects($this->any())->method('resolve')->will($this->returnValue($constraint));
     $validator = new Validator();
     $validator->setConstraintResolver($mockConstraintResolver);
     $validator->setConstraints(['name' => ['not.blank']]);
     $mockInput = $this->getMock('AIV\\InputInterface');
     $mockInput->expects($this->any())->method('getData')->will($this->returnValue($validData));
     $validator->setInput($mockInput);
     $this->assertFalse($validator->hasErrors());
     $this->assertEquals($validData, $validator->getData());
 }