Skip to content

Commit d38278f

Browse files
Merge branch '2.7' into 2.8
* 2.7: [Process] Fix running tests on HHVM>=3.8 [Form] Improved performance of ChoiceType and its subtypes
2 parents a22a070 + c457f7b commit d38278f

File tree

7 files changed

+107
-7
lines changed

7 files changed

+107
-7
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ services: mongodb
3232

3333
before_install:
3434
- if [[ ! $deps && ! $TRAVIS_PHP_VERSION = ${MIN_PHP%.*} && $TRAVIS_PHP_VERSION != hhvm && $TRAVIS_PULL_REQUEST != false ]]; then deps=skip; fi;
35-
- 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;
35+
- 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;
3636
- 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;
3737
- echo memory_limit = -1 >> $INI_FILE
3838
- echo session.gc_probability = 0 >> $INI_FILE

src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,12 @@ public function getQueryBuilderPartsForCachingHash($queryBuilder)
111111
public function __construct(ManagerRegistry $registry, PropertyAccessorInterface $propertyAccessor = null, ChoiceListFactoryInterface $choiceListFactory = null)
112112
{
113113
$this->registry = $registry;
114-
$this->choiceListFactory = $choiceListFactory ?: new PropertyAccessDecorator(new DefaultChoiceListFactory(), $propertyAccessor);
114+
$this->choiceListFactory = $choiceListFactory ?: new CachingFactoryDecorator(
115+
new PropertyAccessDecorator(
116+
new DefaultChoiceListFactory(),
117+
$propertyAccessor
118+
)
119+
);
115120
}
116121

117122
public function buildForm(FormBuilderInterface $builder, array $options)

src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bridge\Doctrine\Form\Type;
1313

1414
use Doctrine\Common\Persistence\ObjectManager;
15+
use Doctrine\ORM\Query\Parameter;
1516
use Doctrine\ORM\QueryBuilder;
1617
use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader;
1718
use Symfony\Component\Form\Exception\UnexpectedTypeException;
@@ -86,8 +87,20 @@ public function getBlockPrefix()
8687
public function getQueryBuilderPartsForCachingHash($queryBuilder)
8788
{
8889
return array(
89-
$queryBuilder->getQuery()->getSQL(),
90-
$queryBuilder->getParameters()->toArray(),
90+
$queryBuilder->getQuery()->getSQL(),
91+
array_map(array($this, 'parameterToArray'), $queryBuilder->getParameters()->toArray()),
9192
);
9293
}
94+
95+
/**
96+
* Converts a query parameter to an array.
97+
*
98+
* @param Parameter $parameter The query parameter
99+
*
100+
* @return array The array representation of the parameter
101+
*/
102+
private function parameterToArray(Parameter $parameter)
103+
{
104+
return array($parameter->getName(), $parameter->getType(), $parameter->getValue());
105+
}
93106
}

src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,69 @@ public function testLoaderCaching()
11401140
$this->assertSame($choiceLoader1, $choiceLoader3);
11411141
}
11421142

1143+
public function testLoaderCachingWithParameters()
1144+
{
1145+
$entity1 = new SingleIntIdEntity(1, 'Foo');
1146+
$entity2 = new SingleIntIdEntity(2, 'Bar');
1147+
$entity3 = new SingleIntIdEntity(3, 'Baz');
1148+
1149+
$this->persist(array($entity1, $entity2, $entity3));
1150+
1151+
$repo = $this->em->getRepository(self::SINGLE_IDENT_CLASS);
1152+
1153+
$entityType = new EntityType(
1154+
$this->emRegistry,
1155+
PropertyAccess::createPropertyAccessor()
1156+
);
1157+
1158+
$entityTypeGuesser = new DoctrineOrmTypeGuesser($this->emRegistry);
1159+
1160+
$factory = Forms::createFormFactoryBuilder()
1161+
->addType($entityType)
1162+
->addTypeGuesser($entityTypeGuesser)
1163+
->getFormFactory();
1164+
1165+
$formBuilder = $factory->createNamedBuilder('form', 'form');
1166+
1167+
$formBuilder->add('property1', 'entity', array(
1168+
'em' => 'default',
1169+
'class' => self::SINGLE_IDENT_CLASS,
1170+
'query_builder' => $repo->createQueryBuilder('e')->where('e.id = :id')->setParameter('id', 1),
1171+
));
1172+
1173+
$formBuilder->add('property2', 'entity', array(
1174+
'em' => 'default',
1175+
'class' => self::SINGLE_IDENT_CLASS,
1176+
'query_builder' => function (EntityRepository $repo) {
1177+
return $repo->createQueryBuilder('e')->where('e.id = :id')->setParameter('id', 1);
1178+
},
1179+
));
1180+
1181+
$formBuilder->add('property3', 'entity', array(
1182+
'em' => 'default',
1183+
'class' => self::SINGLE_IDENT_CLASS,
1184+
'query_builder' => function (EntityRepository $repo) {
1185+
return $repo->createQueryBuilder('e')->where('e.id = :id')->setParameter('id', 1);
1186+
},
1187+
));
1188+
1189+
$form = $formBuilder->getForm();
1190+
1191+
$form->submit(array(
1192+
'property1' => 1,
1193+
'property2' => 1,
1194+
'property3' => 2,
1195+
));
1196+
1197+
$choiceList1 = $form->get('property1')->getConfig()->getOption('choice_list');
1198+
$choiceList2 = $form->get('property2')->getConfig()->getOption('choice_list');
1199+
$choiceList3 = $form->get('property3')->getConfig()->getOption('choice_list');
1200+
1201+
$this->assertInstanceOf('Symfony\Component\Form\ChoiceList\ChoiceListInterface', $choiceList1);
1202+
$this->assertSame($choiceList1, $choiceList2);
1203+
$this->assertSame($choiceList1, $choiceList3);
1204+
}
1205+
11431206
public function testCacheChoiceLists()
11441207
{
11451208
$entity1 = new SingleIntIdEntity(1, 'Foo');

src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@
5757
<!-- CoreExtension -->
5858
<service id="form.property_accessor" alias="property_accessor" public="false" />
5959

60+
<service id="form.choice_list_factory.default" class="Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory" public="false"/>
61+
62+
<service id="form.choice_list_factory.property_access" class="Symfony\Component\Form\ChoiceList\Factory\PropertyAccessDecorator" public="false">
63+
<argument type="service" id="form.choice_list_factory.default"/>
64+
<argument type="service" id="form.property_accessor"/>
65+
</service>
66+
67+
<service id="form.choice_list_factory.cached" class="Symfony\Component\Form\ChoiceList\Factory\CachingFactoryDecorator" public="false">
68+
<argument type="service" id="form.choice_list_factory.property_access"/>
69+
</service>
70+
71+
<service id="form.choice_list_factory" alias="form.choice_list_factory.cached" public="false"/>
72+
6073
<service id="form.type.form" class="Symfony\Component\Form\Extension\Core\Type\FormType">
6174
<argument type="service" id="form.property_accessor" />
6275
<tag name="form.type" alias="form" />
@@ -69,6 +82,7 @@
6982
</service>
7083
<service id="form.type.choice" class="Symfony\Component\Form\Extension\Core\Type\ChoiceType">
7184
<tag name="form.type" alias="choice" />
85+
<argument type="service" id="form.choice_list_factory"/>
7286
</service>
7387
<service id="form.type.collection" class="Symfony\Component\Form\Extension\Core\Type\CollectionType">
7488
<tag name="form.type" alias="collection" />

src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Form\Extension\Core\Type;
1313

1414
use Symfony\Component\Form\AbstractType;
15+
use Symfony\Component\Form\ChoiceList\Factory\CachingFactoryDecorator;
1516
use Symfony\Component\Form\ChoiceList\Factory\PropertyAccessDecorator;
1617
use Symfony\Component\Form\ChoiceList\LegacyChoiceListAdapter;
1718
use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView;
@@ -46,7 +47,11 @@ class ChoiceType extends AbstractType
4647

4748
public function __construct(ChoiceListFactoryInterface $choiceListFactory = null)
4849
{
49-
$this->choiceListFactory = $choiceListFactory ?: new PropertyAccessDecorator(new DefaultChoiceListFactory());
50+
$this->choiceListFactory = $choiceListFactory ?: new CachingFactoryDecorator(
51+
new PropertyAccessDecorator(
52+
new DefaultChoiceListFactory()
53+
)
54+
);
5055
}
5156

5257
/**

src/Symfony/Component/Process/Tests/ExecutableFinderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function testFindWithOpenBaseDir()
9999
$this->markTestSkipped('Cannot test when open_basedir is set');
100100
}
101101

102-
$this->iniSet('open_basedir', dirname(PHP_BINARY).(!defined('HHVM_VERSION') ? PATH_SEPARATOR.'/' : ''));
102+
$this->iniSet('open_basedir', dirname(PHP_BINARY).(!defined('HHVM_VERSION') || HHVM_VERSION_ID >= 30800 ? PATH_SEPARATOR.'/' : ''));
103103

104104
$finder = new ExecutableFinder();
105105
$result = $finder->find($this->getPhpBinaryName());
@@ -120,7 +120,7 @@ public function testFindProcessInOpenBasedir()
120120
}
121121

122122
$this->setPath('');
123-
$this->iniSet('open_basedir', PHP_BINARY.(!defined('HHVM_VERSION') ? PATH_SEPARATOR.'/' : ''));
123+
$this->iniSet('open_basedir', PHP_BINARY.(!defined('HHVM_VERSION') || HHVM_VERSION_ID >= 30800 ? PATH_SEPARATOR.'/' : ''));
124124

125125
$finder = new ExecutableFinder();
126126
$result = $finder->find($this->getPhpBinaryName(), false);

0 commit comments

Comments
 (0)