By default, this is the fully qualified name of the constraint class
suffixed with "Validator". You can override this method to change that
behaviour.
public validatedBy ( ) : string | ||
리턴 | string |
/** * Returns the validator for the supplied constraint. * * @param Constraint $constraint A constraint * * @return ConstraintValidatorInterface A validator for the supplied constraint * * @throws UnexpectedTypeException When the validator is not an instance of ConstraintValidatorInterface */ public function getInstance(Constraint $constraint) { $name = $constraint->validatedBy(); if (!isset($this->validators[$name])) { switch (get_class($constraint)) { case self::BASE_NAMESPACE . '\\All': $name = self::BASE_NAMESPACE . '\\LegacyAllValidator'; break; case self::BASE_NAMESPACE . '\\Choice': $name = self::BASE_NAMESPACE . '\\LegacyChoiceValidator'; break; case self::BASE_NAMESPACE . '\\Collection': $name = self::BASE_NAMESPACE . '\\LegacyCollectionValidator'; break; case self::BASE_NAMESPACE . '\\Count': $name = self::BASE_NAMESPACE . '\\LegacyCountValidator'; break; case self::BASE_NAMESPACE . '\\Length': $name = self::BASE_NAMESPACE . '\\LegacyLengthValidator'; break; case self::FORM_BASE_NAMESPACE . '\\Form': $name = self::FORM_BASE_NAMESPACE . '\\LegacyFormValidator'; break; } $this->validators[$name] = new $name(); } elseif (is_string($this->validators[$name])) { $this->validators[$name] = $this->container->get($this->validators[$name]); } if (!$this->validators[$name] instanceof ConstraintValidatorInterface) { throw new UnexpectedTypeException($this->validators[$name], 'Symfony\\Component\\Validator\\ConstraintValidatorInterface'); } return $this->validators[$name]; }
/** * {@inheritDoc} */ public function getInstance(Constraint $constraint) { $className = $constraint->validatedBy(); if (!isset($this->validators[$className]) || $className === 'Symfony\\Component\\Validator\\Constraints\\CollectionValidator') { $this->validators[$className] = new $className(); } return $this->validators[$className]; }
/** * {@inheritdoc} */ public function getInstance(Constraint $constraint) { $name = $constraint->validatedBy(); if (isset($this->serviceNames[$name])) { return $this->container[$this->serviceNames[$name]]; } return parent::getInstance($constraint); }
/** * @param Constraint $constraint * @return \Symfony\Component\Validator\ConstraintValidatorInterface */ public function getInstance(Constraint $constraint) { $class_name = $constraint->validatedBy(); if (!isset($this->validators[$class_name])) { $this->validators[$class_name] = new $class_name(); } return $this->validators[$class_name]; }
/** * {@inheritdoc} */ public function getInstance(Constraint $constraint) { $className = $constraint->validatedBy(); if (!isset($this->validators[$className])) { $this->validators[$className] = 'validator.expression' === $className ? new ExpressionValidator($this->propertyAccessor) : new $className(); } return $this->validators[$className]; }
/** * {@inheritdoc} */ public function getInstance(Constraint $constraint) { $class_name = $constraint->validatedBy(); if (!isset($this->validators[$class_name])) { $this->validators[$class_name] = $this->classResolver->getInstanceFromDefinition($class_name); } return $this->validators[$class_name]; }
/** * Returns the validator for the supplied constraint. * * @param Constraint $constraint A constraint * @return ConstraintValidator A validator for the supplied constraint */ public function getInstance(Constraint $constraint) { $name = $constraint->validatedBy(); if (isset($this->validators[$name])) { return $this->validators[$name]; } $this->validators[$name] = $this->createValidator($name); return $this->validators[$name]; }
/** * Returns the validator for the supplied constraint. * * @param Constraint $constraint A constraint * * @return Symfony\Component\Validator\ConstraintValidator A validator for the supplied constraint */ public function getInstance(Constraint $constraint) { $className = $constraint->validatedBy(); if (!isset($this->validators[$className])) { $this->validators[$className] = new $className(); } elseif (is_string($this->validators[$className])) { $this->validators[$className] = $this->container[$this->validators[$className]]; } return $this->validators[$className]; }
/** * {@inheritDoc} */ public function getInstance(Constraint $constraint) { $name = $constraint->validatedBy(); if (!isset($this->validators[$name])) { $this->validators[$name] = new $name(); } elseif (is_string($this->validators[$name])) { $this->validators[$name] = $this->serviceLocator->getService($this->validators[$name]); } return $this->validators[$name]; }
public function getInstance(Constraint $constraint) { $className = $constraint->validatedBy(); if (!isset($this->validators[$className])) { if (class_exists($className)) { $this->validators[$className] = new $className(); } else { $this->validators[$className] = $this->app[$className]; } } return $this->validators[$className]; }
/** * Returns the validator for the supplied constraint. * * @param Constraint $constraint A constraint * * @return ConstraintValidatorInterface A validator for the supplied constraint * * @throws UnexpectedTypeException When the validator is not an instance of ConstraintValidatorInterface */ public function getInstance(Constraint $constraint) { $name = $constraint->validatedBy(); if (!isset($this->validators[$name])) { $this->validators[$name] = new $name(); } elseif (is_string($this->validators[$name])) { $this->validators[$name] = $this->container->get($this->validators[$name]); } if (!$this->validators[$name] instanceof ConstraintValidatorInterface) { throw new UnexpectedTypeException($this->validators[$name], 'Symfony\\Component\\Validator\\ConstraintValidatorInterface'); } return $this->validators[$name]; }
/** * Returns a contraint validator from the container service, setting it if it * doesn't exist yet * * Throws an exception if validator service is not instance of * ConstraintValidatorInterface. * * @param Constraint $constraint * @return ConstraintValidatorInterface * @throws \LogicException */ public function getInstance(Constraint $constraint) { $className = $constraint->validatedBy(); $id = $this->getServiceIdFromClass($className); if (!$this->container->has($id)) { $this->container->set($id, new $className()); } $validator = $this->container->get($id); if (!$validator instanceof ConstraintValidatorInterface) { throw new \LogicException('Service "' . $id . '" is not instance of ConstraintValidatorInterface'); } return $validator; }
/** * Returns the validator for the supplied constraint. * * @param Constraint $constraint A constraint * * @return ConstraintValidatorInterface A validator for the supplied constraint * * @throws ValidatorException When the validator class does not exist * @throws UnexpectedTypeException When the validator is not an instance of ConstraintValidatorInterface */ public function getInstance(Constraint $constraint) { $name = $constraint->validatedBy(); if (!isset($this->validators[$name])) { if (!class_exists($name)) { throw new ValidatorException(sprintf('Constraint validator "%s" does not exist or it is not enabled. Check the "validatedBy" method in your constraint class "%s".', $name, get_class($constraint))); } $this->validators[$name] = new $name(); } elseif (is_string($this->validators[$name])) { $this->validators[$name] = $this->container->get($this->validators[$name]); } if (!$this->validators[$name] instanceof ConstraintValidatorInterface) { throw new UnexpectedTypeException($this->validators[$name], 'Symfony\\Component\\Validator\\ConstraintValidatorInterface'); } return $this->validators[$name]; }
/** * {@inheritDoc} */ public function getInstance(Constraint $constraint) { $className = $constraint->validatedBy(); // The second condition is a hack that is needed when CollectionValidator // calls itself recursively (Collection constraints can be nested). // Since the context of the validator is overwritten when initialize() // is called for the nested constraint, the outer validator is // acting on the wrong context when the nested validation terminates. // // A better solution - which should be approached in Symfony 3.0 - is to // remove the initialize() method and pass the context as last argument // to validate() instead. if (!isset($this->validators[$className]) || 'Symfony\\Component\\Validator\\Constraints\\CollectionValidator' === $className) { $this->validators[$className] = 'validator.expression' === $className ? new ExpressionValidator($this->propertyAccessor) : new $className(); } return $this->validators[$className]; }
/** * {@inheritdoc} */ public function validatedBy() { return parent::validatedBy(); }
/** * {@inheritDoc} */ public function getInstance(Constraint $constraint) { $className = $constraint->validatedBy(); if ($className == 'lunetics_locale.validator.locale') { $this->validators[$className] = $this->localeValidator; } if ($className == 'lunetics_locale.validator.locale_allowed') { $this->validators[$className] = $this->localeAllowedValidator; } return $this->validators[$className]; }