From 00104524f6022a94fc9164b4af51fc9c39942ec0 Mon Sep 17 00:00:00 2001 From: Diego Saint Esteben Date: Tue, 9 Jun 2015 20:00:53 -0300 Subject: [PATCH] Fix DoctrineType --- .../Doctrine/Form/Type/DoctrineType.php | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php b/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php index 3771739a8b2e9..95251dc596159 100644 --- a/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php +++ b/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php @@ -126,12 +126,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) public function configureOptions(OptionsResolver $resolver) { - $registry = $this->registry; - $choiceListFactory = $this->choiceListFactory; - $idReaders = &$this->idReaders; - $choiceLoaders = &$this->choiceLoaders; - - $choiceLoader = function (Options $options) use ($choiceListFactory, &$choiceLoaders, $type) { + $choiceLoader = function (Options $options) { // Unless the choices are given explicitly, load them on demand if (null === $options['choices']) { @@ -141,7 +136,7 @@ public function configureOptions(OptionsResolver $resolver) // If there is no QueryBuilder we can safely cache DoctrineChoiceLoader, // also if concrete Type can return important QueryBuilder parts to generate // hash key we go for it as well - if (!$options['query_builder'] || false !== ($qbParts = $type->getQueryBuilderPartsForCachingHash($options['query_builder']))) { + if (!$options['query_builder'] || false !== ($qbParts = $this->getQueryBuilderPartsForCachingHash($options['query_builder']))) { $hash = CachingFactoryDecorator::generateHash(array( $options['em'], @@ -150,8 +145,8 @@ public function configureOptions(OptionsResolver $resolver) $options['loader'], )); - if (isset($choiceLoaders[$hash])) { - return $choiceLoaders[$hash]; + if (isset($this->choiceLoaders[$hash])) { + return $this->choiceLoaders[$hash]; } } @@ -165,7 +160,7 @@ public function configureOptions(OptionsResolver $resolver) } $doctrineChoiceLoader = new DoctrineChoiceLoader( - $choiceListFactory, + $this->choiceListFactory, $options['em'], $options['class'], $options['id_reader'], @@ -173,7 +168,7 @@ public function configureOptions(OptionsResolver $resolver) ); if ($hash !== null) { - $choiceLoaders[$hash] = $doctrineChoiceLoader; + $this->choiceLoaders[$hash] = $doctrineChoiceLoader; } return $doctrineChoiceLoader; @@ -220,17 +215,17 @@ public function configureOptions(OptionsResolver $resolver) // Otherwise, an incrementing integer is used as value automatically }; - $emNormalizer = function (Options $options, $em) use ($registry) { + $emNormalizer = function (Options $options, $em) { /* @var ManagerRegistry $registry */ if (null !== $em) { if ($em instanceof ObjectManager) { return $em; } - return $registry->getManager($em); + return $this->registry->getManager($em); } - $em = $registry->getManagerForClass($options['class']); + $em = $this->registry->getManagerForClass($options['class']); if (null === $em) { throw new RuntimeException(sprintf( @@ -273,7 +268,7 @@ public function configureOptions(OptionsResolver $resolver) // Set the "id_reader" option via the normalizer. This option is not // supposed to be set by the user. - $idReaderNormalizer = function (Options $options) use (&$idReaders) { + $idReaderNormalizer = function (Options $options) { $hash = CachingFactoryDecorator::generateHash(array( $options['em'], $options['class'], @@ -285,12 +280,12 @@ public function configureOptions(OptionsResolver $resolver) // of the field, so we store that information in the reader. // The reader is cached so that two choice lists for the same class // (and hence with the same reader) can successfully be cached. - if (!isset($idReaders[$hash])) { + if (!isset($this->idReaders[$hash])) { $classMetadata = $options['em']->getClassMetadata($options['class']); - $idReaders[$hash] = new IdReader($options['em'], $classMetadata); + $this->idReaders[$hash] = new IdReader($options['em'], $classMetadata); } - return $idReaders[$hash]; + return $this->idReaders[$hash]; }; $resolver->setDefaults(array(