8000 Merge branch '2.5' · symfony/symfony@7f38207 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7f38207

Browse files
Merge branch '2.5'
* 2.5: add missing options [Form] Fixed ValidatorExtension to work with the 2.5 Validation API revert #11510, moved to 2.6 [WebProfilerBundle] Fixed double height of canvas
2 parents 8725243 + de871dc commit 7f38207

File tree

6 files changed

+72
-163
lines changed

6 files changed

+72
-163
lines changed

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/time.html.twig

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@
193193
x = request.left * ratio + space, // position
194194
canvas = cache.get(elementId) || cache.set(elementId, document.getElementById(elementId)),
195195
ctx = canvas.getContext("2d"),
196-
backingStoreRatio,
197196
scaleRatio,
198197
devicePixelRatio;
199198
@@ -206,11 +205,8 @@
206205
207206
// For retina displays so text and boxes will be crisp
208207
devicePixelRatio = window.devicePixelRatio == "undefined" ? 1 : window.devicePixelRatio;
209-
backingStoreRatio = ctx.webkitBackingStorePixelRatio == "undefined" ? 1 : ctx.webkitBackingStorePixelRatio;
210208
scaleRatio = devicePixelRatio / 1;
211209
212-
canvasHeight += gapPerEvent * drawableEvents.length;
213-
214210
canvas.width = width * scaleRatio;
215211
canvas.height = canvasHeight * scaleRatio;
216212
@@ -363,7 +359,7 @@
363359
var self = this;
364360
365361
_requests.forEach(function(request) {
366-
self.drawOne(request, maxRequestTime, threshold, width);
362+
self.drawOne(request, _maxRequestTime, threshold, width);
367363
});
368364
};
369365

src/Symfony/Component/Form/Extension/Validator/ValidatorExtension.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Form\Extension\Validator;
1313

14+
use Symfony\Component\Form\Exception\UnexpectedTypeException;
1415
use Symfony\Component\Form\Extension\Validator\Constraints\Form;
1516
use Symfony\Component\Form\AbstractExtension;
1617
use Symfony\Component\Validator\Constraints\Valid;
@@ -29,37 +30,42 @@ class ValidatorExtension extends AbstractExtension
2930

3031
/**
3132
* @param ValidatorInterface|LegacyValidatorInterface $validator
33+
*
34+
* @throws UnexpectedTypeException If $validator is invalid
3235
*/
3336
public function __construct($validator)
3437
{
35-
// since validator apiVersion 2.5
38+
// 2.5 API
3639
if ($validato F438 r instanceof ValidatorInterface) {
37-
$this->validator = $validator;
38-
39-
/** @var $metadata ClassMetadata */
40-
$metadata = $this->validator->getMetadataFor('Symfony\Component\Form\Form');
41-
// until validator apiVersion 2.4
40+
$metadata = $validator->getMetadataFor('Symfony\Component\Form\Form');
41+
// 2.4 API
4242
} elseif ($validator instanceof LegacyValidatorInterface) {
43-
$this->validator = $validator;
44-
45-
/** @var $metadata ClassMetadata */
46-
$metadata = $this->validator->getMetadataFactory()->getMetadataFor('Symfony\Component\Form\Form');
43+
$metadata = $validator->getMetadataFactory()->getMetadataFor('Symfony\Component\Form\Form');
4744
} else {
48-
throw new \InvalidArgumentException('Validator must be instance of Symfony\Component\Validator\Validator\ValidatorInterface or Symfony\Component\Validator\ValidatorInterface');
45+
throw new UnexpectedTypeException($validator, 'Symfony\Component\Validator\Validator\ValidatorInterface or Symfony\Component\Validator\ValidatorInterface');
4946
}
5047

5148
// Register the form constraints in the validator programmatically.
5249
// This functionality is required when using the Form component without
5350
// the DIC, where the XML file is loaded automatically. Thus the following
5451
// code must be kept synchronized with validation.xml
5552

53+
/** @var $metadata ClassMetadata */
5654
$metadata->addConstraint(new Form());
5755
$metadata->addPropertyConstraint('children', new Valid());
56+
57+
$this->validator = $validator;
5858
}
5959

6060
public function loadTypeGuesser()
6161
{
62-
return new ValidatorTypeGuesser($this->validator->getMetadataFactory());
62+
// 2.4 API
63+
if ($this->validator instanceof LegacyValidatorInterface) {
64+
return new ValidatorTypeGuesser($this->validator->getMetadataFactory());
65+
}
66+
67+
// 2.5 API - ValidatorInterface extends MetadataFactoryInterface
68+
return new ValidatorTypeGuesser($this->validator);
6369
}
6470

6571
protected function loadTypeExtensions()

src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorExtensionTest.php

Lines changed: 42 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,79 +15,70 @@
1515

1616
class ValidatorExtensionTest extends \PHPUnit_Framework_TestCase
1717
{
18-
public function testValidatorInterfaceSinceSymfony25()
18+
public function test2Dot5ValidationApi()
1919
{
20-
$classMetaData = $this->createClassMetaDataMock();
21-
22-
// Mock of ValidatorInterface since apiVersion 2.5
2320
$validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface');
21+
$metadata = $this->getMockBuilder('Symfony\Component\Validator\Mapping\ClassMetadata')
22+
->disableOriginalConstructor()
23+
->getMock();
2424

25-
$validator
26-
->expects($this->once())
25+
$validator->expects($this->once())
2726
->method('getMetadataFor')
2827
->with($this->identicalTo('Symfony\Component\Form\Form'))
29-
->will($this->returnValue($classMetaData))
30-
;
28+
->will($this->returnValue($metadata));
29+
30+
// Verify that the constraints are added
31+
$metadata->expects($this->once())
32+
->method('addConstraint')
33+
->with($this->isInstanceOf('Symfony\Component\Form\Extension\Validator\Constraints\Form'));
34+
35+
$metadata->expects($this->once())
36+
->method('addPropertyConstraint')
37+
->with('children', $this->isInstanceOf('Symfony\Component\Validator\Constraints\Valid'));
3138

32-
$validatorExtension = new ValidatorExtension($validator);
33-
$this->assertAttributeSame($validator, 'validator', $validatorExtension);
39+
$extension = new ValidatorExtension($validator);
40+
$guesser = $extension->loadTypeGuesser();
41+
42+
$this->assertInstanceOf('Symfony\Component\Form\Extension\Validator\ValidatorTypeGuesser', $guesser);
3443
}
3544

36-
public function testValidatorInterfaceUntilSymfony24()
45+
public function test2Dot4ValidationApi()
3746
{
38-
$classMetaData = $this->createClassMetaDataMock();
47+
$factory = $this->getMock('Symfony\Component\Validator\MetadataFactoryInterface');
48+
$validator = $this->getMock('Symfony\Component\Validator\ValidatorInterface');
49+
$metadata = $this->getMockBuilder('Symfony\Component\Validator\Mapping\ClassMetadata')
50+
->disableOriginalConstructor()
51+
->getMock();
3952

40-
$metaDataFactory = $this->getMock('Symfony\Component\Validator\MetadataFactoryInterface');
53+
$validator->expects($this->any())
54+
->method('getMetadataFactory')
55+
->will($this->returnValue($factory));
4156

42-
$metaDataFactory
43-
->expects($this->once())
57+
$factory->expects($this->once())
4458
->method('getMetadataFor')
4559
->with($this->identicalTo('Symfony\Component\Form\Form'))
46-
->will($this->returnValue($classMetaData))
47-
;
60+
->will($this->returnValue($metadata));
4861

49-
// Mock of ValidatorInterface until apiVersion 2.4
50-
$validator = $this->getMock('Symfony\Component\Validator\ValidatorInterface');
62+
// Verify that the constraints are added
63+
$metadata->expects($this->once())
64+
->method('addConstraint')
65+
->with($this->isInstanceOf('Symfony\Component\Form\Extension\Validator\Constraints\Form'));
5166

52-
$validator
53-
->expects($this->once())
54-
->method('getMetadataFactory')
55-
->will($this->returnValue($metaDataFactory))
56-
;
67+
$metadata->expects($this->once())
68+
->method('addPropertyConstraint')
69+
->with('children', $this->isInstanceOf('Symfony\Component\Validator\Constraints\Valid'));
5770

58-
$validatorExtension = new ValidatorExtension($validator);
59-
$this->assertAttributeSame($validator, 'validator', $validatorExtension);
71+
$extension = new ValidatorExtension($validator);
72+
$guesser = $extension->loadTypeGuesser();
73+
74+
$this->assertInstanceOf('Symfony\Component\Form\Extension\Validator\ValidatorTypeGuesser', $guesser);
6075
}
6176

6277
/**
63-
* @expectedException \InvalidArgumentException
78+
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
6479
*/
6580
public function testInvalidValidatorInterface()
6681
{
6782
new ValidatorExtension(null);
6883
}
69-
70-
/**
71-
* @return mixed
72-
*/
73-
private function createClassMetaDataMock()
74-
{
75-
$classMetaData = $this->getMockBuilder('Symfony\Component\Validator\Mapping\ClassMetadata')
76-
->disableOriginalConstructor()
77-
->getMock();
78-
79-
$classMetaData
80-
->expects($this->once())
81-
->method('addConstraint')
82-
->with($this->isInstanceOf('Symfony\Component\Form\Extension\Validator\Constraints\Form'));
83-
$classMetaData
84-
->expects($this->once())
85-
->method('addPropertyConstraint')
86-
->with(
87-
$this->identicalTo('children'),
88-
$this->isInstanceOf('Symfony\Component\Validator\Constraints\Valid')
89-
);
90-
91-
return $classMetaData;
92-
}
9384
}

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,9 @@ public function __construct($mongo, array $options)
6262
$this->mongo = $mongo;
6363

6464
$this->options = array_merge(array(
65-
'id_field' => '_id',
66-
'data_field' => 'data',
67-
'time_field' => 'time',
68-
'expiry_field' => false,
65+
'id_field' => '_id',
66+
'data_field' => 'data',
67+
'time_field' => 'time',
6968
), $options);
7069
}
7170

@@ -110,9 +109,6 @@ public function gc($maxlifetime)
110109
*
111110
* See: http://docs.mongodb.org/manual/tutorial/expire-data/
112111
*/
113-
if (false !== $this->options['expiry_field']) {
114-
return true;
115-
}
116112
$time = new \MongoDate(time() - $maxlifetime);
117113

118114
$this->getCollection()->remove(array(
@@ -127,27 +123,12 @@ public function gc($maxlifetime)
127123
*/
128124
public function write($sessionId, $data)
129125
{
130-
$fields = array(
131-
$this->options['data_field'] => new \MongoBinData($data, \MongoBinData::BYTE_ARRAY),
132-
$this->options['time_field'] => new \MongoDate(),
133-
);
134-
135-
/* Note: As discussed in the gc method of this class. You can utilise
136-
* TTL collections in MongoDB 2.2+
137-
* We are setting the "expiry_field" as part of the write operation here
138-
* You will need to create the index on your collection that expires documents
139-
* at that time
140-
* e.g.
141-
* db.MySessionCollection.ensureIndex( { "expireAt": 1 }, { expireAfterSeconds: 0 } )
142-
*/
143-
if (false !== $this->options['expiry_field']) {
144-
$expiry = new \MongoDate(time() + (int) ini_get('session.gc_maxlifetime'));
145-
$fields[$this->options['expiry_field']] = $expiry;
146-
}
147-
148126
$this->getCollection()->update(
149127
array($this->options['id_field'] => $sessionId),
150-
array('$set' => $fields),
128+
array('$set' => array(
129+
$this->options['data_field'] => new \MongoBinData($data, \MongoBinData::BYTE_ARRAY),
130+
$this->options['time_field'] => new \MongoDate(),
131+
)),
151132
array('upsert' => true, 'multiple' => false)
152133
);
153134

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php

Lines changed: 3 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected function setUp()
4141
'data_field' => 'data',
4242
'time_field' => 'time',
4343
'database' => 'sf2-test',
44-
'collection' => 'session-test',
44+
'collection' => 'session-test'
4545
);
4646

4747
$this->storage = new MongoDbSessionHandler($this->mongo, $this->options);
@@ -100,45 +100,6 @@ public function testWrite()
100100
$that->assertInstanceOf('MongoDate', $data[$this->options['time_field']]);
101101
}
102102

103-
public function testWriteWhenUsingExpiresField()
104-
{
105-
$this->options = array(
106-
'id_field' => '_id',
107-
'data_field' => 'data',
108-
'time_field' => 'time',
109-
'database' => 'sf2-test',
110-
'collection' => 'session-test',
111-
'expiry_field' => 'expiresAt'
112-
);
113-
114-
$this->storage = new MongoDbSessionHandler($this->mongo, $this->options);
115-
116-
$collection = $this->createMongoCollectionMock();
117-
118-
$this->mongo->expects($this->once())
119-
->method('selectCollection')
120-
->with($this->options['database'], $this->options['collection'])
121-
->will($this->returnValue($collection));
122-
123-
$that = $this;
124-
$data = array();
125-
126-
$collection->expects($this->once())
127-
->method('update')
128-
->will($this->returnCallback(function ($criteria, $updateData, $options) use ($that, &$data) {
129-
$that->assertEquals(array($that->options['id_field'] => 'foo'), $criteria);
130-
$that->assertEquals(array('upsert' => true, 'multiple' => false), $options);
131-
132-
$data = $updateData['$set'];
133-
}));
134-
135-
$this->assertTrue($this->storage->write('foo', 'bar'));
136-
137-
$this->assertEquals('bar', $data[$this->options['data_field']]->bin);
138-
$that->assertInstanceOf('MongoDate', $data[$this->options['time_field']]);
139-
$that->assertInstanceOf('MongoDate', $data[$this->options['expiry_field']]);
140-
}
141-
142103
public function testReplaceSessionData()
143104
{
144105
$collection = $this->createMongoCollectionMock();
@@ -193,36 +154,10 @@ public function testGc()
193154
->method('remove')
194155
->will($this->returnCallback(function ($criteria) use ($that) {
195156
$that->assertInstanceOf('MongoDate', $criteria[$that->options['time_field']]['$lt']);
196-
$that->assertGreaterThanOrEqual(time() - 1, $criteria[$that->options['time_field']]['$lt']->sec);
157+
$that->assertGreaterThanOrEqual(time() - -1, $criteria[$that->options['time_field']]['$lt']->sec);
197158
}));
198159

199-
$this->assertTrue($this->storage->gc(1));
200-
}
201-
202-
public function testGcWhenUsingExpiresField()
203-
{
204-
$this->options = array(
205-
'id_field' => '_id',
206-
'data_field' => 'data',
207-
'time_field' => 'time',
208-
'database' => 'sf2-test',
209-
'collection' => 'session-test',
210-
'expiry_field' => 'expiresAt'
211-
);
212-
213-
$this->storage = new MongoDbSessionHandler($this->mongo, $this->options);
214-
215-
$collection = $this->createMongoCollectionMock();
216-
217-
$this->mongo->expects($this->never())
218-
->method('selectCollection');
219-
220-
$that = $this;
221-
222-
$collection->expects($this->never())
223-
->method('remove');
224-
225-
$this->assertTrue($this->storage->gc(1));
160+
$this->assertTrue($this->storage->gc(-1));
226161
}
227162

228163
public function testGetConnection()

src/Symfony/Component/Validator/Resources/translations/validators.nl.xlf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@
180180
</trans-unit>
181181
<trans-unit id="48">
182182
<source>This value should have exactly {{ limit }} character.|This value should have exactly {{ limit }} characters.</source>
183-
<target>Deze waarde moet exact {{ limit }} tekens lang zijn.</target>
183+
<target>Deze waarde moet exact {{ limit }} teken lang zijn.|Deze waarde moet exact {{ limit }} tekens lang zijn.</target>
184184
</trans-unit>
185185
<trans-unit id="49">
186186
<source>The file was only partially uploaded.</source>

0 commit comments

Comments
 (0)
0