minor #13111 [FrameworkBundle] Optimize validator registration (dunglas)
This PR was merged into the 2.7 branch.
Discussion
----------
[FrameworkBundle] Optimize validator registration
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| License | MIT
Optimize validator registration (avoid an unneeded loop and access to the Reflection API).
Commits
-------
9c5b9e1
[FrameworkBundle] Optimize validator registration
This commit is contained in:
commit
2a85c7e19b
@ -40,6 +40,7 @@ class FrameworkExtension extends Extension
|
||||
*
|
||||
* @param array $configs
|
||||
* @param ContainerBuilder $container
|
||||
* @throws LogicException
|
||||
*/
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
@ -711,9 +712,7 @@ class FrameworkExtension extends Extension
|
||||
|
||||
$container->setParameter('validator.translation_domain', $config['translation_domain']);
|
||||
|
||||
$xmlMappings = $this->getValidatorXmlMappingFiles($container);
|
||||
$yamlMappings = $this->getValidatorYamlMappingFiles($container);
|
||||
|
||||
list($xmlMappings, $yamlMappings) = $this->getValidatorMappingFiles($container);
|
||||
if (count($xmlMappings) > 0) {
|
||||
$validatorBuilder->addMethodCall('addXmlMappings', array($xmlMappings));
|
||||
}
|
||||
@ -766,35 +765,28 @@ class FrameworkExtension extends Extension
|
||||
$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')) {
|
||||
$reflClass = new \ReflectionClass('Symfony\Component\Form\FormInterface');
|
||||
$files[] = dirname($reflClass->getFileName()).'/Resources/config/validation.xml';
|
||||
$container->addResource(new FileResource($files[0]));
|
||||
$files[0][] = dirname($reflClass->getFileName()).'/Resources/config/validation.xml';
|
||||
$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);
|
||||
if (is_file($file = dirname($reflection->getFilename()).'/Resources/config/validation.xml')) {
|
||||
$files[] = realpath($file);
|
||||
$dirname = dirname($reflection->getFilename());
|
||||
|
||||
if (is_file($file = $dirname.'/Resources/config/validation.xml')) {
|
||||
$files[0][] = realpath($file);
|
||||
$container->addResource(new FileResource($file));
|
||||
}
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
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);
|
||||
if (is_file($file = $dirname.'/Resources/config/validation.yml')) {
|
||||
$files[1][] = realpath($file);
|
||||
$container->addResource(new FileResource($file));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user