本文整理汇总了PHP中Symfony\Component\Validator\Context\ExecutionContextInterface::addViolationAt方法的典型用法代码示例。如果您正苦于以下问题:PHP ExecutionContextInterface::addViolationAt方法的具体用法?PHP ExecutionContextInterface::addViolationAt怎么用?PHP ExecutionContextInterface::addViolationAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Validator\Context\ExecutionContextInterface
的用法示例。
在下文中一共展示了ExecutionContextInterface::addViolationAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isValidUppMsgType
/**
* @param ExecutionContextInterface $context
*/
public function isValidUppMsgType(ExecutionContextInterface $context)
{
$uppMsgType = $this->getUppMsgType();
if (self::MSGTYPE_GET !== $uppMsgType) {
$context->addViolationAt('status', "Invalid uppMsgType '{$uppMsgType}' given!");
}
}
示例2: 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.');
}
}
}
示例3: isNiveauValid
/**
* @Assert\Callback()
* @param ExecutionContextInterface $context
*/
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())));
}
}
示例4: validate
/**
* Validates contact method
*
* @param ContactRequest $object
* @param ExecutionContextInterface $context
*/
public static function validate(ContactRequest $object, ExecutionContextInterface $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.');
}
}
示例5: 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;
}
示例6: validatePassword
/**
* Si es un user nuevo el password debe ser obligatorio.
*
* @param ExecutionContextInterface $ec Contexto de Ejecuci..n.
*
* @return void
*/
public function validatePassword(ExecutionContextInterface $ec)
{
$plainPassword = $this->getPlainPassword();
if (!$this->id && empty($plainPassword)) {
$ec->addViolationAt('plainPassword', 'La contraseña no debe estar vacía.');
}
}
示例7: validateEntity
/**
* @param ExecutionContextInterface $context
*/
public function validateEntity(ExecutionContextInterface $context)
{
if ($this->getType() == self::TYPE_PAGE_LINK && !$this->getNodeTranslation()) {
$context->addViolationAt('nodeTranslation', 'Please select a page');
} elseif ($this->getType() == self::TYPE_URL_LINK) {
if (strlen($this->getTitle()) == 0) {
$context->addViolationAt('title', 'Please set the link title');
}
if (strlen($this->getUrl()) == 0) {
$context->addViolationAt('url', 'Please set the link URL');
}
}
}
示例8: isValidReqType
/**
* @param ExecutionContextInterface $context
*/
public function isValidReqType(ExecutionContextInterface $context)
{
$reqType = $this->getReqType();
if (!in_array($reqType, array_keys(\Dominikzogg\ClassHelpers\getConstantsWithPrefix(__CLASS__, 'REQTYPE_')))) {
$context->addViolationAt('status', "Unknown reqType '{$reqType}' given!");
}
}
示例9: isDataFieldValid
/**
* @Assert\Callback
*/
public function isDataFieldValid(ExecutionContextInterface $context)
{
//TODO: why is it not working?
$context->addViolationAt('textValue', 'Haaaaha', array(), null);
}
示例10: forbiddenWords
/**
* @Assert\Callback
*/
public function forbiddenWords(ExecutionContextInterface $context)
{
$forbiddenWords = array('branches', 'details', 'activity', 'default');
if (in_array($this->branchId, $forbiddenWords)) {
$context->addViolationAt('branchId', 'Branch ID is a forbidden word ("' . $this->branchId . '") !', array(), null);
}
}
示例11: forbiddenWords
/**
* @Assert\Callback
* Need to change this to avoid team name duplicates
*/
public function forbiddenWords(ExecutionContextInterface $context)
{
$forbiddenWords = array('test');
if (in_array($this->usernameCanonical, $forbiddenWords)) {
$context->addViolationAt('usernameCanonical', 'Username is a forbidden word ("' . $this->usernameCanonical . '") !', array(), null);
}
}
示例12: isValidStatus
/**
* @param ExecutionContextInterface $context
*/
public function isValidStatus(ExecutionContextInterface $context)
{
$status = $this->getStatus();
if (!in_array($status, array_keys(\Dominikzogg\ClassHelpers\getConstantsWithPrefix(__CLASS__, 'RESPONSESTATUS_')))) {
$context->addViolationAt('status', "Unknown status '{$status}' given!");
}
}
示例13: contenuValide
/**
* @Assert\Callback
*/
public function contenuValide(ExecutionContextInterface $context)
{
$mots_interdits = array('échec', 'abandon');
// On vérifie que le contenu ne contient pas l'un des mots
if (preg_match('#' . implode('|', $mots_interdits) . '#', $this->getContenu())) {
// 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('contenu', 'Contenu invalide car il contient un mot interdit.', array(), null);
}
}
示例14: isValidExpy
/**
* @param ExecutionContextInterface $context
*/
public function isValidExpy(ExecutionContextInterface $context)
{
$expy = $this->getExpy();
$now = new \DateTime();
$years = array();
for ($i = 0; $i < 10; $i++) {
$years[] = $now->format('y');
$now->modify('+1year');
}
if (!in_array($expy, $years, true)) {
$context->addViolationAt('expy', "Invalid expy '{$expy}' given!");
}
}
示例15: validate
/**
* @Assert\Callback(groups={"suscribe"})
* use Symfony\Component\Validator\Context\ExecutionContextInterface;
*/
public function validate(ExecutionContextInterface $context)
{
$val = $this->getUsername();
if (!empty($val)) {
if ($this->getUsername() == $this->getPassword()) {
$context->addViolationAt('username', 'Votre login ne doit pas être identique à votre mot de passe', array(), null);
}
}
$val = $this->getEmail();
if (!empty($val)) {
if ($this->getUsername() == $this->getEmail()) {
$context->addViolationAt('email', 'Votre email ne doit pas être identique à votre login', array(), null);
}
}
}