Skip to content

Commit 7027068

Browse files
committed
Merge branch '2.3' into 2.4
* 2.3: [HttpFoundation] implement session locking for PDO [DomCrawler] Fixed the coding standards to use strict comparisons [HttpKernel] removed absolute paths from the generated container [DomCrawler] Fixed the initial state for options without value attribute Fixed the handling of boolean attributes in ChoiceFormField Conflicts: src/Symfony/Component/DomCrawler/Tests/Field/ChoiceFormFieldTest.php src/Symfony/Component/HttpKernel/Tests/KernelTest.php
2 parents 5be0125 + 309046a commit 7027068

File tree

19 files changed

+488
-149
lines changed

19 files changed

+488
-149
lines changed

src/Symfony/Component/DomCrawler/Field/ChoiceFormField.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ public function untick()
123123
*/
124124
public function setValue($value)
125125
{
126-
if ('checkbox' == $this->type && false === $value) {
126+
if ('checkbox' === $this->type && false === $value) {
127127
// uncheck
128128
$this->value = null;
129-
} elseif ('checkbox' == $this->type && true === $value) {
129+
} elseif ('checkbox' === $this->type && true === $value) {
130130
// check
131131
$this->value = $this->options[0]['value'];
132132
} else {
@@ -167,14 +167,14 @@ public function setValue($value)
167167
*/
168168
public function addChoice(\DOMNode $node)
169169
{
170-
if (!$this->multiple && 'radio' != $this->type) {
170+
if (!$this->multiple && 'radio' !== $this->type) {
171171
throw new \LogicException(sprintf('Unable to add a choice for "%s" as it is not multiple or is not a radio button.', $this->name));
172172
}
173173

174174
$option = $this->buildOptionValue($node);
175175
$this->options[] = $option;
176176

177-
if ($node->getAttribute('checked')) {
177+
if ($node->hasAttribute('checked')) {
178178
$this->value = $option['value'];
179179
}
180180
}
@@ -206,11 +206,11 @@ public function isMultiple()
206206
*/
207207
protected function initialize()
208208
{
209-
if ('input' != $this->node->nodeName && 'select' != $this->node->nodeName) {
209+
if ('input' !== $this->node->nodeName && 'select' !== $this->node->nodeName) {
210210
throw new \LogicException(sprintf('A ChoiceFormField can only be created from an input or select tag (%s given).', $this->node->nodeName));
211211
}
212212

213-
if ('input' == $this->node->nodeName && 'checkbox' != strtolower($this->node->getAttribute('type')) && 'radio' != strtolower($this->node->getAttribute('type'))) {
213+
if ('input' === $this->node->nodeName && 'checkbox' !== strtolower($this->node->getAttribute('type')) && 'radio' !== strtolower($this->node->getAttribute('type'))) {
214214
throw new \LogicException(sprintf('A ChoiceFormField can only be created from an input tag with a type of checkbox or radio (given type is %s).', $this->node->getAttribute('type')));
215215
}
216216

@@ -223,7 +223,7 @@ protected function initialize()
223223
$optionValue = $this->buildOptionValue($this->node);
224224
$this->options[] = $optionValue;
225225

226-
if ($this->node->getAttribute('checked')) {
226+
if ($this->node->hasAttribute('checked')) {
227227
$this->value = $optionValue['value'];
228228
}
229229
} else {
@@ -236,22 +236,22 @@ protected function initialize()
236236

237237
$found = false;
238238
foreach ($this->xpath->query('descendant::option', $this->node) as $option) {
239-
$this->options[] = $this->buildOptionValue($option);
239+
$optionValue = $this->buildOptionValue($option);
240+
$this->options[] = $optionValue;
240241

241-
if ($option->getAttribute('selected')) {
242+
if ($option->hasAttribute('selected')) {
242243
$found = true;
243244
if ($this->multiple) {
244-
$this->value[] = $option->getAttribute('value');
245+
$this->value[] = $optionValue['value'];
245246
} else {
246-
$this->value = $option->getAttribute('value');
247+
$this->value = $optionValue['value'];
247248
}
248249
}
249250
}
250251

251252
// if no option is selected and if it is a simple select box, take the first option as the value
252-
$option = $this->xpath->query('descendant::option', $this->node)->item(0);
253-
if (!$found && !$this->multiple && $option instanceof \DOMElement) {
254-
$this->value = $option->getAttribute('value');
253+
if (!$found && !$this->multiple && !empty($this->options)) {
254+
$this->value = $this->options[0]['value'];
255255
}
256256
}
257257
}
@@ -269,13 +269,13 @@ private function buildOptionValue($node)
269269

270270
$defaultValue = (isset($node->nodeValue) && !empty($node->nodeValue)) ? $node->nodeValue : '1';
271271
$option['value'] = $node->hasAttribute('value') ? $node->getAttribute('value') : $defaultValue;
272-
$option['disabled'] = ($node->hasAttribute('disabled') && $node->getAttribute('disabled') == 'disabled');
272+
$option['disabled'] = $node->hasAttribute('disabled');
273273

274274
return $option;
275275
}
276276

277277
/**
278-
* Checks whether given vale is in the existing options
278+
* Checks whether given value is in the existing options
279279
*
280280
* @param string $optionValue
281281
* @param array $options

src/Symfony/Component/DomCrawler/Field/FileFormField.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ public function setFilePath($path)
9999
*/
100100
protected function initialize()
101101
{
102-
if ('input' != $this->node->nodeName) {
102+
if ('input' !== $this->node->nodeName) {
103103
throw new \LogicException(sprintf('A FileFormField can only be created from an input tag (%s given).', $this->node->nodeName));
104104
}
105105

106-
if ('file' != strtolower($this->node->getAttribute('type'))) {
106+
if ('file' !== strtolower($this->node->getAttribute('type'))) {
107107
throw new \LogicException(sprintf('A FileFormField can only be created from an input tag with a type of file (given type is %s).', $this->node->getAttribute('type')));
108108
}
109109

src/Symfony/Component/DomCrawler/Field/InputFormField.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ class InputFormField extends FormField
3030
*/
3131
protected function initialize()
3232
{
33-
if ('input' != $this->node->nodeName && 'button' != $this->node->nodeName) {
33+
if ('input' !== $this->node->nodeName && 'button' !== $this->node->nodeName) {
3434
throw new \LogicException(sprintf('An InputFormField can only be created from an input or button tag (%s given).', $this->node->nodeName));
3535
}
3636

37-
if ('checkbox' == strtolower($this->node->getAttribute('type'))) {
37+
if ('checkbox' === strtolower($this->node->getAttribute('type'))) {
3838
throw new \LogicException('Checkboxes should be instances of ChoiceFormField.');
3939
}
4040

41-
if ('file' == strtolower($this->node->getAttribute('type'))) {
41+
if ('file' === strtolower($this->node->getAttribute('type'))) {
4242
throw new \LogicException('File inputs should be instances of FileFormField.');
4343
}
4444

src/Symfony/Component/DomCrawler/Field/TextareaFormField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class TextareaFormField extends FormField
2727
*/
2828
protected function initialize()
2929
{
30-
if ('textarea' != $this->node->nodeName) {
30+
if ('textarea' !== $this->node->nodeName) {
3131
throw new \LogicException(sprintf('A TextareaFormField can only be created from a textarea tag (%s given).', $this->node->nodeName));
3232
}
3333

src/Symfony/Component/DomCrawler/Form.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Form extends Link implements \ArrayAccess
2828
private $button;
2929

3030
/**
31-
* @var Field\FormField[]
31+
* @var FormFieldRegistry
3232
*/
3333
private $fields;
3434

@@ -368,7 +368,7 @@ public function disableValidation()
368368
protected function setNode(\DOMNode $node)
369369
{
370370
$this->button = $node;
371-
if ('button' == $node->nodeName || ('input' == $node->nodeName && in_array(strtolower($node->getAttribute('type')), array('submit', 'button', 'image')))) {
371+
if ('button' === $node->nodeName || ('input' === $node->nodeName && in_array(strtolower($node->getAttribute('type')), array('submit', 'button', 'image')))) {
372372
if ($node->hasAttribute('form')) {
373373
// if the node has the HTML5-compliant 'form' attribute, use it
374374
$formId = $node->getAttribute('form');
@@ -385,8 +385,8 @@ protected function setNode(\DOMNode $node)
385385
if (null === $node = $node->parentNode) {
386386
throw new \LogicException('The selected node does not have a form ancestor.');
387387
}
388-
} while ('form' != $node->nodeName);
389-
} elseif ('form' != $node->nodeName) {
388+
} while ('form' !== $node->nodeName);
389+
} elseif ('form' !== $node->nodeName) {
390390
throw new \LogicException(sprintf('Unable to submit on a "%s" tag.', $node->nodeName));
391391
}
392392

src/Symfony/Component/DomCrawler/FormFieldRegistry.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function set($name, $value)
137137
/**
138138
* Returns the list of field with their value.
139139
*
140-
* @return array The list of fields as array((string) Fully qualified name => (mixed) value)
140+
* @return FormField[] The list of fields as array((string) Fully qualified name => (mixed) value)
141141
*/
142142
public function all()
143143
{
@@ -196,7 +196,7 @@ private function walk(array $array, $base = '', array &$output = array())
196196
*
197197
* @param string $name The name of the field
198198
*
199-
* @return array The list of segments
199+
* @return string[] The list of segments
200200
*
201201
* @throws \InvalidArgumentException when the name is malformed
202202
*/

src/Symfony/Component/DomCrawler/Link.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ protected function canonicalizePath($path)
188188
*/
189189
protected function setNode(\DOMNode $node)
190190
{
191-
if ('a' != $node->nodeName && 'area' != $node->nodeName) {
191+
if ('a' !== $node->nodeName && 'area' !== $node->nodeName) {
192192
throw new \LogicException(sprintf('Unable to click on a "%s" tag.', $node->nodeName));
193193
}
194194

src/Symfony/Component/DomCrawler/Tests/Field/ChoiceFormFieldTest.php

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public function testIsMultiple()
7373
$field = new ChoiceFormField($node);
7474

7575
$this->assertTrue($field->isMultiple(), '->isMultiple() returns true for selects with the multiple attribute');
76+
77+
$node = $this->createNode('select', '', array('multiple' => ''));
78+
$field = new ChoiceFormField($node);
79+
80+
$this->assertTrue($field->isMultiple(), '->isMultiple() returns true for selects with an empty multiple attribute');
7681
}
7782

7883
public function testSelects()
@@ -107,6 +112,14 @@ public function testSelects()
107112
}
108113
}
109114

115+
public function testSelectWithEmptyBooleanAttribute()
116+
{
117+
$node = $this->createSelectNode(array('foo' => false, 'bar' => true), array(), '');
118+
$field = new ChoiceFormField($node);
119+
120+
$this->assertEquals('bar', $field->getValue());
121+
}
122+
110123
public function testMultipleSelects()
111124
{
112125
$node = $this->createSelectNode(array('foo' => false, 'bar' => false), array('multiple' => 'multiple'));
@@ -166,12 +179,25 @@ public function testRadioButtons()
166179
}
167180
}
168181

182+
public function testRadioButtonsWithEmptyBooleanAttribute()
183+
{
184+
$node = $this->createNode('input', '', array('type' => 'radio', 'name' => 'name', 'value' => 'foo'));
185+
$field = new ChoiceFormField($node);
186+
$node = $this->createNode('input', '', array('type' => 'radio', 'name' => 'name', 'value' => 'bar', 'checked' => ''));
187+
$field->addChoice($node);
188+
189+
$this->assertTrue($field->hasValue(), '->hasValue() returns true when a radio button is selected');
190+
$this->assertEquals('bar', $field->getValue(), '->getValue() returns the value attribute of the selected radio button');
191+
}
192+
169193
public function testRadioButtonIsDisabled()
170194
{
171195
$node = $this->createNode('input', '', array('type' => 'radio', 'name' => 'name', 'value' => 'foo', 'disabled' => 'disabled'));
172196
$field = new ChoiceFormField($node);
173197
$node = $this->createNode('input', '', array('type' => 'radio', 'name' => 'name', 'value' => 'bar'));
174198
$field->addChoice($node);
199+
$node = $this->createNode('input', '', array('type' => 'radio', 'name' => 'name', 'value' => 'baz', 'disabled' => ''));
200+
$field->addChoice($node);
175201

176202
$field->select('foo');
177203
$this->assertEquals('foo', $field->getValue(), '->getValue() returns the value attribute of the selected radio button');
@@ -180,6 +206,10 @@ public function testRadioButtonIsDisabled()
180206
$field->select('bar');
181207
$this->assertEquals('bar', $field->getValue(), '->getValue() returns the value attribute of the selected radio button');
182208
$this->assertFalse($field->isDisabled());
209+
210+
$field->select('baz');
211+
$this->assertEquals('baz', $field->getValue(), '->getValue() returns the value attribute of the selected radio button');
212+
$this->assertTrue($field->isDisabled());
183213
}
184214

185215
public function testCheckboxes()
@@ -225,6 +255,15 @@ public function testCheckboxes()
225255
}
226256
}
227257

258+
public function testCheckboxWithEmptyBooleanAttribute()
259+
{
260+
$node = $this->createNode('input', '', array('type' => 'checkbox', 'name' => 'name', 'value' => 'foo', 'checked' => ''));
261+
$field = new ChoiceFormField($node);
262+
263+
$this->assertTrue($field->hasValue(), '->hasValue() returns true when the checkbox is checked');
264+
$this->assertEquals('foo', $field->getValue());
265+
}
266+
228267
public function testTick()
229268
{
230269
$node = $this->createSelectNode(array('foo' => false, 'bar' => false));
@@ -280,6 +319,11 @@ public function testOptionWithNoValue()
280319
{
281320
$node = $this->createSelectNodeWithEmptyOption(array('foo' => false, 'bar' => false));
282321
$field = new ChoiceFormField($node);
322+
$this->assertEquals('foo', $field->getValue());
323+
324+
$node = $this->createSelectNodeWithEmptyOption(array('foo' => false, 'bar' => true));
325+
$field = new ChoiceFormField($node);
326+
$this->assertEquals('bar', $field->getValue());
283327
$field->select('foo');
284328
$this->assertEquals('foo', $field->getValue(), '->select() changes the selected option');
285329
}
@@ -299,7 +343,7 @@ public function testDisableValidation()
299343
$this->assertEquals(array('foobar'), $field->getValue(), '->disableValidation() allows to set a value which is not in the selected options.');
300344
}
301345

302-
protected function createSelectNode($options, $attributes = array())
346+
protected function createSelectNode($options, $attributes = array(), $selectedAttrText = 'selected')
303347
{
304348
$document = new \DOMDocument();
305349
$node = $document->createElement('select');
@@ -313,7 +357,7 @@ protected function createSelectNode($options, $attributes = array())
313357
$option = $document->createElement('option', $value);
314358
$option->setAttribute('value', $value);
315359
if ($selected) {
316-
$option->setAttribute('selected', 'selected');
360+
$option->setAttribute('selected', $selectedAttrText);
317361
}
318362
$node->appendChild($option);
319363
}

src/Symfony/Component/DomCrawler/Tests/FormTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,6 @@ protected function createForm($form, $method = null, $currentUri = null)
813813
$dom = new \DOMDocument();
814814
$dom->loadHTML('<html>'.$form.'</html>');
815815

816-
$nodes = $dom->getElementsByTagName('input');
817816
$xPath = new \DOMXPath($dom);
818817
$nodes = $xPath->query('//input | //button');
819818

@@ -876,5 +875,4 @@ public function testgetPhpValuesWithEmptyTextarea()
876875
$form = new Form($nodes->item(0), 'http://example.com');
877876
$this->assertEquals($form->getPhpValues(), array('example' => ''));
878877
}
879-
880878
}

src/Symfony/Component/HttpFoundation/Resources/stubs/SessionHandlerInterface.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,22 @@
1212
/**
1313
* SessionHandlerInterface for PHP < 5.4
1414
*
15+
* The order in which these methods are invoked by PHP are:
16+
* 1. open [session_start]
17+
* 2. read
18+
* 3. gc [optional depending on probability settings: gc_probability / gc_divisor]
19+
* 4. destroy [optional when session_regenerate_id(true) is used]
20+
* 5. write [session_write_close] or destroy [session_destroy]
21+
* 6. close
22+
*
1523
* Extensive documentation can be found at php.net, see links:
1624
*
1725
* @see http://php.net/sessionhandlerinterface
1826
* @see http://php.net/session.customhandler
1927
* @see http://php.net/session-set-save-handler
2028
*
2129
* @author Drak <drak@zikula.org>
30+
* @author Tobias Schultze <http://tobion.de>
2231
*/
2332
interface SessionHandlerInterface
2433
{
@@ -57,6 +66,9 @@ public function read($sessionId);
5766
/**
5867
* Writes the session data to the storage.
5968
*
69+
* Care, the session ID passed to write() can be different from the one previously
70+
* received in read() when the session ID changed due to session_regenerate_id().
71+
*
6072
* @see http://php.net/sessionhandlerinterface.write
6173
*
6274
* @param string $sessionId Session ID , see http://php.net/function.session-id

0 commit comments

Comments
 (0)