本文整理汇总了PHP中Symfony\Component\Validator\Constraint::validatedBy方法的典型用法代码示例。如果您正苦于以下问题:PHP Constraint::validatedBy方法的具体用法?PHP Constraint::validatedBy怎么用?PHP Constraint::validatedBy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Validator\Constraint
的用法示例。
在下文中一共展示了Constraint::validatedBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getInstance
/**
* 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];
}
示例2: getInstance
/**
* {@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];
}
示例3: getInstance
/**
* {@inheritdoc}
*/
public function getInstance(Constraint $constraint)
{
$name = $constraint->validatedBy();
if (isset($this->serviceNames[$name])) {
return $this->container[$this->serviceNames[$name]];
}
return parent::getInstance($constraint);
}
示例4: getInstance
/**
* @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];
}
示例5: getInstance
/**
* {@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];
}
示例6: getInstance
/**
* {@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];
}
示例7: getInstance
/**
* 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];
}
示例8: getInstance
/**
* 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];
}
示例9: getInstance
/**
* {@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];
}
示例10: getInstance
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];
}
示例11: getInstance
/**
* 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];
}
示例12: getInstance
/**
* 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;
}
示例13: getInstance
/**
* 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];
}
示例14: getInstance
/**
* {@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];
}
示例15: validatedBy
/**
* {@inheritdoc}
*/
public function validatedBy()
{
return parent::validatedBy();
}