[FrameworkBundle] Optimize validator registration
This commit is contained in:
parent
9280c6272a
commit
9c5b9e1fed
@ -40,6 +40,7 @@ class FrameworkExtension extends Extension
|
|||||||
*
|
*
|
||||||
* @param array $configs
|
* @param array $configs
|
||||||
* @param ContainerBuilder $container
|
* @param ContainerBuilder $container
|
||||||
|
* @throws LogicException
|
||||||
*/
|
*/
|
||||||
public function load(array $configs, ContainerBuilder $container)
|
public function load(array $configs, ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
@ -711,9 +712,7 @@ class FrameworkExtension extends Extension
|
|||||||
|
|
||||||
$container->setParameter('validator.translation_domain', $config['translation_domain']);
|
$container->setParameter('validator.translation_domain', $config['translation_domain']);
|
||||||
|
|
||||||
$xmlMappings = $this->getValidatorXmlMappingFiles($container);
|
list($xmlMappings, $yamlMappings) = $this->getValidatorMappingFiles($container);
|
||||||
$yamlMappings = $this->getValidatorYamlMappingFiles($container);
|
|
||||||
|
|
||||||
if (count($xmlMappings) > 0) {
|
if (count($xmlMappings) > 0) {
|
||||||
$validatorBuilder->addMethodCall('addXmlMappings', array($xmlMappings));
|
$validatorBuilder->addMethodCall('addXmlMappings', array($xmlMappings));
|
||||||
}
|
}
|
||||||
@ -766,35 +765,28 @@ class FrameworkExtension extends Extension
|
|||||||
$container->setParameter('validator.api', $api);
|
$container->setParameter('validator.api', $api);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getValidatorXmlMappingFiles(ContainerBuilder $container)
|
private function getValidatorMappingFiles(ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$files = array();
|
$files = array(array(), array());
|
||||||
|
|
||||||
if (interface_exists('Symfony\Component\Form\FormInterface')) {
|
if (interface_exists('Symfony\Component\Form\FormInterface')) {
|
||||||
$reflClass = new \ReflectionClass('Symfony\Component\Form\FormInterface');
|
$reflClass = new \ReflectionClass('Symfony\Component\Form\FormInterface');
|
||||||
$files[] = dirname($reflClass->getFileName()).'/Resources/config/validation.xml';
|
$files[0][] = dirname($reflClass->getFileName()).'/Resources/config/validation.xml';
|
||||||
$container->addResource(new FileResource($files[0]));
|
$container->addResource(new FileResource($files[0][0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($container->getParameter('kernel.bundles') as $bundle) {
|
$bundles = $container->getParameter('kernel.bundles');
|
||||||
|
foreach ($bundles as $bundle) {
|
||||||
$reflection = new \ReflectionClass($bundle);
|
$reflection = new \ReflectionClass($bundle);
|
||||||
if (is_file($file = dirname($reflection->getFilename()).'/Resources/config/validation.xml')) {
|
$dirname = dirname($reflection->getFilename());
|
||||||
$files[] = realpath($file);
|
|
||||||
|
if (is_file($file = $dirname.'/Resources/config/validation.xml')) {
|
||||||
|
$files[0][] = realpath($file);
|
||||||
$container->addResource(new FileResource($file));
|
$container->addResource(new FileResource($file));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return $files;
|
if (is_file($file = $dirname.'/Resources/config/validation.yml')) {
|
||||||
}
|
$files[1][] = realpath($file);
|
||||||
|
|
||||||
private function getValidatorYamlMappingFiles(ContainerBuilder $container)
|
|
||||||
{
|
|
||||||
$files = array();
|
|
||||||
|
|
||||||
foreach ($container->getParameter('kernel.bundles') as $bundle) {
|
|
||||||
$reflection = new \ReflectionClass($bundle);
|
|
||||||
if (is_file($file = dirname($reflection->getFilename()).'/Resources/config/validation.yml')) {
|
|
||||||
$files[] = realpath($file);
|
|
||||||
$container->addResource(new FileResource($file));
|
$container->addResource(new FileResource($file));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user