Skip to content

Commit 78a08f3

Browse files
Merge branch '2.8' into 3.0
* 2.8: Fix merge [Process] Fix running tests on HHVM>=3.8 [Form] Improved performance of ChoiceType and its subtypes Removed an object as route generator argument Conflicts: src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml
2 parents 52c4304 + 3676c3b commit 78a08f3

File tree

8 files changed

+107
-9
lines changed

8 files changed

+107
-9
lines changed

.travis.yml

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

3131
before_install:
3232
- if [[ ! $deps && ! $TRAVIS_PHP_VERSION = ${MIN_PHP%.*} && $TRAVIS_PHP_VERSION != hhvm && $TRAVIS_PULL_REQUEST != false ]]; then deps=skip; fi;
33-
- 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;
33+
- 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;
3434
- 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;
3535
- echo memory_limit = -1 >> $INI_FILE
3636
- 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;
@@ -78,8 +79,20 @@ public function getBlockPrefix()
7879
public function getQueryBuilderPartsForCachingHash($queryBuilder)
7980
{
8081
return array(
81-
$queryBuilder->getQuery()->getSQL(),
82-
$queryBuilder->getParameters()->toArray(),
82+
$queryBuilder->getQuery()->getSQL(),
83+
array_map(array($this, 'parameterToArray'), $queryBuilder->getParameters()->toArray()),
8384
);
8485
}
86+
87+
/**
88+
* Converts a query parameter to an array.
89+
*
90+
* @param Parameter $parameter The query parameter
91+
*
92+
* @return array The array representation of the parameter
93+
*/
94+
private function parameterToArray(Parameter $parameter)
95+
{
96+
return array($parameter->getName(), $parameter->getType(), $parameter->getValue());
97+
}
8598
}

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

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

1130+
public function testLoaderCachingWithParameters()
1131+
{
1132+
$entity1 = new SingleIntIdEntity(1, 'Foo');
1133+
$entity2 = new SingleIntIdEntity(2, 'Bar');
1134+
$entity3 = new SingleIntIdEntity(3, 'Baz');
1135+
1136+
$this->persist(array($entity1, $entity2, $entity3));
1137+
1138+
$repo = $this->em->getRepository(self::SINGLE_IDENT_CLASS);
1139+
1140+
$entityType = new EntityType(
1141+
$this->emRegistry,
1142+
PropertyAccess::createPropertyAccessor()
1143+
);
1144+
1145+
$entityTypeGuesser = new DoctrineOrmTypeGuesser($this->emRegistry);
1146+
1147+
$factory = Forms::createFormFactoryBuilder()
1148+
->addType($entityType)
1149+
->addTypeGuesser($entityTypeGuesser)
1150+
->getFormFactory();
1151+
1152+
$formBuilder = $factory->createNamedBuilder('form', 'Symfony\Component\Form\Extension\Core\Type\FormType');
1153+
1154+
$formBuilder->add('property1', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', array(
1155+
'em' => 'default',
1156+
'class' => self::SINGLE_IDENT_CLASS,
1157+
'query_builder' => $repo->createQueryBuilder('e')->where('e.id = :id')->setParameter('id', 1),
1158+
));
1159+
1160+
$formBuilder->add('property2', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', array(
1161+
'em' => 'default',
1162+
'class' => self::SINGLE_IDENT_CLASS,
1163+
'query_builder' => function (EntityRepository $repo) {
1164+
return $repo->createQueryBuilder('e')->where('e.id = :id')->setParameter('id', 1);
1165+
},
1166+
));
1167+
1168+
$formBuilder->add('property3', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', array(
1169+
'em' => 'default',
1170+
'class' => self::SINGLE_IDENT_CLASS,
1171+
'query_builder' => function (EntityRepository $repo) {
1172+
return $repo->createQueryBuilder('e')->where('e.id = :id')->setParameter('id', 1);
1173+
},
1174+
));
1175+
1176+
$form = $formBuilder->getForm();
1177+
1178+
$form->submit(array(
1179+
'property1' => 1,
1180+
'property2' => 1,
1181+
'property3' => 2,
1182+
));
1183+
1184+
$choiceLoader1 = $form->get('property1')->getConfig()->getOption('choice_loader');
1185+
$choiceLoader2 = $form->get('property2')->getConfig()->getOption('choice_loader');
1186+
$choiceLoader3 = $form->get('property3')->getConfig()->getOption('choice_loader');
1187+
1188+
$this->assertInstanceOf('Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface', $choiceLoader1);
1189+
$this->assertSame($choiceLoader1, $choiceLoader2);
1190+
$this->assertSame($choiceLoader1, $choiceLoader3);
1191+
}
1192+
11301193
protected function createRegistryMock($name, $em)
11311194
{
11321195
$registry = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry');

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

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

51+
<service id="form.choice_list_factory.default" class="Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory" public="false"/>
52+
53+
<service id="form.choice_list_factory.property_access" class="Symfony\Component\Form\ChoiceList\Factory\PropertyAccessDecorator" public="false">
54+
<argument type="service" id="form.choice_list_factory.default"/>
55+
<argument type="service" id="form.property_accessor"/>
56+
</service>
57+
58+
<service id="form.choice_list_factory.cached" class="Symfony\Component\Form\ChoiceList\Factory\CachingFactoryDecorator" public="false">
59+
<argument type="service" id="form.choice_list_factory.property_access"/>
60+
</service>
61+
62+
<service id="form.choice_list_factory" alias="form.choice_list_factory.cached" public="false"/>
63+
5164
<service id="form.type.form" class="Symfony\Component\Form\Extension\Core\Type\FormType">
5265
<argument type="service" id="form.property_accessor" />
5366
<tag name="form.type" />
@@ -60,6 +73,7 @@
6073
</service>
6174
<service id="form.type.choice" class="Symfony\Component\Form\Extension\Core\Type\ChoiceType">
6275
<tag name="form.type" />
76+
<argument type="service" id="form.choice_list_factory"/>
6377
</service>
6478
<service id="form.type.collection" class="Symfony\Component\Form\Extension\Core\Type\CollectionType">
6579
<tag name="form.type" />

src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ public function searchResultsAction(Request $request, $token)
286286
'end' => $end,
287287
'limit' => $limit,
288288
'panel' => null,
289-
'request' => $request,
290289
)), 200, array('Content-Type' => 'text/html'));
291290
}
292291

@@ -332,7 +331,6 @@ public function searchAction(Request $request)
332331
$tokens = $this->profiler->find($ip, $url, $limit, $method, $start, $end);
333332

334333
return new RedirectResponse($this->generator->generate('_profiler_search_results', array(
335-
'request' => $request,
336334
'token' => $tokens ? $tokens[0]['token'] : 'empty',
337335
'ip' => $ip,
338336
'method' => $method,

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\View\ChoiceGroupView;
1718
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
@@ -44,7 +45,11 @@ class ChoiceType extends AbstractType
4445

4546
public function __construct(ChoiceListFactoryInterface $choiceListFactory = null)
4647
{
47-
$this->choiceListFactory = $choiceListFactory ?: new PropertyAccessDecorator(new DefaultChoiceListFactory());
48+
$this->choiceListFactory = $choiceListFactory ?: new CachingFactoryDecorator(
49+
new PropertyAccessDecorator(
50+
new DefaultChoiceListFactory()
51+
)
52+
);
4853
}
4954

5055
/**

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

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

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

9595
$finder = new ExecutableFinder();
9696
$result = $finder->find($this->getPhpBinaryName());
@@ -108,7 +108,7 @@ public function testFindProcessInOpenBasedir()
108108
}
109109

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

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

0 commit comments

Comments
 (0)