本文整理汇总了PHP中Symfony\Component\Validator\Validation::createValidatorBuilder方法的典型用法代码示例。如果您正苦于以下问题:PHP Validation::createValidatorBuilder方法的具体用法?PHP Validation::createValidatorBuilder怎么用?PHP Validation::createValidatorBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Validator\Validation
的用法示例。
在下文中一共展示了Validation::createValidatorBuilder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct()
{
$this->validator = Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator();
$this->getSetNormalizer = new GetSetMethodNormalizer();
$this->builder = new Builder();
$this->annotationReader = new AnnotationReader();
}
示例2: validate
public function validate()
{
$this->helper = (include FrontController::getRootPath() . "/src/cli_config.php");
$validator = Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator();
$violations = $validator->validate($this);
return $violations;
}
示例3: createUser
public function createUser()
{
$user = new Test\User();
$post = $this->app->request()->getBody();
$data = json_decode($post);
var_dump($data);
$user->name = $data->name;
$user->email = $data->email;
var_dump($user);
/*
$validator = Validation::createValidator();
$constraint = new Assert\Collection(array(
'email' => new Assert\Email(),
'name' => new Assert\Length(array('min' => 10)),
));
$violations = $validator->validateValue($data, $constraint);
*/
$builder = Validation::createValidatorBuilder();
$builder->addYamlMapping(__DIR__ . '/rules.yml');
$validator = $builder->getValidator();
$violations = $validator->validate($user);
if (0 === count($violations)) {
echo 'valid';
} else {
foreach ($violations as $violation) {
echo $violation->getMessage();
}
}
}
示例4: __construct
public function __construct(Request $request, $type = "form", $data = array(), $options = array())
{
$this->request = $request;
$validator = Validation::createValidatorBuilder();
if (!isset($options["attr"]["name"])) {
$options["attr"]["thelia_name"] = $this->getName();
}
$builder = Forms::createFormFactoryBuilder()->addExtension(new HttpFoundationExtension());
if (!isset($options["csrf_protection"]) || $options["csrf_protection"] !== false) {
$builder->addExtension(new CsrfExtension(new SessionCsrfProvider($request->getSession(), isset($options["secret"]) ? $options["secret"] : ConfigQuery::read("form.secret", md5(__DIR__)))));
}
$translator = Translator::getInstance();
$validator->setTranslationDomain('validators')->setTranslator($translator);
$this->formBuilder = $builder->addExtension(new ValidatorExtension($validator->getValidator()))->getFormFactory()->createNamedBuilder($this->getName(), $type, $data, $this->cleanOptions($options));
$this->buildForm();
// If not already set, define the success_url field
// This field is not included in the standard form hidden fields
// This field is not included in the hidden fields generated by form_hidden_fields Smarty function
if (!$this->formBuilder->has('success_url')) {
$this->formBuilder->add("success_url", "hidden");
}
// The "error_message" field defines the error message displayed if
// the form could not be validated. If it is empty, a standard error message is displayed instead.
// This field is not included in the hidden fields generated by form_hidden_fields Smarty function
if (!$this->formBuilder->has('error_message')) {
$this->formBuilder->add("error_message", "hidden");
}
$this->form = $this->formBuilder->getForm();
}
示例5: testConstraintsValidatorCanBeModified
public function testConstraintsValidatorCanBeModified()
{
$validator = Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator();
Configuration::setConstraintsValidator($validator);
$returnedValidator = Configuration::getConstraintsValidator();
$this->assertEquals($validator, $returnedValidator);
}
示例6: register
public function register(Container $app)
{
$app['validator'] = function ($app) {
return $app['validator.builder']->getValidator();
};
$app['validator.builder'] = function ($app) {
$builder = Validation::createValidatorBuilder();
$builder->setConstraintValidatorFactory($app['validator.validator_factory']);
$builder->setTranslationDomain('validators');
$builder->addObjectInitializers($app['validator.object_initializers']);
$builder->setMetadataFactory($app['validator.mapping.class_metadata_factory']);
if (isset($app['translator'])) {
$builder->setTranslator($app['translator']);
}
return $builder;
};
$app['validator.mapping.class_metadata_factory'] = function ($app) {
return new LazyLoadingMetadataFactory(new StaticMethodLoader());
};
$app['validator.validator_factory'] = function () use($app) {
return new ConstraintValidatorFactory($app, $app['validator.validator_service_ids']);
};
$app['validator.object_initializers'] = function ($app) {
return array();
};
$app['validator.validator_service_ids'] = array();
}
示例7: getMetaValidator
public function getMetaValidator($allowedLocales = array(), $intlExtension = false, $strict = false)
{
$factory = new ConstraintValidatorFactory($this->getLocaleValidator($intlExtension), $this->getLocaleAllowedValidator($intlExtension, $allowedLocales, $strict));
$validator = Validation::createValidatorBuilder();
$validator->setConstraintValidatorFactory($factory);
return new MetaValidator($validator->getValidator());
}
示例8: testCreate
public function testCreate()
{
$teamA = new Team();
$teamA->setPlayerA(new Player(1, 'John Doe'));
$teamA->setPlayerB(new Player(2, 'James Doe'));
$teamB = new Team();
$teamB->setPlayerA(new Player(3, 'John Smith'));
$teamB->setPlayerB(new Player(4, 'James Smith'));
$setScore = new SetScore();
$setScore->setScoresByString('21-18');
$match = new Match();
$match->setTeamA($teamA);
$match->setTeamB($teamB);
$match->addSetScore($setScore);
$match->addSetScoreByString('21-16');
$match->setGameTimeLengthInSeconds(5);
$validator = Validation::createValidatorBuilder()->addMethodMapping('loadValidatorMetadata')->getValidator();
$this->assertEmpty($validator->validate($match));
$this->assertTrue($match->getTeamA() instanceof Team);
$this->assertTrue($match->getTeamB() instanceof Team);
$this->assertSame(2, count($match->getSetScores()));
$this->assertTrue($match->getSetscores()[0] instanceof SetSCore);
$this->assertTrue($match->getSetscore(1) instanceof SetSCore);
$this->assertSame(null, $match->getSetScore(3));
$this->assertSame(5, $match->getGameTimeLengthInSeconds());
$this->assertSame('[(1) John Doe, (2) James Doe] def [(3) John Smith, (4) James Smith]', $match->__toString());
}
示例9: register
public function register(Application $app)
{
$app['validator'] = $app->share(function ($app) {
return $app['validator.builder']->getValidator();
});
$app['validator.builder'] = $app->share(function ($app) {
$builder = Validation::createValidatorBuilder();
$builder->setConstraintValidatorFactory($app['validator.validator_factory']);
$builder->setTranslationDomain('validators');
$builder->addObjectInitializers($app['validator.object_initializers']);
$builder->setMetadataFactory($app['validator.mapping.class_metadata_factory']);
if (isset($app['translator'])) {
$builder->setTranslator($app['translator']);
}
return $builder;
});
$app['validator.mapping.class_metadata_factory'] = $app->share(function ($app) {
if (class_exists('Symfony\\Component\\Validator\\Mapping\\Factory\\LazyLoadingMetadataFactory')) {
return new LazyLoadingMetadataFactory(new StaticMethodLoader());
}
return new ClassMetadataFactory(new StaticMethodLoader());
});
$app['validator.validator_factory'] = $app->share(function () use($app) {
return new ConstraintValidatorFactory($app, $app['validator.validator_service_ids']);
});
$app['validator.object_initializers'] = $app->share(function ($app) {
return array();
});
$app['validator.validator_service_ids'] = array();
}
示例10: __construct
public function __construct()
{
$builder = Validation::createValidatorBuilder();
$builder->setConstraintValidatorFactory(new ConstraintValidatorFactory());
$builder->setMetadataFactory(new LazyLoadingMetadataFactory(new StaticMethodLoader()));
parent::__construct($builder->getValidator());
}
示例11: getValidator
/**
* @return ValidatorInterface
*/
public function getValidator()
{
if (is_null($this->validator)) {
$this->validator = Validation::createValidatorBuilder()->enableAnnotationMapping($this->getAnnotationReader())->getValidator();
}
return $this->validator;
}
示例12: getValidator
/**
* @param Reader $reader
*
* @return ValidatorInterface
*/
public function getValidator(Reader $reader = null)
{
if (null === $reader) {
$reader = new AnnotationReader();
}
return Validation::createValidatorBuilder()->enableAnnotationMapping($reader)->getValidator();
}
示例13: register
public function register(Container $app)
{
$app['validator'] = function ($app) {
if (isset($app['translator'])) {
$r = new \ReflectionClass('Symfony\\Component\\Validator\\Validation');
$file = dirname($r->getFilename()) . '/Resources/translations/validators.' . $app['locale'] . '.xlf';
if (file_exists($file)) {
$app['translator']->addResource('xliff', $file, $app['locale'], 'validators');
}
}
return $app['validator.builder']->getValidator();
};
$app['validator.builder'] = function ($app) {
$builder = Validation::createValidatorBuilder();
$builder->setConstraintValidatorFactory($app['validator.validator_factory']);
$builder->setTranslationDomain('validators');
$builder->addObjectInitializers($app['validator.object_initializers']);
$builder->setMetadataFactory($app['validator.mapping.class_metadata_factory']);
if (isset($app['translator'])) {
$builder->setTranslator($app['translator']);
}
return $builder;
};
$app['validator.mapping.class_metadata_factory'] = function ($app) {
return new LazyLoadingMetadataFactory(new StaticMethodLoader());
};
$app['validator.validator_factory'] = function () use($app) {
$validators = isset($app['validator.validator_service_ids']) ? $app['validator.validator_service_ids'] : array();
return new ConstraintValidatorFactory($app, $validators);
};
$app['validator.object_initializers'] = function ($app) {
return array();
};
}
示例14: setUp
/**
* Setting up the validator.
*/
protected function setUp()
{
$this->now = new \DateTime();
$this->validator = Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator();
$this->baseVacancy = new Vacancy();
$this->baseVacancy = $this->baseVacancy->setId(1)->setTitle("this is a title")->setDescription("this is a description for a vacancy")->setStartDate($this->now)->setUrlid("/vacancy/this_is_a_title");
}
示例15: testPassesValidationWithNullScoreWithForfeit
public function testPassesValidationWithNullScoreWithForfeit()
{
$setScore = new SetScore();
$setScore->setTeamBForfeit();
$validator = Validation::createValidatorBuilder()->addMethodMapping('loadValidatorMetadata')->getValidator();
$this->assertEmpty($validator->validate($setScore));
}