本文整理汇总了PHP中Symfony\Component\Validator\ExecutionContextInterface::addViolationAt方法的典型用法代码示例。如果您正苦于以下问题:PHP ExecutionContextInterface::addViolationAt方法的具体用法?PHP ExecutionContextInterface::addViolationAt怎么用?PHP ExecutionContextInterface::addViolationAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Validator\ExecutionContextInterface
的用法示例。
在下文中一共展示了ExecutionContextInterface::addViolationAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* @Assert\Callback
*/
public function validate(ExecutionContextInterface $context)
{
// Vérifie si le nom est bidon
if ($this->getDebut() > $this->getFin()) {
$context->addViolationAt('fin', 'La date de début ne peut être postérieure à la date de fin');
}
$datesysteme = new \Datetime();
if ($this->getFin() < $datesysteme) {
$context->addViolationAt('fin', 'La date de fin ne peut être antérieure à la date du jour');
}
}
示例2: checkEndDate
/**
* Validation function for optional constraints
*
* @param RentRecoveryPlusCancellation $cancellation
* @param ExecutionContextInterface $context
*/
public function checkEndDate($cancellation, ExecutionContextInterface $context)
{
$expiresAt = new \DateTime($cancellation->getPolicyExpiresAt());
$endAt = new \DateTime($cancellation->getPolicyEndAt());
$now = new \DateTime();
$now->setTime(0, 0, 0);
if ($endAt > $expiresAt) {
$context->addViolationAt('policyEndAt', 'Requested date exceeds existing end date of ' . $expiresAt->format('d-m-Y'), array(), null);
} else {
if ($endAt < $now) {
$context->addViolationAt('policyEndAt', 'Requested date is in the past', array(), null);
}
}
}
示例3: checkAtLeastOnePhoneNumberIsDefined
public function checkAtLeastOnePhoneNumberIsDefined($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
if (empty($data["phone"]) && empty($data["cellphone"])) {
$context->addViolationAt("phone", Translator::getInstance()->trans("Please enter a home or mobile phone number"));
}
}
示例4: isSubjectValid
public function isSubjectValid(ExecutionContextInterface $context)
{
$text = preg_replace(array('/<a[^>]+href[^>]+>/', '/<\\/a>/'), '', $this->subjectParsed);
if (mb_strlen($text, 'utf-8') > 500) {
$context->addViolationAt('subject', 'The subject too long');
}
}
示例5: isValid
public function isValid(ExecutionContextInterface $context)
{
$is_valid = $this->start <= $this->end;
if (!$is_valid) {
$context->addViolationAt('end', 'bladetester_calendar.validation.event_dates', array(), null);
}
}
示例6: isVoteValid
/**
* {@inheritdoc}
*/
public function isVoteValid(ExecutionContextInterface $context)
{
if (!$this->checkValue($this->value)) {
$message = 'A vote cannot have a 0 value';
$propertyPath = $context->getPropertyPath() . '.value';
$context->addViolationAt($propertyPath, $message);
}
}
示例7: isSettingsValid
/**
* Validate settings
*
* @param ExecutionContext $context
*/
public function isSettingsValid(ExecutionContextInterface $context)
{
foreach ($this->getSettings() as $value) {
if (is_array($value)) {
$context->addViolationAt('settings', 'A multidimensional array is not allowed, only use key-value pairs.');
}
}
}
示例8: addViolation
/**
* {@inheritdoc}
*/
public function addViolation()
{
if ($this->propertyPath) {
$this->context->addViolationAt($this->propertyPath, $this->message, $this->parameters, $this->invalidValue, $this->plural, $this->code);
return;
}
$this->context->addViolation($this->message, $this->parameters, $this->invalidValue, $this->plural, $this->code);
}
示例9: isNiveauValid
public function isNiveauValid(ExecutionContextInterface $context)
{
if ((int) $this->niveau >= count(self::getNiveaux())) {
// La règle est violée, on définit l'erreur et son message
// 1er argument : on dit quel attribut l'erreur concerne, ici « contenu »
// 2e argument : le message d'erreur
$context->addViolationAt('niveau', sprintf('Niveau invalide, il doit être parmis "%s".', implode(', ', self::getNiveaux())));
}
}
示例10: isCorrectRequiredFields
public function isCorrectRequiredFields(ExecutionContextInterface $context)
{
if ($this->group->getFillFieldsRequired()) {
$groupFieldsIds = $this->group->getFieldsIds();
$userFieldsIds = $this->getFieldsIds();
if (!empty(array_diff($groupFieldsIds, $userFieldsIds))) {
$context->addViolationAt('fields', 'Please to fill required fields', array(), null);
}
}
}
示例11: contenuValide
public function contenuValide(ExecutionContextInterface $context)
{
$mots_interdits = array('échec', 'abandon');
// On verfie que le contenu ne contient pas l'un des mots
if (preg_match('#' . implode('|', $mots_interdits) . '#', $this->getContenu())) {
//La regle est violé, on definit le l'erreur et son message
// 1 er argument : on dit quel attribut l'erreur concerne, ici <<contenu >>
// 2 e argument : le message d'erreur
$context->addViolationAt('contenu', 'Contenu invalide car il contient un mot inderdit, array(), null');
}
}
示例12: addViolation
/**
* @param string|array $message
* @param array $parameters
* @param null $value
*
* @return ErrorElement
*/
public function addViolation($message, $parameters = array(), $value = null)
{
if (is_array($message)) {
$value = isset($message[2]) ? $message[2] : $value;
$parameters = isset($message[1]) ? (array) $message[1] : array();
$message = isset($message[0]) ? $message[0] : 'error';
}
$subPath = (string) $this->getCurrentPropertyPath();
$this->context->addViolationAt($subPath, $message, $parameters, $value);
$this->errors[] = array($message, $parameters, $value);
return $this;
}
示例13: checkStock
public function checkStock($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
if (null === $data["product_sale_elements_id"]) {
$context->addViolationAt("quantity", Translator::getInstance()->trans("Invalid product_sale_elements"));
} else {
$productSaleElements = ProductSaleElementsQuery::create()->filterById($data["product_sale_elements_id"])->filterByProductId($data["product"])->findOne();
$product = $productSaleElements->getProduct();
if ($productSaleElements->getQuantity() < $value && $product->getVirtual() === 0 && ConfigQuery::checkAvailableStock()) {
$context->addViolation(Translator::getInstance()->trans("quantity value is not valid"));
}
}
}
示例14: addViolation
/**
* @param string|array $message
* @param array $parameters
* @param null $value
*
* @return ErrorElement
*/
public function addViolation($message, $parameters = array(), $value = null)
{
if (is_array($message)) {
$value = isset($message[2]) ? $message[2] : $value;
$parameters = isset($message[1]) ? (array) $message[1] : array();
$message = isset($message[0]) ? $message[0] : 'error';
}
$subPath = (string) $this->getCurrentPropertyPath();
if ($this->context instanceof LegacyExecutionContextInterface) {
$this->context->addViolationAt($subPath, $message, $parameters, $value);
} else {
$this->context->buildViolation($message)->atPath($subPath)->setParameters($parameters)->setInvalidValue($value)->addViolation();
}
$this->errors[] = array($message, $parameters, $value);
return $this;
}
示例15: validateMethod
public function validateMethod(ExecutionContextInterface $context)
{
if ($this->fakerConfig && !in_array($this->getMethod(), array_keys($this->fakerConfig->getMethods()))) {
$context->addViolationAt('method', 'This method \'{{ method }}\' is not available in Faker.', ['{{ method }}' => $this->getMethod()], null);
}
}