public function ValidatorBuilder::getValidator in Plug 7
Builds and returns a new validator object.
Return value
ValidatorInterface The built validator.
Overrides ValidatorBuilderInterface::getValidator
File
- lib/
Symfony/ validator/ Symfony/ Component/ Validator/ ValidatorBuilder.php, line 346
Class
- ValidatorBuilder
- The default implementation of {@link ValidatorBuilderInterface}.
Namespace
Symfony\Component\ValidatorCode
public function getValidator() {
$metadataFactory = $this->metadataFactory;
$apiVersion = $this->apiVersion;
if (null === $apiVersion) {
$apiVersion = PHP_VERSION_ID < 50309 ? Validation::API_VERSION_2_4 : Validation::API_VERSION_2_5_BC;
}
if (!$metadataFactory) {
$loaders = array();
if (count($this->xmlMappings) > 1) {
$loaders[] = new XmlFilesLoader($this->xmlMappings);
}
elseif (1 === count($this->xmlMappings)) {
$loaders[] = new XmlFileLoader($this->xmlMappings[0]);
}
if (count($this->yamlMappings) > 1) {
$loaders[] = new YamlFilesLoader($this->yamlMappings);
}
elseif (1 === count($this->yamlMappings)) {
$loaders[] = new YamlFileLoader($this->yamlMappings[0]);
}
foreach ($this->methodMappings as $methodName) {
$loaders[] = new StaticMethodLoader($methodName);
}
if ($this->annotationReader) {
$loaders[] = new AnnotationLoader($this->annotationReader);
}
$loader = null;
if (count($loaders) > 1) {
$loader = new LoaderChain($loaders);
}
elseif (1 === count($loaders)) {
$loader = $loaders[0];
}
if (Validation::API_VERSION_2_5 === $apiVersion) {
$metadataFactory = new LazyLoadingMetadataFactory($loader, $this->metadataCache);
}
else {
$metadataFactory = new ClassMetadataFactory($loader, $this->metadataCache);
}
}
$validatorFactory = $this->validatorFactory ?: new ConstraintValidatorFactory($this->propertyAccessor);
$translator = $this->translator ?: new DefaultTranslator();
if (Validation::API_VERSION_2_4 === $apiVersion) {
return new ValidatorV24($metadataFactory, $validatorFactory, $translator, $this->translationDomain, $this->initializers);
}
if (Validation::API_VERSION_2_5 === $apiVersion) {
$contextFactory = new ExecutionContextFactory($translator, $this->translationDomain);
return new RecursiveValidator($contextFactory, $metadataFactory, $validatorFactory, $this->initializers);
}
$contextFactory = new LegacyExecutionContextFactory($metadataFactory, $translator, $this->translationDomain);
return new LegacyValidator($contextFactory, $metadataFactory, $validatorFactory, $this->initializers);
}