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 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