8000 Merge branch '2.1' · symfony/symfony@31ff3db · GitHub
[go: up one dir, main page]

Skip to content

Commit 31ff3db

Browse files
committed
Merge branch '2.1'
* 2.1: (24 commits) updated license year Update src/Symfony/Component/HttpFoundation/Response.php [Form] Fixed inheritance of "error_bubbling" in RepeatedType [Form] Fixed DateType when used with the intl extension disabled. [HttpFoundation] fix return types and handling of zero in Response [HttpFoundation] better fix for non-parseable Expires header date Fixed missing plural message in portuguese validator Fix Expires when the header is -1 [DoctrineBridge] Allowing memcache port to be 0 to support memcache unix domain sockets. [Console] fixed unitialized properties (closes #5935) [Process] Prevented test from failing when pcntl extension is not enabled. Revert "[DoctrineBridge] Improved performance of the EntityType when used with the "query_builder" option" [Form] Fixed failing tests for DateTimeToStringTransformer. [Locale] Fixed the StubLocaleTest for ICU versions lower than 4.8. [Bundle] [FrameworkBundle] fixed typo in phpdoc of the SessionListener. [Form] Fixed test regression introduced in #6440 [Tests] Fix namespaces Fixed php doc of GenericEvent::__construct HttpUtils must handle RequestMatcher too use preferred_choices in favor of preferred_query ... Conflicts: src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php
2 parents 1885642 + 8349816 commit 31ff3db

File tree

25 files changed

+219
-118
lines changed

25 files changed

+219
-118
lines changed

CHANGELOG-2.0.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ in 2.0 minor versions.
77
To get the diff for a specific change, go to https://github.com/symfony/symfony/commit/XXX where XXX is the change hash
88
To get the diff between two versions, go to https://github.com/symfony/symfony/compare/v2.0.0...v2.0.1
99

10+
* 2.0.21 (2012-12-21)
11+
12+
* b8e5689: [FrameworkBundle] fixed ESI calls
13+
1014
* 2.0.20 (2012-12-20)
1115

1216
* 532cc9a: [FrameworkBundle] added support for URIs as an argument to HttpKernel::render()

src/Symfony/Bridge/Doctrine/CHANGELOG.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
CHANGELOG
22
=========
33

4-
2.1.5
5-
-----
6-
7-
* fixed caching of choice lists when EntityType is used with the "query_builder" option
8-
94
2.1.0
105
-----
116

src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ protected function loadObjectManagerCacheDriver(array $objectManager, ContainerB
315315
$memcacheClass = !empty($cacheDriver['class']) ? $cacheDriver['class'] : '%'.$this->getObjectManagerElementName('cache.memcache.class').'%';
316316
$memcacheInstanceClass = !empty($cacheDriver['instance_class']) ? $cacheDriver['instance_class'] : '%'.$this->getObjectManagerElementName('cache.memcache_instance.class').'%';
317317
$memcacheHost = !empty($cacheDriver['host']) ? $cacheDriver['host'] : '%'.$this->getObjectManagerElementName('cache.memcache_host').'%';
318-
$memcachePort = !empty($cacheDriver['port']) ? $cacheDriver['port'] : '%'.$this->getObjectManagerElementName('cache.memcache_port').'%';
318+
$memcachePort = !empty($cacheDriver['port']) || (isset($cacheDriver['port']) && $cacheDriver['port'] === 0) ? $cacheDriver['port'] : '%'.$this->getObjectManagerElementName('cache.memcache_port').'%';
319319
$cacheDef = new Definition($memcacheClass);
320320
$memcacheInstance = new Definition($memcacheInstanceClass);
321321
$memcacheInstance->addMethodCall('connect', array(

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

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,53 +11,26 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Form\Type;
1313

14-
use Symfony\Component\Form\Exception\UnexpectedTypeException;
15-
use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader;
1614
use Doctrine\Common\Persistence\ObjectManager;
17-
use Doctrine\ORM\QueryBuilder;
15+
use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader;
1816

1917
class EntityType extends DoctrineType
2018
{
21-
/**
22-
* @var array
23-
*/
24-
private $loaderCache = array();
25-
2619
/**
2720
* Return the default loader object.
2821
*
29-
* @param ObjectManager $manager
30-
* @param QueryBuilder|\Closure $queryBuilder
31-
* @param string $class
32-
*
22+
* @param ObjectManager $manager
23+
* @param mixed $queryBuilder
24+
* @param string $class
3325
* @return ORMQueryBuilderLoader
34-
*
35-
* @throws UnexpectedTypeException If the passed $queryBuilder is no \Closure
36-
* and no QueryBuilder or if the closure
37-
* does not return a QueryBuilder.
3826
*/
3927
public function getLoader(ObjectManager $manager, $queryBuilder, $class)
4028
{
41-
if ($queryBuilder instanceof \Closure) {
42-
$queryBuilder = $queryBuilder($manager->getRepository($class));
43-
44-
if (!$queryBuilder instanceof QueryBuilder) {
45-
throw new UnexpectedTypeException($queryBuilder, 'Doctrine\ORM\QueryBuilder');
46-
}
47-
} elseif (!$queryBuilder instanceof QueryBuilder) {
48-
throw new UnexpectedTypeException($queryBuilder, 'Doctrine\ORM\QueryBuilder or \Closure');
49-
}
50-
51-
// It is important to return the same loader for identical queries,
52-
// otherwise the caching mechanism in DoctrineType does not work
53-
// (which expects identical loaders for the cache to work)
54-
$hash = md5($queryBuilder->getQuery()->getDQL());
55-
56-
if (!isset($this->loaderCache[$hash])) {
57-
$this->loaderCache[$hash] = new ORMQueryBuilderLoader($queryBuilder);
58-
}
59-
60-
return $this->loaderCache[$hash];
29+
return new ORMQueryBuilderLoader(
30+
$queryBuilder,
31+
$manager,
32+
$class
33+
);
6134
}
6235

6336
public function getName()

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

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

1414
use Symfony\Component\Form\Tests\FormPerformanceTestCase;
15-
use Doctrine\ORM\EntityRepository;
1615
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIdentEntity;
1716
use Doctrine\ORM\Tools\SchemaTool;
1817
use Symfony\Bridge\Doctrine\Tests\DoctrineOrmTestCase;
@@ -37,9 +36,6 @@ protected function getExtensions()
3736
$manager->expects($this->any())
3837
->method('getManager')
3938
->will($this->returnValue($this->em));
40-
$manager->expects($this->any())
41-
->method('getManagerForClass')
42-
->will($this->returnValue($this->em));
4339

4440
return array(
4541
new CoreExtension(),
@@ -114,26 +110,6 @@ public function testCollapsedEntityField()
114110
}
115111
}
116112

117-
/**
118-
* @group benchmark
119-
*/
120-
public function testCollapsedEntityFieldWithQueryBuilder()
121-
{
122-
$this->setMaxRunningTime(1);
123-
124-
for ($i = 0; $i < 40; ++$i) {
125-
$form = $this->factory->create('entity', null, array(
126-
'class' => self::ENTITY_CLASS,
127-
'query_builder' => function (EntityRepository $repo) {
128-
return $repo->createQueryBuilder('e')->addOrderBy('e.id', 'DESC');
129-
}
130-
));
131-
132-
// force loading of the choice list
133-
$form->createView();
134-
}
135-
}
136-
137113
/**
138114
* @group benchmark
139115
*/

src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
namespace Symfony\Bridge\Propel1\Form\ChoiceList;
1313

14+
use \ModelCriteria;
1415
use \BaseObject;
1516
use \Persistent;
17+
1618
use Symfony\Component\Form\Exception\FormException;
1719
use Symfony\Component\Form\Exception\StringCastException;
1820
use Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList;
@@ -21,6 +23,7 @@
2123
* Widely inspired by the EntityChoiceList.
2224
*
2325
* @author William Durand <william.durand1@gmail.com>
26+
* @author Toni Uebernickel <tuebernickel@gmail.com>
2427
*/
2528
class ModelChoiceList extends ObjectChoiceList
2629
{
@@ -31,19 +34,28 @@ class ModelChoiceList extends ObjectChoiceList
3134
*
3235
* @var array
3336
*/
34-
private $identifier = array();
37+
protected $identifier = array();
38+
39+
/**
40+
* The query to retrieve the choices of this list.
41+
*
42+
* @var ModelCriteria
43+
*/
44+
protected $query;
3545

3646
/**
37-
* Query
47+
* The query to retrieve the preferred choices for this list.
48+
*
49+
* @var ModelCriteria
3850
*/
39-
private $query = null;
51+
protected $preferredQuery;
4052

4153
/**
4254
* Whether the model objects have already been loaded.
4355
*
4456
* @var Boolean
4557
*/
46-
private $loaded = false;
58+
protected $loaded = false;
4759

4860
/**
4961
* Whether to use the identifier for index generation
@@ -53,13 +65,20 @@ class ModelChoiceList extends ObjectChoiceList
5365
private $identifierAsIndex = false;
5466

5567
/**
56-
* @param string $class
57-
* @param string $labelPath
58-
* @param array $choices
59-
* @param \ModelCriteria $queryObject
60-
* @param string $groupPath
68+
* Constructor.
69+
*
70+
* @see Symfony\Bridge\Propel1\Form\Type\ModelType How to use the preferred choices.
71+
*
72+
* @param string $class The FQCN of the model class to be loaded.
73+
* @param string $labelPath A property path pointing to the property used for the choice labels.
74+
* @param array $choices An optional array to use, rather than fetching the models.
75+
* @param ModelCriteria $queryObject The query to use retrieving model data from database.
76+
* @param string $groupPath A property path pointing to the property used to group the choices.
77+
* @param array|ModelCriteria $preferred The preferred items of this choice.
78+
* Either an array if $choices is given,
79+
* or a ModelCriteria to be merged with the $queryObject.
6180
*/
62-
public function __construct($class, $labelPath = null, $choices = null, $queryObject = null, $groupPath = null)
81+
public function __construct($class, $labelPath = null, $choices = null, $queryObject = null, $groupPath = null, $preferred = array())
6382
{
6483
$this->class = $class;
6584

@@ -70,10 +89,15 @@ public function __construct($class, $labelPath = null, $choices = null, $queryOb
7089
$this->query = $queryObject ?: $query;
7190
$this->loaded = is_array($choices) || $choices instanceof \Traversable;
7291

92+
if ($preferred instanceof ModelCriteria) {
93+
$this->preferredQuery = $preferred->mergeWith($this->query);
94+
}
95+
7396
if (!$this->loaded) {
7497
// Make sure the constraints of the parent constructor are
7598
// fulfilled
7699
$choices = array();
100+
$preferred = array();
77101
}
78102

79103
if (1 === count($this->identifier) && $this->isInteger(current($this->identifier))) {
@@ -328,10 +352,14 @@ private function load()
328352
{
329353
$models = (array) $this->query->find();
330354

355+
$preferred = array();
356+
if ($this->preferredQuery instanceof ModelCriteria) {
357+
$preferred = (array) $this->preferredQuery->find();
358+
}
359+
331360
try {
332361
// The second parameter $labels is ignored by ObjectChoiceList
333-
// The third parameter $preferredChoices is currently not supported
334-
parent::initialize($models, array(), array());
362+
parent::initialize($models, array(), $preferred);
335363
} catch (StringCastException $e) {
336364
throw new StringCastException(str_replace('argument $labelPath', 'option "property"', $e->getMessage()), null, $e);
337365
}

src/Symfony/Bridge/Propel1/Form/Type/ModelType.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,29 @@
2222
* ModelType class.
2323
*
2424
* @author William Durand <william.durand1@gmail.com>
25+
* @author Toni Uebernickel <tuebernickel@gmail.com>
26+
*
27+
* Example using the preferred_choices option.
28+
*
29+
* <code>
30+
* public function buildForm(FormBuilderInterface $builder, array $options)
31+
* {
32+
* $builder
33+
* ->add('product', 'model', array(
34+
* 'class' => 'Model\Product',
35+
* 'query' => ProductQuery::create()
36+
* ->filterIsActive(true)
37+
* ->useI18nQuery($options['locale'])
38+
* ->orderByName()
39+
* ->endUse()
40+
* ,
41+
* 'preferred_choices' => ProductQuery::create()
42+
* ->filterByIsTopProduct(true)
43+
* ,
44+
* ))
45+
* ;
46+
* }
47+
* </code>
2548
*/
2649
class ModelType extends AbstractType
2750
{
@@ -40,7 +63,8 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
4063
$options['property'],
4164
$options['choices'],
4265
$options['query'],
43-
$options['group_by']
66+
$options['group_by'],
67+
$options['preferred_choices']
4468
);
4569
};
4670

src/Symfony/Bridge/Propel1/Tests/Form/ChoiceList/ModelChoiceListTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,29 @@ public function testFlattenedChoices()
7070
$this->assertSame(array(1 => $item1, 2 => $item2), $choiceList->getChoices());
7171
}
7272

73+
public function testFlattenedPreferredChoices()
74+
{
75+
$item1 = new Item(1, 'Foo');
76+
$item2 = new Item(2, 'Bar');
77+
78+
$choiceList = new ModelChoiceList(
79+
self::ITEM_CLASS,
80+
'value',
81+
array(
82+
$item1,
83+
$item2,
84+
),
85+
null,
86+
null,
87+
array(
88+
$item1
89+
)
90+
);
91+
92+
$this->assertSame(array(1 => $item1, 2 => $item2), $choiceList->getChoices());
93+
$this->assertEquals(array(1 => new ChoiceView($item1, '1', 'Foo')), $choiceList->getPreferredViews());
94+
}
95+
7396
public function testNestedChoices()
7497
{
7598
$item1 = new Item(1, 'Foo');

src/Symfony/Bundle/FrameworkBundle/EventListener/SessionListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
2020

2121
/**
22-
* Sets the session on the request.
22+
* Sets the session in the request.
2323
*
2424
* This will also start the session if it was already started during a previous
2525
* request.

src/Symfony/Component/Console/Input/Input.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ abstract class Input implements InputInterface
3737
public function __construct(InputDefinition $definition = null)
3838
{
3939
if (null === $definition) {
40+
$this->arguments = array();
41+
$this->options = array();
4042
$this->definition = new InputDefinition();
4143
} else {
4244
$this->bind($definition);

src/Symfony/Component/EventDispatcher/GenericEvent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class GenericEvent extends Event implements \ArrayAccess, \IteratorAggregate
3535
protected $arguments;
3636

3737
/**
38-
* Encapsulate an event with $subject, $args, and $data.
38+
* Encapsulate an event with $subject and $args.
3939
*
4040
* @param mixed $subject The subject of the event, usually an object.
4141
* @param array $arguments Arguments to store in the event.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
8383
// Only pass a subset of the options to children
8484
$yearOptions['choices'] = $this->formatTimestamps($formatter, '/y+/', $this->listYears($options['years']));
8585
$yearOptions['empty_value'] = $options['empty_value']['year'];
86-
$monthOptions['choices'] = $this->formatTimestamps($formatter, '/M+/', $this->listMonths($options['months']));
86+
$monthOptions['choices'] = $this->formatTimestamps($formatter, '/[M|L]+/', $this->listMonths($options['months']));
8787
$monthOptions['empty_value'] = $options['empty_value']['month'];
8888
$dayOptions['choices'] = $this->formatTimestamps($formatter, '/d+/', $this->listDays($options['days']));
8989
$dayOptions['empty_value'] = $options['empty_value']['day'];

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public function buildForm(FormBuilderInterface $builder, array $options)
2727
$options['first_options']['required'] = $options['required'];
2828
$options['second_options']['required'] = $options['required'];
2929

30+
if (!isset($options['options']['error_bubbling'])) {
31+
$options['options']['error_bubbling'] = $options['error_bubbling'];
32+
}
33+
3034
$builder
3135
->addViewTransformer(new ValueToDuplicatesTransformer(array(
3236
$options['first_name'],

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToStringTransformerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function dataProvider()
2323
array('Y-m-d H:i', '2010-02-03 16:05', '2010-02-03 16:05:00 UTC'),
2424
array('Y-m-d H', '2010-02-03 16', '2010-02-03 16:00:00 UTC'),
2525
array('Y-m-d', '2010-02-03', '2010-02-03 00:00:00 UTC'),
26-
array('Y-m', '2010-02', '2010-02-01 00:00:00 UTC'),
26+
array('Y-m', '2010-12', '2010-12-01 00:00:00 UTC'),
2727
array('Y', '2010', '2010-01-01 00:00:00 UTC'),
2828
array('d-m-Y', '03-02-2010', '2010-02-03 00:00:00 UTC'),
2929
array('H:i:s', '16:05:06', '1970-01-01 16:05:06 UTC'),
@@ -111,11 +111,11 @@ public function testTransformExpectsDateTime()
111111
*/
112112
public function testReverseTransformUsingPipe($format, $input, $output)
113113
{
114-
if (version_compare(phpversion(), '5.3.7', '>=')) {
114+
if (version_compare(phpversion(), '5.3.7', '<')) {
115115
$this->markTestSkipped('Pipe usage requires PHP 5.3.7 or newer.');
116116
}
117117

118-
$reverseTransformer = new DateTimeToStringTransformer('UTC', 'UTC', $format, false);
118+
$reverseTransformer = new DateTimeToStringTransformer('UTC', 'UTC', $format, true);
119119

120120
$output = new \DateTime($output);
121121

0 commit comments

Comments
 (0)
0