作者:KasaiDo
项目:FoolFram
/**
* Runs the validation against the provided array of fields
*
* @param array $data
*/
public function validate(array $data)
{
$this->original_values = $data;
$this->final_values = $data;
$validator = SymfonyValidation::createValidator();
$violations_arr = [];
$this->violations = new ViolationCollection([]);
foreach ($this->constraints as $key => $constraint) {
// we always keep the variables set someway
if (!isset($this->final_values[$key])) {
$this->final_values[$key] = false;
}
// if it isn't an array and we just request a Trim
if (!is_array($constraint) && $constraint instanceof ActiveConstraint) {
$this->final_values[$key] = $constraint->run($this->final_values[$key]);
// it's not a classic symfony constraint, get rid of it
$constraint = [];
}
if (is_array($constraint)) {
foreach ($constraint as $k => $c) {
if ($c instanceof ActiveConstraint) {
$this->final_values[$key] = $c->run($this->final_values[$key]);
// it's not a classic symfony constraint, get rid of it
unset($constraint[$k]);
}
}
}
$violations = $validator->validateValue($this->final_values[$key], $constraint);
if ($violations->count() > 0) {
$violations_arr[$key] = new Violation($violations, $key, $this->labels[$key]);
}
$this->violations = new ViolationCollection($violations_arr);
}
}
作者:barryvd
项目:laravel-form-bridg
public function __construct()
{
$builder = Validation::createValidatorBuilder();
$builder->setConstraintValidatorFactory(new ConstraintValidatorFactory());
$builder->setMetadataFactory(new LazyLoadingMetadataFactory(new StaticMethodLoader()));
parent::__construct($builder->getValidator());
}
作者:Sententiaregu
项目:LocaleBundl
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());
}
作者:jujhars1
项目:gearman-ui.docke
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();
}
作者:adam-paterso
项目:orocommerc
/**
* @return array
*/
protected function getExtensions()
{
$accountUserRoleSelectType = new EntitySelectTypeStub($this->getRoles(), AccountUserRoleSelectType::NAME, new AccountUserRoleSelectType());
$addressEntityType = new EntityType($this->getAddresses(), 'test_address_entity');
$accountSelectType = new AccountSelectTypeStub($this->getAccounts(), AccountSelectType::NAME);
return [new PreloadedExtension([OroDateType::NAME => new OroDateType(), AccountUserRoleSelectType::NAME => $accountUserRoleSelectType, $accountSelectType->getName() => $accountSelectType, AddressCollectionTypeStub::NAME => new AddressCollectionTypeStub(), $addressEntityType->getName() => $addressEntityType], []), new ValidatorExtension(Validation::createValidator())];
}
作者:krzysztof-gzoch
项目:pay
/**
* @param Reader $reader
*
* @return ValidatorInterface
*/
public function getValidator(Reader $reader = null)
{
if (null === $reader) {
$reader = new AnnotationReader();
}
return Validation::createValidatorBuilder()->enableAnnotationMapping($reader)->getValidator();
}
作者:amstaffi
项目:rest-crud-action
protected function setUp()
{
parent::setUp();
$this->serializer = SerializerBuilder::create()->build();
$this->validator = Validation::createValidator();
$this->action->setSerializer($this->serializer)->setValidator($this->validator);
}
作者:degara
项目:openpay-php-clien
public function validate(array $parameters)
{
$validator = Validation::createValidator();
$constraints = new Collection(['method' => new Assert\Required(), 'source_id' => [new Assert\Required(), new Assert\Length(['max' => 45])], 'amount' => [new Assert\GreaterThan(0), new Assert\Required()], 'currency' => [new Assert\Length(3), new Assert\Optional()], 'description' => [new Assert\Length(['max' => 250]), new Assert\Required()], 'order_id' => [new Assert\Length(['max' => 100]), new Assert\Optional()], 'device_session_id' => [new Assert\Length(['max' => 255]), new Assert\Optional()], 'capture' => new Assert\Optional(), 'customer' => new Assert\Optional(), 'metadata' => new Assert\Optional(), 'use_card_points' => new Assert\Optional()]);
$violations = $validator->validate($parameters, $constraints);
return $violations;
}
作者:rayrutje
项目:Sile
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();
};
}
作者:degara
项目:openpay-php-clien
public function validate(array $parameters)
{
$validator = Validation::createValidator();
$constraints = new Collection(['token_id' => new Assert\Required(), 'device_session_id' => new Assert\Optional()]);
$violations = $validator->validate($parameters, $constraints);
return $violations;
}
作者:degara
项目:openpay-php-clien
public function validate(array $parameters)
{
$validator = Validation::createValidator();
$constraints = new Collection(['line1' => new Assert\Required(), 'line2' => new Assert\Optional(), 'line3' => new Assert\Optional(), 'postal_code' => new Assert\Length(['min' => 5]), 'state' => [new Assert\Length(['min' => 2]), new Assert\Required()], 'city' => new Assert\Required(), 'country_code' => [new Assert\Length(['min' => 2, 'max' => 2]), new Assert\Required()]]);
$violations = $validator->validate($parameters, $constraints);
return $violations;
}
作者:antarestupi
项目:Accessibl
public function testConstraintsValidatorCanBeModified()
{
$validator = Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator();
Configuration::setConstraintsValidator($validator);
$returnedValidator = Configuration::getConstraintsValidator();
$this->assertEquals($validator, $returnedValidator);
}
作者:degara
项目:openpay-php-clien
public function validate(array $parameters)
{
$validator = Validation::createValidator();
$constraints = new Collection(['customer_id' => [new Assert\Required(), new Assert\Length(['max' => 45])], 'amount' => [new Assert\GreaterThan(0), new Assert\Required()], 'description' => [new Assert\Length(['max' => 250]), new Assert\Required()], 'order_id' => [new Assert\Length(['max' => 100]), new Assert\Optional()]]);
$violations = $validator->validate($parameters, $constraints);
return $violations;
}
作者:pdt25
项目:vbscrape
public function testPassesValidationWithNullScoreWithForfeit()
{
$setScore = new SetScore();
$setScore->setTeamBForfeit();
$validator = Validation::createValidatorBuilder()->addMethodMapping('loadValidatorMetadata')->getValidator();
$this->assertEmpty($validator->validate($setScore));
}
作者:howest-wsd
项目:VrijwilligersToo
/**
* 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");
}
作者:deltaph
项目:deltacor
protected function getFormValidator()
{
if (is_null($this->formValidator)) {
$this->formValidator = \Symfony\Component\Validator\Validation::createValidator();
}
return $this->formValidator;
}
作者:Jandersolution
项目:mauti
/**
* @param $type
* @param $value
* @param null $f
*
* @return array
*/
public function validateFieldValue($type, $value, $f = null)
{
$errors = array();
if (isset($this->types[$type]['constraints'])) {
$validator = Validation::createValidator();
foreach ($this->types[$type]['constraints'] as $constraint => $opts) {
//don't check empty values unless the constraint is NotBlank
if (strpos($constraint, 'NotBlank') === false && empty($value)) {
continue;
}
if ($type == 'captcha' && strpos($constraint, 'EqualTo') !== false) {
$props = $f->getProperties();
$opts['value'] = $props['captcha'];
}
$violations = $validator->validateValue($value, new $constraint($opts));
if (count($violations)) {
foreach ($violations as $v) {
$transParameters = $v->getMessageParameters();
if ($f !== null) {
$transParameters['%label%'] = """ . $f->getLabel() . """;
}
$errors[] = $this->translator->trans($v->getMessage(), $transParameters, 'validators');
}
}
}
}
return $errors;
}
作者:epopliv
项目:pillo
public function validate()
{
$this->helper = (include FrontController::getRootPath() . "/src/cli_config.php");
$validator = Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator();
$violations = $validator->validate($this);
return $violations;
}
作者:pdt25
项目:vbscrape
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());
}
作者:suramo
项目:entity-serialize
public function __construct()
{
$this->validator = Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator();
$this->getSetNormalizer = new GetSetMethodNormalizer();
$this->builder = new Builder();
$this->annotationReader = new AnnotationReader();
}