本文整理汇总了PHP中Symfony\Component\Validator\Validator\ValidatorInterface::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP ValidatorInterface::validate方法的具体用法?PHP ValidatorInterface::validate怎么用?PHP ValidatorInterface::validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Validator\Validator\ValidatorInterface
的用法示例。
在下文中一共展示了ValidatorInterface::validate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: apply
public function apply(Request $request, ParamConverter $configuration)
{
$name = $configuration->getName();
$snakeCasedName = $this->camelCaseToSnakeCase($name);
$class = $configuration->getClass();
$json = $request->getContent();
$object = json_decode($json, true);
if (!isset($object[$snakeCasedName]) || !is_array($object[$snakeCasedName])) {
throw new BadJsonRequestException([sprintf("Missing parameter '%s'", $name)]);
}
$object = $object[$snakeCasedName];
$convertedObject = new $class();
$errors = [];
foreach ($object as $key => $value) {
$properlyCasedKey = lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $key))));
if (!property_exists($convertedObject, $properlyCasedKey)) {
$errors[] = sprintf("Unknown property '%s.%s'", $snakeCasedName, $key);
continue;
}
$convertedObject->{$properlyCasedKey} = $value;
}
$violations = $this->validator->validate($convertedObject);
if (count($errors) + count($violations) > 0) {
throw BadJsonRequestException::createForViolationsAndErrors($violations, $name, $errors);
}
$request->attributes->set($name, $convertedObject);
}
示例2: validate
/**
* @param SourceInterface $source
*
* @throws ValidationException
*/
protected function validate(SourceInterface $source)
{
$violations = $this->validator->validate($source);
if ($violations->count()) {
throw ValidationException::create($violations);
}
}
示例3: execute
/**
* @param CommandInterface $command
* @return bool
*/
public function execute(CommandInterface $command)
{
if (!$command instanceof EditMemberCommand) {
throw new \DomainException("Internal error, silahkan hubungi CS kami");
}
$command->setRepository($this->member_repo);
$violation = $this->validator->validate($command);
if ($violation->count() > 0) {
$message = $violation->get(0)->getMessage();
throw new \DomainException($message);
}
// $member = new Member();
$member = $this->app->em->getRepository("Mabes\\Entity\\Member")->find($command->getAccountId());
$member->setEmail($command->getEmail());
$member->setAccountNumber($command->getAccountNumber());
$member->setAccountHolder($command->getAccountHolder());
$member->setBankName($command->getBankName());
$member->setFullName($command->getFullname());
$member->setAddress($command->getAddress());
$member->setPhone($command->getPhone());
$this->app->em->flush();
// $this->member_repo->save($member);
$data = ["account_id" => $member->getAccountId(), "email" => $member->getEmail(), "phone" => $member->getPhone(), "fullname" => $member->getFullName(), "bank_name" => $member->getBankName(), "account_number" => $member->getAccountNumber(), "account_holder" => $member->getAccountHolder(), "address" => $member->getAddress(), "date" => date("Y-m-d H:i:s")];
$this->event_emitter->emit("validation.created", [$data]);
return true;
}
示例4: validateUser
/**
* @param User $user
* @throws CreateUserException
*/
private function validateUser(User $user)
{
$violations = $this->validator->validate($user);
if ($violations->count()) {
throw new CreateUserException($violations, 'Invalid User entity.');
}
}
示例5: testValidationConfiguration
public function testValidationConfiguration()
{
$valid = $this->validator->validate(new ProductCollection([]));
$this->assertCount(1, $valid);
$productCollectionWithWrongProduct = new ProductCollection([new Product()]);
$this->assertCount(3, $this->validator->validate($productCollectionWithWrongProduct));
}
示例6: tryValidate
private function tryValidate(Category $category)
{
$errors = $this->validator->validate($category);
if (count($errors)) {
throw new \Exception(implode('\\n', $errors));
}
}
示例7: validate
/**
*
* @param object $object
* @throws ValidationException
*/
public function validate($object)
{
$violations = $this->validator->validate($object);
if (count($violations) > 0) {
throw new ValidationException($violations);
}
}
示例8: validate
/**
* {@inheritdoc}
*/
public function validate(ServiceReference $service, array $arguments)
{
$validationResult = array();
$parameterCount = 0;
$validatedCount = 0;
$hasStrictFailure = false;
foreach ($arguments as $name => $value) {
if (strpos($name, '__internal__') !== false) {
continue;
}
$constraints = $service->getParameterConstraints($name);
$validationGroups = $service->getParameterValidationGroups($name);
$isStrictValidation = $service->isStrictParameterValidation($name);
if (!empty($constraints)) {
$violations = $this->validator->validate($value, $constraints, $validationGroups);
if (count($violations)) {
$validationResult[$name] = $violations;
if ($isStrictValidation) {
$hasStrictFailure = true;
}
}
$validatedCount++;
}
$parameterCount++;
}
if ($this->strict && $parameterCount !== $validatedCount) {
throw new StrictArgumentValidationException();
}
if (!empty($validationResult)) {
throw new ArgumentValidationException(new ArgumentValidationResult($validationResult), $hasStrictFailure);
}
}
示例9: validate
/**
* @inheritdoc
*/
public function validate($value, Param $param)
{
$constraint = $this->getRequirementsConstraint($value, $param);
if (null !== $constraint) {
$constraint = [$constraint];
if ($param->allowBlank === false) {
$constraint[] = new NotBlank();
}
if ($param->nullable === false) {
$constraint[] = new NotNull();
}
} else {
$constraint = [];
}
if ($param->array) {
$constraint = [new All(['constraints' => $constraint])];
}
if ($param->incompatibles) {
$constraint[] = new IncompatibleParams($param->incompatibles);
}
if (!count($constraint)) {
return new ConstraintViolationList();
}
return $this->validator->validate($value, $constraint);
}
示例10: process
/**
* {@inheritdoc}
*/
public function process($item)
{
$entity = $this->findOrCreateObject($item);
try {
$this->updater->update($entity, $item);
} catch (\InvalidArgumentException $exception) {
$this->skipItemWithMessage($item, $exception->getMessage(), $exception);
}
$violations = $this->validator->validate($entity);
if ($violations->count() > 0) {
$this->objectDetacher->detach($entity);
$this->skipItemWithConstraintViolations($item, $violations);
}
$rawParameters = $entity->getRawParameters();
if (!empty($rawParameters)) {
$job = $this->jobRegistry->get($entity->getJobName());
$parameters = $this->jobParamsFactory->create($job, $rawParameters);
$violations = $this->jobParamsValidator->validate($job, $parameters);
if ($violations->count() > 0) {
$this->objectDetacher->detach($entity);
$this->skipItemWithConstraintViolations($item, $violations);
}
}
return $entity;
}
示例11: validateCommand
/**
* @param mixed $command
*
* @return array
*/
private function validateCommand($command)
{
if ($this->validator) {
return $this->validator->validate($command);
}
return null;
}
示例12: validate
/**
* @param string $dataClass Parent entity class name
* @param File|Attachment $entity File entity
* @param string $fieldName Field name where new file/image field was added
*
* @return \Symfony\Component\Validator\ConstraintViolationListInterface
*/
public function validate($dataClass, $entity, $fieldName = '')
{
/** @var Config $entityAttachmentConfig */
if ($fieldName === '') {
$entityAttachmentConfig = $this->attachmentConfigProvider->getConfig($dataClass);
$mimeTypes = $this->getMimeArray($entityAttachmentConfig->get('mimetypes'));
if (!$mimeTypes) {
$mimeTypes = array_merge($this->getMimeArray($this->config->get('oro_attachment.upload_file_mime_types')), $this->getMimeArray($this->config->get('oro_attachment.upload_image_mime_types')));
}
} else {
$entityAttachmentConfig = $this->attachmentConfigProvider->getConfig($dataClass, $fieldName);
/** @var FieldConfigId $fieldConfigId */
$fieldConfigId = $entityAttachmentConfig->getId();
if ($fieldConfigId->getFieldType() === 'file') {
$configValue = 'upload_file_mime_types';
} else {
$configValue = 'upload_image_mime_types';
}
$mimeTypes = $this->getMimeArray($this->config->get('oro_attachment.' . $configValue));
}
$fileSize = $entityAttachmentConfig->get('maxsize') * 1024 * 1024;
foreach ($mimeTypes as $id => $value) {
$mimeTypes[$id] = trim($value);
}
return $this->validator->validate($entity->getFile(), [new FileConstraint(['maxSize' => $fileSize, 'mimeTypes' => $mimeTypes])]);
}
示例13: validate
/**
* @param Validatable $comment
*
* @throws ValidationError
* @return void
*/
public function validate(Validatable $comment)
{
$errors = $this->validator->validate($comment);
if ($errors->count()) {
throw new ValidationError($errors);
}
}
示例14: validate
public function validate($value, Constraint $constraint)
{
if (!$value instanceof OrderInterface) {
$this->context->buildViolation('Value should implements OrderInterface')->addViolation();
}
if ($value->getUser() === null) {
$emailErrors = $this->validator->validate($value->getEmail(), [new NotNull(), new Email()]);
foreach ($emailErrors as $error) {
$this->context->buildViolation($error->getMessage())->addViolation();
}
}
$shippingAddressErrors = $this->validator->validate($value->getShippingAddress());
if (count($shippingAddressErrors)) {
/** @var ConstraintViolation $error */
foreach ($shippingAddressErrors as $error) {
$this->context->buildViolation($error->getMessage())->addViolation();
}
}
if ($value->isDifferentBillingAddress()) {
$billingAddressErrors = $this->validator->validate($value->getBillingAddress());
if (count($billingAddressErrors)) {
/** @var ConstraintViolation $error */
foreach ($billingAddressErrors as $error) {
$this->context->buildViolation($error->getMessage())->addViolation();
}
}
}
}
示例15: tryValidate
private function tryValidate(Article $article)
{
$errors = $this->validator->validate($article);
if (count($errors)) {
throw new \Exception(implode('\\n', $errors));
}
}