From 43fd7bba44775ac1da380220afe602141c80824b Mon Sep 17 00:00:00 2001 From: Iltar van der Berg Date: Wed, 30 Dec 2015 10:27:04 +0100 Subject: [PATCH 1/4] Removed an object as route generator argument --- .../Bundle/WebProfilerBundle/Controller/ProfilerController.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php index 51a52099b7..6d37caf4f1 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php @@ -307,7 +307,6 @@ class ProfilerController 'end' => $end, 'limit' => $limit, 'panel' => null, - 'request' => $request, )), 200, array('Content-Type' => 'text/html')); } @@ -353,7 +352,6 @@ class ProfilerController $tokens = $this->profiler->find($ip, $url, $limit, $method, $start, $end); return new RedirectResponse($this->generator->generate('_profiler_search_results', array( - 'request' => $request, 'token' => $tokens ? $tokens[0]['token'] : 'empty', 'ip' => $ip, 'method' => $method, From a0ef1018d697523f57056138d128602816bfe943 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Sun, 29 Nov 2015 20:59:45 +0100 Subject: [PATCH 2/4] [Form] Improved performance of ChoiceType and its subtypes --- .../Doctrine/Form/Type/DoctrineType.php | 13 ++-- .../Bridge/Doctrine/Form/Type/EntityType.php | 23 +++++-- .../Tests/Form/Type/EntityTypeTest.php | 63 +++++++++++++++++++ .../FrameworkBundle/Resources/config/form.xml | 14 +++++ .../Form/Extension/Core/Type/ChoiceType.php | 7 ++- 5 files changed, 110 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php b/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php index ed8e7a5c3c..99f3019726 100644 --- a/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php +++ b/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php @@ -94,12 +94,12 @@ abstract class DoctrineType extends AbstractType * Gets important parts from QueryBuilder that will allow to cache its results. * For instance in ORM two query builders with an equal SQL string and * equal parameters are considered to be equal. - * + * * @param object $queryBuilder - * + * * @return array|false Array with important QueryBuilder parts or false if * they can't be determined - * + * * @internal This method is public to be usable as callback. It should not * be used in user code. */ @@ -111,7 +111,12 @@ abstract class DoctrineType extends AbstractType public function __construct(ManagerRegistry $registry, PropertyAccessorInterface $propertyAccessor = null, ChoiceListFactoryInterface $choiceListFactory = null) { $this->registry = $registry; - $this->choiceListFactory = $choiceListFactory ?: new PropertyAccessDecorator(new DefaultChoiceListFactory(), $propertyAccessor); + $this->choiceListFactory = $choiceListFactory ?: new CachingFactoryDecorator( + new PropertyAccessDecorator( + new DefaultChoiceListFactory(), + $propertyAccessor + ) + ); } public function buildForm(FormBuilderInterface $builder, array $options) diff --git a/src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php b/src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php index 486eca94ab..fef097d3ea 100644 --- a/src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php +++ b/src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php @@ -12,6 +12,7 @@ namespace Symfony\Bridge\Doctrine\Form\Type; use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\ORM\Query\Parameter; use Doctrine\ORM\QueryBuilder; use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader; use Symfony\Component\Form\Exception\UnexpectedTypeException; @@ -64,19 +65,31 @@ class EntityType extends DoctrineType /** * We consider two query builders with an equal SQL string and * equal parameters to be equal. - * + * * @param QueryBuilder $queryBuilder - * + * * @return array - * + * * @internal This method is public to be usable as callback. It should not * be used in user code. */ public function getQueryBuilderPartsForCachingHash($queryBuilder) { return array( - $queryBuilder->getQuery()->getSQL(), - $queryBuilder->getParameters()->toArray(), + $queryBuilder->getQuery()->getSQL(), + array_map(array($this, 'parameterToArray'), $queryBuilder->getParameters()->toArray()), ); } + + /** + * Converts a query parameter to an array. + * + * @param Parameter $parameter The query parameter + * + * @return array The array representation of the parameter + */ + private function parameterToArray(Parameter $parameter) + { + return array($parameter->getName(), $parameter->getType(), $parameter->getValue()); + } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php index ce37d261c0..c5cdc60bbd 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php @@ -1114,6 +1114,69 @@ class EntityTypeTest extends TypeTestCase $this->assertSame($choiceList1, $choiceList3); } + public function testLoaderCachingWithParameters() + { + $entity1 = new SingleIntIdEntity(1, 'Foo'); + $entity2 = new SingleIntIdEntity(2, 'Bar'); + $entity3 = new SingleIntIdEntity(3, 'Baz'); + + $this->persist(array($entity1, $entity2, $entity3)); + + $repo = $this->em->getRepository(self::SINGLE_IDENT_CLASS); + + $entityType = new EntityType( + $this->emRegistry, + PropertyAccess::createPropertyAccessor() + ); + + $entityTypeGuesser = new DoctrineOrmTypeGuesser($this->emRegistry); + + $factory = Forms::createFormFactoryBuilder() + ->addType($entityType) + ->addTypeGuesser($entityTypeGuesser) + ->getFormFactory(); + + $formBuilder = $factory->createNamedBuilder('form', 'form'); + + $formBuilder->add('property1', 'entity', array( + 'em' => 'default', + 'class' => self::SINGLE_IDENT_CLASS, + 'query_builder' => $repo->createQueryBuilder('e')->where('e.id = :id')->setParameter('id', 1), + )); + + $formBuilder->add('property2', 'entity', array( + 'em' => 'default', + 'class' => self::SINGLE_IDENT_CLASS, + 'query_builder' => function (EntityRepository $repo) { + return $repo->createQueryBuilder('e')->where('e.id = :id')->setParameter('id', 1); + }, + )); + + $formBuilder->add('property3', 'entity', array( + 'em' => 'default', + 'class' => self::SINGLE_IDENT_CLASS, + 'query_builder' => function (EntityRepository $repo) { + return $repo->createQueryBuilder('e')->where('e.id = :id')->setParameter('id', 1); + }, + )); + + $form = $formBuilder->getForm(); + + $form->submit(array( + 'property1' => 1, + 'property2' => 1, + 'property3' => 2, + )); + + $choiceList1 = $form->get('property1')->getConfig()->getOption('choice_list'); + $choiceList2 = $form->get('property2')->getConfig()->getOption('choice_list'); + $choiceList3 = $form->get('property3')->getConfig()->getOption('choice_list'); + + $this->assertInstanceOf('Symfony\Component\Form\ChoiceList\ChoiceListInterface', $choiceList1); + $this->assertSame($choiceList1, $choiceList2); + $this->assertSame($choiceList1, $choiceList3); + } + public function testCacheChoiceLists() { $entity1 = new SingleIntIdEntity(1, 'Foo'); diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml index 7d1a588fba..2c86675589 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml @@ -57,6 +57,19 @@ + + + + + + + + + + + + + @@ -69,6 +82,7 @@ + diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index 1465551b90..93492fdf50 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Form\Extension\Core\Type; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\ChoiceList\Factory\CachingFactoryDecorator; use Symfony\Component\Form\ChoiceList\Factory\PropertyAccessDecorator; use Symfony\Component\Form\ChoiceList\LegacyChoiceListAdapter; use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView; @@ -46,7 +47,11 @@ class ChoiceType extends AbstractType public function __construct(ChoiceListFactoryInterface $choiceListFactory = null) { - $this->choiceListFactory = $choiceListFactory ?: new PropertyAccessDecorator(new DefaultChoiceListFactory()); + $this->choiceListFactory = $choiceListFactory ?: new CachingFactoryDecorator( + new PropertyAccessDecorator( + new DefaultChoiceListFactory() + ) + ); } /** From a47208bea956f5216448c8fc6eb3d01955cf0e2a Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 30 Dec 2015 17:55:43 +0100 Subject: [PATCH 3/4] [Process] Fix running tests on HHVM>=3.8 --- .travis.yml | 2 +- src/Symfony/Component/Process/Tests/ExecutableFinderTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 46a2109589..a748fc24a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,7 +32,7 @@ services: mongodb before_install: - if [[ ! $deps && ! $TRAVIS_PHP_VERSION = ${MIN_PHP%.*} && $TRAVIS_PHP_VERSION != hhvm && $TRAVIS_PULL_REQUEST != false ]]; then deps=skip; fi; - - if [[ ! $deps && ! -d php-$MIN_PHP/sapi ]]; then wget http://museum.php.net/php5/php-$MIN_PHP.tar.bz2 -O - | tar -xj; (cd php-$MIN_PHP; ./configure --enable-sigchild --enable-pcntl; make -j2); fi; + - if [[ ! $deps && $TRAVIS_PHP_VERSION = ${MIN_PHP%.*} && ! -d php-$MIN_PHP/sapi ]]; then wget http://museum.php.net/php5/php-$MIN_PHP.tar.bz2 -O - | tar -xj; (cd php-$MIN_PHP; ./configure --enable-sigchild --enable-pcntl; make -j2); fi; - if [[ $TRAVIS_PHP_VERSION != hhvm ]]; then INI_FILE=~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; else INI_FILE=/etc/hhvm/php.ini; fi; - echo memory_limit = -1 >> $INI_FILE - echo session.gc_probability = 0 >> $INI_FILE diff --git a/src/Symfony/Component/Process/Tests/ExecutableFinderTest.php b/src/Symfony/Component/Process/Tests/ExecutableFinderTest.php index 812429e886..0e97ae9b17 100644 --- a/src/Symfony/Component/Process/Tests/ExecutableFinderTest.php +++ b/src/Symfony/Component/Process/Tests/ExecutableFinderTest.php @@ -99,7 +99,7 @@ class ExecutableFinderTest extends \PHPUnit_Framework_TestCase $this->markTestSkipped('Cannot test when open_basedir is set'); } - $this->iniSet('open_basedir', dirname(PHP_BINARY).(!defined('HHVM_VERSION') ? PATH_SEPARATOR.'/' : '')); + $this->iniSet('open_basedir', dirname(PHP_BINARY).(!defined('HHVM_VERSION') || HHVM_VERSION_ID >= 30800 ? PATH_SEPARATOR.'/' : '')); $finder = new ExecutableFinder(); $result = $finder->find($this->getPhpBinaryName()); @@ -120,7 +120,7 @@ class ExecutableFinderTest extends \PHPUnit_Framework_TestCase } $this->setPath(''); - $this->iniSet('open_basedir', PHP_BINARY.(!defined('HHVM_VERSION') ? PATH_SEPARATOR.'/' : '')); + $this->iniSet('open_basedir', PHP_BINARY.(!defined('HHVM_VERSION') || HHVM_VERSION_ID >= 30800 ? PATH_SEPARATOR.'/' : '')); $finder = new ExecutableFinder(); $result = $finder->find($this->getPhpBinaryName(), false); From 3676c3b61c1b5f8e01493fa33a59a8b89dd6c970 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 30 Dec 2015 19:31:26 +0100 Subject: [PATCH 4/4] Fix merge --- .../Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php index 3b9ec29801..f08dc769eb 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php @@ -1162,15 +1162,15 @@ class EntityTypeTest extends TypeTestCase ->addTypeGuesser($entityTypeGuesser) ->getFormFactory(); - $formBuilder = $factory->createNamedBuilder('form', 'form'); + $formBuilder = $factory->createNamedBuilder('form', 'Symfony\Component\Form\Extension\Core\Type\FormType'); - $formBuilder->add('property1', 'entity', array( + $formBuilder->add('property1', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', array( 'em' => 'default', 'class' => self::SINGLE_IDENT_CLASS, 'query_builder' => $repo->createQueryBuilder('e')->where('e.id = :id')->setParameter('id', 1), )); - $formBuilder->add('property2', 'entity', array( + $formBuilder->add('property2', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', array( 'em' => 'default', 'class' => self::SINGLE_IDENT_CLASS, 'query_builder' => function (EntityRepository $repo) { @@ -1178,7 +1178,7 @@ class EntityTypeTest extends TypeTestCase }, )); - $formBuilder->add('property3', 'entity', array( + $formBuilder->add('property3', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', array( 'em' => 'default', 'class' => self::SINGLE_IDENT_CLASS, 'query_builder' => function (EntityRepository $repo) {