本文整理汇总了PHP中Symfony\Component\Validator\ExecutionContext::addViolationAt方法的典型用法代码示例。如果您正苦于以下问题:PHP ExecutionContext::addViolationAt方法的具体用法?PHP ExecutionContext::addViolationAt怎么用?PHP ExecutionContext::addViolationAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Validator\ExecutionContext
的用法示例。
在下文中一共展示了ExecutionContext::addViolationAt方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAddViolationAtUsesPassedNullValue
public function testAddViolationAtUsesPassedNullValue()
{
$this->translator->expects($this->once())->method('trans')->with('Error', array('foo' => 'bar'))->will($this->returnValue('Translated error'));
$this->translator->expects($this->once())->method('transChoice')->with('Choice error', 2, array('foo' => 'bar'))->will($this->returnValue('Translated choice error'));
// passed null value should override preconfigured value "invalid"
$this->context->addViolationAt('bam.baz', 'Error', array('foo' => 'bar'), null);
$this->context->addViolationAt('bam.baz', 'Choice error', array('foo' => 'bar'), null, 2);
$this->assertEquals(new ConstraintViolationList(array(new ConstraintViolation('Translated error', 'Error', array('foo' => 'bar'), 'Root', 'foo.bar.bam.baz', null), new ConstraintViolation('Translated choice error', 'Choice error', array('foo' => 'bar'), 'Root', 'foo.bar.bam.baz', null, 2))), $this->context->getViolations());
}
示例2:
function it_validates_if_user_with_given_email_is_already_registered(UserRepository $userRepository, TokenStorageInterface $tokenStorage, AuthorizationCheckerInterface $authorizationChecker, ExecutionContext $context, TokenInterface $token, UniqueReviewerEmail $constraint, ReviewInterface $review, CustomerInterface $customer, CustomerInterface $existingUser)
{
$tokenStorage->getToken()->willReturn($token);
$authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')->willReturn(false);
$review->getAuthor()->willReturn($customer);
$customer->getEmail()->willReturn('john.doe@example.com');
$userRepository->findOneByEmail('john.doe@example.com')->willReturn($existingUser);
$constraint->message = 'This email is already registered. Please log in.';
$context->addViolationAt('author', 'This email is already registered. Please log in.', [], null)->shouldBeCalled();
$this->validate($review, $constraint);
}
示例3: validate
/**
* Validates contact method
*
* @param ContactRequest $object
* @param ExecutionContext $context
*/
public static function validate(ContactRequest $object, ExecutionContext $context)
{
$emailError = $phoneError = false;
switch ($object->getPreferredContactMethod()) {
case ContactRequest::CONTACT_METHOD_PHONE:
$phoneError = !$object->getPhone();
break;
case ContactRequest::CONTACT_METHOD_EMAIL:
$emailError = !$object->getEmailAddress();
break;
case ContactRequest::CONTACT_METHOD_BOTH:
default:
$phoneError = !$object->getPhone();
$emailError = !$object->getEmailAddress();
}
if ($emailError) {
$context->addViolationAt('emailAddress', 'This value should not be blank.');
}
if ($phoneError) {
$context->addViolationAt('phone', 'This value should not be blank.');
}
}
示例4: areImagesValid
public function areImagesValid(ExecutionContext $context)
{
$captured_ids = array_map(function ($image) {
return $image->getId();
}, $this->images->toArray());
$property_path = $context->getPropertyPath() . '.images';
if (!count($captured_ids)) {
$context->addViolationAt($property_path, 'Please select at least one image!', array(), null);
return;
}
$count = $this->query_builder->andWhere($this->query_builder->expr()->in('i.id', $captured_ids))->select('COUNT(i.id)')->getQuery()->getSingleScalarResult();
if (!$count) {
$context->addViolation('Please select images from the list!', array(), null);
}
}
示例5: isRegionValid
public function isRegionValid(ExecutionContext $context)
{
if ($this->getCountry() && $this->getCountry()->hasRegions() && !$this->region && !$this->regionText) {
// do not allow saving text region in case when region was checked from list
// except when in base data region text existed
// another way region_text field will be null, logic are placed in form listener
$propertyPath = $context->getPropertyPath() . '.region';
$context->addViolationAt($propertyPath, 'Region is required for country %country%', array('%country%' => $this->getCountry()->getName()));
}
}
示例6: isRegionValid
public function isRegionValid(ExecutionContext $context)
{
if ($this->getCountry() && $this->getCountry()->hasRegions() && !$this->state) {
$propertyPath = $context->getPropertyPath() . '.state';
$context->addViolationAt($propertyPath, 'State is required for country %country%', array('%country%' => $this->getCountry()->getName()));
}
}
示例7: isValid
/**
* Custom validation constraint
* Not valid if no one recipient specified
*
* @param ExecutionContext $context
*/
public function isValid(ExecutionContext $context)
{
$notValid = $this->getGroups()->isEmpty() && $this->getUsers()->isEmpty() && $this->getEmail() == null && $this->getOwner() == null;
if ($notValid) {
$propertyPath = $context->getPropertyPath() . '.recipientList';
$context->addViolationAt($propertyPath, 'oro.notification.validators.recipient_list.empty.message');
}
}
示例8: isPackageUnique
public function isPackageUnique(ExecutionContext $context)
{
try {
if ($this->entityRepository->findOneByName($this->name)) {
$context->addViolationAt('repository', 'A package with the name <a href="' . $this->router->generate('view_package', array('name' => $this->name)) . '">' . $this->name . '</a> already exists.', array(), null);
}
} catch (\Doctrine\ORM\NoResultException $e) {
}
}
示例9: validate
/**
* validate
*
* @param type $data
* @param ExecutionContext $context
*/
public function validate($data, ExecutionContext $context)
{
if ($data['mode'] === 'add_favorite') {
if (!$this->security->isGranted('ROLE_USER')) {
$context->addViolationAt('', 'ログインしてください.');
}
} else {
$context->validateValue($data['product_class_id'], array(new Assert\NotBlank()), '[product_class_id]');
if ($this->Product->getClassName1()) {
$context->validateValue($data['classcategory_id1'], array(new Assert\NotBlank(), new Assert\NotEqualTo(array('value' => '__unselected', 'message' => 'This value should be blank.'))), '[classcategory_id1]');
}
if ($this->Product->getClassName2()) {
$context->validateValue($data['classcategory_id2'], array(new Assert\NotBlank(), new Assert\NotEqualTo(array('value' => '__unselected', 'message' => 'This value should be blank.'))), '[classcategory_id2]');
}
}
}
示例10: isExpireDateValid
public function isExpireDateValid(ExecutionContext $context)
{
$now = new \DateTime();
$thisYear = (int) $now->format('Y');
$thisMonth = (int) $now->format('m');
$expYear = (int) $this->getExpiryDateYear();
$expMonth = (int) $this->getExpiryDateMonth();
if ($thisYear > $expYear || $thisYear == $expYear && $thisMonth > $expMonth) {
$context->addViolationAt('expiry_date_month', 'expired card', array(), null);
}
}
示例11: isUnderTotalConstraint
public function isUnderTotalConstraint(ExecutionContext $context)
{
$this->getFreeTotal($credit, $debit);
// compare with an epsilon, we're using floats here!
if ($credit < -0.001) {
$context->addViolationAt('credit', 'Le total des factures dépasse le crédit de la ligne de %depassement% €', array('%depassement%' => round($credit, 2) * -1), null);
}
if ($debit < -0.001) {
$context->addViolationAt('debit', 'Le total des factures dépasse le débit de la ligne de %depassement% €', array('%depassement%' => round($debit, 2) * -1), null);
}
}
示例12: checkPasswordLength
public function checkPasswordLength(ExecutionContext $context)
{
if ($this->can_credentials === true && mb_strlen($this->password, 'UTF-8') < 6) {
$context->addViolationAt('password', "Le mot de passe doit faire au minimum 6 caractères");
}
}
示例13: isTvasCorrect
public function isTvasCorrect(ExecutionContext $context)
{
$montant_ht = 0;
foreach ($this->tvas as $tva) {
$montant_ht += $tva->getMontantHt();
}
if (abs($this->montant - $montant_ht) > 0.001) {
// floats -> epsilon!
$context->addViolationAt('tvas', 'La somme des montants HT doit être égale au montant de la facture');
}
}
示例14: isPhoneValid
public function isPhoneValid(ExecutionContext $context)
{
if (!$this->getPhoneNumber() && !$this->getContactPhoneNumber()) {
$propertyPath = $context->getPropertyPath() . '.contactPhoneNumber';
$context->addViolationAt($propertyPath, 'orocrm.call.phone.required.message');
}
}