Skip to content

Commit 703db1e

Browse files
Merge branch '3.1'
* 3.1: [travis] Use 7.0 until 7.1 is fixed [DIC] Fix service autowiring inheritance [Serializer] Fix denormalization of arrays [SecurityBundle] Add missing deprecation notice for form_login.intention Verify explicitly that the request IP is a valid IPv4 address [WebProfilerBundle] replaces tabs characters by spaces.
2 parents 94078a0 + 298a680 commit 703db1e

File tree

12 files changed

+140
-25
lines changed

12 files changed

+140
-25
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ matrix:
2828
- php: 5.6
2929
- php: 7.0
3030
env: deps=high
31-
- php: 7.1
31+
- php: 7.0
3232
env: deps=low
3333
fast_finish: true
3434

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,17 @@
8383
</div>
8484
</div>
8585
{% endif %}
86-
86+
8787
{% if forward_handler is defined %}
88-
<div class="sf-toolbar-info-group">
89-
<div class="sf-toolbar-info-piece">
90-
<b>Forwarded to</b>
91-
<span>
92-
{{ forward_handler }}
93-
(<a href="{{ path('_profiler', { token: collector.forward.token }) }}">{{ collector.forward.token }}</a>)
94-
</span>
95-
</div>
96-
</div>
88+
<div class="sf-toolbar-info-group">
89+
<div class="sf-toolbar-info-piece">
90+
<b>Forwarded to</b>
91+
<span>
92+
{{ forward_handler }}
93+
(<a href="{{ path('_profiler', { token: collector.forward.token }) }}">{{ collector.forward.token }}</a>)
94+
</span>
95+
</div>
96+
</div>
9797
{% endif %}
9898
{% endset %}
9999

src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ private function resolveDefinition(ContainerBuilder $container, DefinitionDecora
127127
$def->setFile($parentDef->getFile());
128128
$def->setPublic($parentDef->isPublic());
129129
$def->setLazy($parentDef->isLazy());
130+
$def->setAutowired($parentDef->isAutowired());
130131

131132
// overwrite with values specified in the decorator
132133
$changes = $definition->getChanges();
@@ -151,6 +152,9 @@ private function resolveDefinition(ContainerBuilder $container, DefinitionDecora
151152
if (isset($changes['deprecated'])) {
152153
$def->setDeprecated($definition->isDeprecated(), $definition->getDeprecationMessage('%service_id%'));
153154
}
155+
if (isset($changes['autowire'])) {
156+
$def->setAutowired($definition->isAutowired());
157+
}
154158
if (isset($changes['decorated_service'])) {
155159
$decoratedService = $definition->getDecoratedService();
156160
if (null === $decoratedService) {

src/Symfony/Component/DependencyInjection/DefinitionDecorator.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ public function setDeprecated($boolean = true, $template = null)
134134
return parent::setDeprecated($boolean, $template);
135135
}
136136

137+
/**
138+
* {@inheritdoc}
139+
*/
140+
public function setAutowired($autowired)
141+
{
142+
$this->changes['autowire'] = true;
143+
144+
return parent::setAutowired($autowired);
145+
}
146+
137147
/**
138148
* Gets an argument to pass to the service constructor/factory method.
139149
*

src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,36 @@ public function testSetLazyOnServiceIsParent()
210210
$this->assertTrue($container->getDefinition('child1')->isLazy());
211211
}
212212

213+
public function testSetAutowiredOnServiceHasParent()
214+
{
215+
$container = new ContainerBuilder();
216+
217+
$container->register('parent', 'stdClass');
218+
219+
$container->setDefinition('child1', new DefinitionDecorator('parent'))
220+
->setAutowired(true)
221+
;
222+
223+
$this->process($container);
224+
225+
$this->assertTrue($container->getDefinition('child1')->isAutowired());
226+
}
227+
228+
public function testSetAutowiredOnServiceIsParent()
229+
{
230+
$container = new ContainerBuilder();
231+
232+
$container->register('parent', 'stdClass')
233+
->setAutowired(true)
234+
;
235+
236+
$container->setDefinition('child1', new DefinitionDecorator('parent'));
237+
238+
$this->process($container);
239+
240+
$this->assertTrue($container->getDefinition('child1')->isAutowired());
241+
}
242+
213243
public function testDeepDefinitionsResolving()
214244
{
215245
$container = new ContainerBuilder();

src/Symfony/Component/DependencyInjection/Tests/DefinitionDecoratorTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ public function testSetLazy()
6969
$this->assertEquals(array('lazy' => true), $def->getChanges());
7070
}
7171

72+
public function testSetAutowired()
73+
{
74+
$def = new DefinitionDecorator('foo');
75+
76+
$this->assertFalse($def->isAutowired());
77+
$this->assertSame($def, $def->setAutowired(false));
78+
$this->assertFalse($def->isAutowired());
79+
$this->assertEquals(array('autowire' => true), $def->getChanges());
80+
}
81+
7282
public function testSetArgument()
7383
{
7484
$def = new DefinitionDecorator('foo');

src/Symfony/Component/HttpFoundation/IpUtils.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,14 @@ public static function checkIp($requestIp, $ips)
6161
*/
6262
public static function checkIp4($requestIp, $ip)
6363
{
64+
if (!filter_var($requestIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
65+
return false;
66+
}
67+
6468
if (false !== strpos($ip, '/')) {
6569
list($address, $netmask) = explode('/', $ip, 2);
6670

6771
if ($netmask === '0') {
68-
// Ensure IP is valid - using ip2long below implicitly validates, but we need to do it manually here
6972
return filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
7073
}
7174

src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function testIpv4Provider()
3737
array(true, '1.2.3.4', '0.0.0.0/0'),
3838
array(true, '1.2.3.4', '192.168.1.0/0'),
3939
array(false, '1.2.3.4', '256.256.256/0'), // invalid CIDR notation
40+
array(false, 'an_invalid_ip', '192.168.1.0/24'),
4041
);
4142
}
4243

src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,18 @@ private function validateAndDenormalize($currentClass, $attribute, $data, $forma
248248
return;
249249
}
250250

251-
$builtinType = $type->getBuiltinType();
252-
$class = $type->getClassName();
251+
if ($type->isCollection() && null !== ($collectionValueType = $type->getCollectionValueType()) && Type::BUILTIN_TYPE_OBJECT === $collectionValueType->getBuiltinType()) {
252+
$builtinType = Type::BUILTIN_TYPE_OBJECT;
253+
$class = $collectionValueType->getClassName().'[]';
254+
255+
if (null !== $collectionKeyType = $type->getCollectionKeyType()) {
256+
$context['key_type'] = $collectionKeyType;
257+
}
258+
} else {
259+
$builtinType = $type->getBuiltinType();
260+
$class = $type->getClassName();
261+
}
262+
253263
$expectedTypes[Type::BUILTIN_TYPE_OBJECT === $builtinType && $class ? $class : $builtinType] = true;
254264

255265
if (Type::BUILTIN_TYPE_OBJECT === $builtinType) {

src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Serializer\Exception\BadMethodCallException;
1515
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
16+
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
1617
use Symfony\Component\Serializer\SerializerAwareInterface;
1718
use Symfony\Component\Serializer\SerializerInterface;
1819

@@ -30,6 +31,8 @@ class ArrayDenormalizer implements DenormalizerInterface, SerializerAwareInterfa
3031

3132
/**
3233
* {@inheritdoc}
34+
*
35+
* @throws UnexpectedValueException
3336
*/
3437
public function denormalize($data, $class, $format = null, array $context = array())
3538
{
@@ -46,12 +49,16 @@ public function denormalize($data, $class, $format = null, array $context = arra
4649
$serializer = $this->serializer;
4750
$class = substr($class, 0, -2);
4851

49-
return array_map(
50-
function ($data) use ($serializer, $class, $format, $context) {
51-
return $serializer->denormalize($data, $class, $format, $context);
52-
},
53-
$data
54-
);
52+
$builtinType = isset($context['key_type']) ? $context['key_type']->getBuiltinType() : null;
53+
foreach ($data as $key => $value) {
54+
if (null !== $builtinType && !call_user_func('is_'.$builtinType, $key)) {
55+
throw new UnexpectedValueException(sprintf('The type of the key "%s" must be "%s" ("%s" given).', $key, $builtinType, gettype($key)));
56+
}
57+
58+
$data[$key] = $serializer->denormalize($value, $class, $format, $context);
59+
}
60+
61+
return $data;
5562
}
5663

5764
/**

src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
namespace Symfony\Component\Serializer\Tests\Normalizer;
1313

1414
use Doctrine\Common\Annotations\AnnotationReader;
15+
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
1516
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
17+
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
1618
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
1719
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
20+
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
1821
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
1922
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
2023
use Symfony\Component\Serializer\Serializer;
@@ -569,13 +572,21 @@ public function testThrowUnexpectedValueException()
569572

570573
public function testDenomalizeRecursive()
571574
{
572-
$normalizer = new ObjectNormalizer(null, null, null, new ReflectionExtractor());
573-
$serializer = new Serializer(array(new DateTimeNormalizer(), $normalizer));
575+
$extractor = new PropertyInfoExtractor(array(), array(new PhpDocExtractor(), new ReflectionExtractor()));
576+
$normalizer = new ObjectNormalizer(null, null, null, $extractor);
577+
$serializer = new Serializer(array(new ArrayDenormalizer(), new DateTimeNormalizer(), $normalizer));
578+
579+
$obj = $serializer->denormalize(array(
580+
'inner' => array('foo' => 'foo', 'bar' => 'bar'),
581+
'date' => '1988/01/21',
582+
'inners' => array(array('foo' => 1), array('foo' => 2)),
583+
), ObjectOuter::class);
574584

575-
$obj = $serializer->denormalize(array('inner' => array('foo' => 'foo', 'bar' => 'bar'), 'date' => '1988/01/21'), ObjectOuter::class);
576585
$this->assertEquals('foo', $obj->getInner()->foo);
577586
$this->assertEquals('bar', $obj->getInner()->bar);
578587
$this->assertEquals('1988-01-21', $obj->getDate()->format('Y-m-d'));
588+
$this->assertEquals(1, $obj->getInners()[0]->foo);
589+
$this->assertEquals(2, $obj->getInners()[1]->foo);
579590
}
580591

581592
/**
@@ -590,6 +601,19 @@ public function testRejectInvalidType()
590601
$serializer->denormalize(array('date' => 'foo'), ObjectOuter::class);
591602
}
592603

604+
/**
605+
* @expectedException UnexpectedValueException
606+
* @expectedExceptionMessage The type of the key "a" must be "int" ("string" given).
607+
*/
608+
public function testRejectInvalidKey()
609+
{
610+
$extractor = new PropertyInfoExtractor(array(), array(new PhpDocExtractor(), new ReflectionExtractor()));
611+
$normalizer = new ObjectNormalizer(null, null, null, $extractor);
612+
$serializer = new Serializer(array(new ArrayDenormalizer(), new DateTimeNormalizer(), $normalizer));
613+
614+
$serializer->denormalize(array('inners' => array('a' => array('foo' => 1))), ObjectOuter::class);
615+
}
616+
593617
public function testExtractAttributesRespectsFormat()
594618
{
595619
$normalizer = new FormatAndContextAwareNormalizer();
@@ -784,6 +808,11 @@ class ObjectOuter
784808
private $inner;
785809
private $date;
786810

811+
/**
812+
* @var ObjectInner[]
813+
*/
814+
private $inners;
815+
787816
public function getInner()
788817
{
789818
return $this->inner;
@@ -803,6 +832,16 @@ public function getDate()
803832
{
804833
return $this->date;
805834
}
835+
836+
public function setInners(array $inners)
837+
{
838+
$this->inners = $inners;
839+
}
840+
841+
public function getInners()
842+
{
843+
return $this->inners;
844+
}
806845
}
807846

808847
class ObjectInner

src/Symfony/Component/Serializer/composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424
"symfony/property-access": "~2.8|~3.0",
2525
"symfony/http-foundation": "~2.8|~3.0",
2626
"symfony/cache": "~3.1",
27-
"symfony/property-info": "~2.8|~3.0",
27+
"symfony/property-info": "~3.1",
2828
"doctrine/annotations": "~1.0",
29-
"doctrine/cache": "~1.0"
29+
"doctrine/cache": "~1.0",
30+
"phpdocumentor/reflection-docblock": "~3.0"
3031
},
3132
"conflict": {
3233
"symfony/property-access": ">=3.0,<3.0.4|>=2.8,<2.8.4"

0 commit comments

Comments
 (0)