class ValidatorFactory implements ValidatorContextInterface
Creates and configures new validator objects
Usually you will use the static method buildDefault() to initialize a
factory with default configuration. To this method you can pass various
parameters that configure where the validator mapping is found. If you
don't pass a parameter, the mapping will be read from annotations.
<code>
// read from annotations only
$factory = ValidatorFactory::buildDefault();
// read from XML and YAML, suppress annotations
$factory = ValidatorFactory::buildDefault(array(
'/path/to/mapping.xml',
'/path/to/other/mapping.yml',
), false);
</code>
You then have to call getValidator() to create new validators.
<code>
$validator = $factory->getValidator();
</code>
When manually constructing a factory, the default configuration of the
validators can be passed to the constructor as a ValidatorContextInterface
object.
<code>
$defaultContext = new ValidatorContext();
$defaultContext->setClassMetadataFactory($metadataFactory);
$defaultContext->setConstraintValidatorFactory($validatorFactory);
$factory = new ValidatorFactory($defaultContext);
$form = $factory->getValidator();
</code>
You can also override the default configuration by calling any of the
methods in this class. These methods return a ValidatorContextInterface object
on which you can override further settings or call getValidator() to create
a form.
<code>
$form = $factory
->setClassMetadataFactory($customFactory);
->getValidator();
</code>
ValidatorFactory instances should be cached and reused in your application.
Methods
| static ValidatorFactory |
buildDefault(array $mappingFiles = array(), Boolean $annotations = false, string $staticMethod = null)
Builds a validator factory with the default mapping loaders |
|
|
__construct(ValidatorContextInterface $defaultContext = null)
Sets the given context as default context |
||
| ValidatorContextInterface |
setClassMetadataFactory(ClassMetadataFactoryInterface $metadataFactory)
Sets the class metadata factory used in the new validator |
|
| ValidatorContextInterface |
setConstraintValidatorFactory(ConstraintValidatorFactoryInterface $validatorFactory)
Sets the constraint validator factory used in the new validator |
|
| ValidatorInterface |
getValidator()
Creates a new validator with the settings stored in this context |
Details
at line 110
static public ValidatorFactory
buildDefault(array $mappingFiles = array(), Boolean $annotations = false, string $staticMethod = null)
Builds a validator factory with the default mapping loaders
at line 173
public
__construct(ValidatorContextInterface $defaultContext = null)
Sets the given context as default context
at line 191
public ValidatorContextInterface
setClassMetadataFactory(ClassMetadataFactoryInterface $metadataFactory)
Sets the class metadata factory used in the new validator
at line 211
public ValidatorContextInterface
setConstraintValidatorFactory(ConstraintValidatorFactoryInterface $validatorFactory)
Sets the constraint validator factory used in the new validator
at line 228
public ValidatorInterface
getValidator()
Creates a new validator with the settings stored in this context