Skip to content

Commit 9346dff

Browse files
Merge branch '3.3' into 3.4
* 3.3: [TwigBridge] Fix namespaced classes bumped Symfony version to 3.3.2 updated VERSION for 3.3.1 updated CHANGELOG for 3.3.1 [DependencyInjection] Fix named args support in ChildDefinition [Cache] Fallback to positional when keyed results are broken [HttpFoundation][FrameworkBundle] Revert "trusted proxies" BC break [Cache] MemcachedAdapter not working with TagAwareAdapter Remove closure-proxy leftovers [DependencyInjection] Use more clear message when unused environment variables detected [Form][Profiler] Fixes form collector triggering deprecations mitigate BC break with empty trusted_proxies [Profiler] Never wrap in code excerpts [Form][FrameworkBundle] Remove non-existing arg for data_collector.form explain that a role can be an instance of Role [Cache] fix Redis scheme detection mix attr options between type-guess options and user options
2 parents d42e280 + 9e48546 commit 9346dff

File tree

10 files changed

+137
-23
lines changed

10 files changed

+137
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CHANGELOG
77
* Not defining the `type` option of the `framework.workflows.*` configuration entries is deprecated.
88
The default value will be `state_machine` in Symfony 4.0.
99
* Deprecated the `CompilerDebugDumpPass` class
10-
* [BC BREAK] Removed the "framework.trusted_proxies" configuration option and the corresponding "kernel.trusted_proxies" parameter
10+
* Deprecated the "framework.trusted_proxies" configuration option and the corresponding "kernel.trusted_proxies" parameter
1111
* Added a new new version strategy option called json_manifest_path
1212
that allows you to use the `JsonManifestVersionStrategy`.
1313
* Added `Symfony\Bundle\FrameworkBundle\Controller\AbstractController`. It provides

Console/Descriptor/Descriptor.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,4 @@ protected function sortServiceIds(array $serviceIds)
307307

308308
return $serviceIds;
309309
}
310-
311-
protected function formatClosure(\Closure $closure)
312-
{
313-
$r = new \ReflectionFunction($closure);
314-
315-
return 'closure';
316-
}
317310
}

Console/Descriptor/JsonDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ private function getCallableData($callable, array $options = array())
373373
}
374374

375375
if ($callable instanceof \Closure) {
376-
$data['type'] = $this->formatClosure($callable);
376+
$data['type'] = 'closure';
377377

378378
return $data;
379379
}

Console/Descriptor/MarkdownDescriptor.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,7 @@ protected function describeCallable($callable, array $options = array())
352352
}
353353

354354
if ($callable instanceof \Closure) {
355-
$formatted = $this->formatClosure($callable);
356-
$string .= "\n- Type: `$formatted`";
355+
$string .= "\n- Type: `closure`";
357356

358357
return $this->write($string."\n");
359358
}

Console/Descriptor/TextDescriptor.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -475,13 +475,7 @@ private function formatCallable($callable)
475475
}
476476

477477
if ($callable instanceof \Closure) {
478-
$formatted = $this->formatClosure($callable);
479-
480-
if ('closure' === $formatted) {
481-
return '\Closure()';
482-
}
483-
484-
return $formatted.'()';
478+
return '\Closure()';
485479
}
486480

487481
if (method_exists($callable, '__invoke')) {

Console/Descriptor/XmlDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ private function getCallableDocument($callable)
593593
}
594594

595595
if ($callable instanceof \Closure) {
596-
$callableXML->setAttribute('type', $this->formatClosure($callable));
596+
$callableXML->setAttribute('type', 'closure');
597597

598598
return $dom;
599599
}

DependencyInjection/Configuration.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,38 @@ public function getConfigTreeBuilder()
6565
->info("Set true to enable support for the '_method' request parameter to determine the intended HTTP method on POST requests. Note: When using the HttpCache, you need to call the method in your front controller instead")
6666
->defaultTrue()
6767
->end()
68-
->arrayNode('trusted_proxies') // @deprecated in version 3.3, to be removed in 4.0
68+
->arrayNode('trusted_proxies')
6969
->beforeNormalization()
70-
->always()
71-
->thenInvalid('The "framework.trusted_proxies" configuration key has been removed in Symfony 3.3. Use the Request::setTrustedProxies() method in your front controller instead.')
70+
->ifTrue(function ($v) {
71+
@trigger_error('The "framework.trusted_proxies" configuration key has been deprecated in Symfony 3.3. Use the Request::setTrustedProxies() method in your front controller instead.', E_USER_DEPRECATED);
72+
73+
return !is_array($v) && null !== $v;
74+
})
75+
->then(function ($v) { return is_bool($v) ? array() : preg_split('/\s*,\s*/', $v); })
76+
->end()
77+
->prototype('scalar')
78+
->validate()
79+
->ifTrue(function ($v) {
80+
if (empty($v)) {
81+
return false;
82+
}
83+
84+
if (false !== strpos($v, '/')) {
85+
if ('0.0.0.0/0' === $v) {
86+
return false;
87+
}
88+
89+
list($v, $mask) = explode('/', $v, 2);
90+
91+
if (strcmp($mask, (int) $mask) || $mask < 1 || $mask > (false !== strpos($v, ':') ? 128 : 32)) {
92+
return true;
93+
}
94+
}
95+
96+
return !filter_var($v, FILTER_VALIDATE_IP);
97+
})
98+
->thenInvalid('Invalid proxy IP "%s"')
99+
->end()
72100
->end()
73101
->end()
74102
->scalarNode('ide')->defaultNull()->end()

DependencyInjection/FrameworkExtension.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ public function load(array $configs, ContainerBuilder $container)
155155

156156
$container->setParameter('kernel.http_method_override', $config['http_method_override']);
157157
$container->setParameter('kernel.trusted_hosts', $config['trusted_hosts']);
158+
if ($config['trusted_proxies']) {
159+
$container->setParameter('kernel.trusted_proxies', $config['trusted_proxies']);
160+
}
158161
$container->setParameter('kernel.default_locale', $config['default_locale']);
159162

160163
if (!$container->hasParameter('debug.file_link_format')) {

Resources/config/form_debug.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
<service id="data_collector.form" class="Symfony\Component\Form\Extension\DataCollector\FormDataCollector" public="true">
2727
<tag name="data_collector" template="@WebProfiler/Collector/form.html.twig" id="form" priority="310" />
2828
<argument type="service" id="data_collector.form.extractor" />
29-
<argument>false</argument>
3029
</service>
3130
</services>
3231
</container>

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,103 @@ public function testDoNoDuplicateDefaultFormResources()
4343
$this->assertEquals(array('FrameworkBundle:Form'), $config['templating']['form']['resources']);
4444
}
4545

46+
/**
47+
* @group legacy
48+
* @expectedDeprecation The "framework.trusted_proxies" configuration key has been deprecated in Symfony 3.3. Use the Request::setTrustedProxies() method in your front controller instead.
49+
*/
50+
public function testTrustedProxiesSetToNullIsDeprecated()
51+
{
52+
$processor = new Processor();
53+
$configuration = new Configuration(true);
54+
$processor->processConfiguration($configuration, array(array('trusted_proxies' => null)));
55+
}
56+
57+
/**
58+
* @group legacy
59+
* @expectedDeprecation The "framework.trusted_proxies" configuration key has been deprecated in Symfony 3.3. Use the Request::setTrustedProxies() method in your front controller instead.
60+
*/
61+
public function testTrustedProxiesSetToEmptyArrayIsDeprecated()
62+
{
63+
$processor = new Processor();
64+
$configuration = new Configuration(true);
65+
$processor->processConfiguration($configuration, array(array('trusted_proxies' => array())));
66+
}
67+
68+
/**
69+
* @group legacy
70+
* @expectedDeprecation The "framework.trusted_proxies" configuration key has been deprecated in Symfony 3.3. Use the Request::setTrustedProxies() method in your front controller instead.
71+
*/
72+
public function testTrustedProxiesSetToNonEmptyArrayIsInvalid()
73+
{
74+
$processor = new Processor();
75+
$configuration = new Configuration(true);
76+
$processor->processConfiguration($configuration, array(array('trusted_proxies' => array('127.0.0.1'))));
77+
}
78+
79+
/**
80+
* @group legacy
81+
* @dataProvider getTestValidTrustedProxiesData
82+
*/
83+
public function testValidTrustedProxies($trustedProxies, $processedProxies)
84+
{
85+
$processor = new Processor();
86+
$configuration = new Configuration(true);
87+
$config = $processor->processConfiguration($configuration, array(array(
88+
'secret' => 's3cr3t',
89+
'trusted_proxies' => $trustedProxies,
90+
)));
91+
92+
$this->assertEquals($processedProxies, $config['trusted_proxies']);
93+
}
94+
95+
public function getTestValidTrustedProxiesData()
96+
{
97+
return array(
98+
array(array('127.0.0.1'), array('127.0.0.1')),
99+
array(array('::1'), array('::1')),
100+
array(array('127.0.0.1', '::1'), array('127.0.0.1', '::1')),
101+
array(null, array()),
102+
array(false, array()),
103+
array(array(), array()),
104+
array(array('10.0.0.0/8'), array('10.0.0.0/8')),
105+
array(array('::ffff:0:0/96'), array('::ffff:0:0/96')),
106+
array(array('0.0.0.0/0'), array('0.0.0.0/0')),
107+
);
108+
}
109+
110+
/**
111+
* @group legacy
112+
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
113+
*/
114+
public function testInvalidTypeTrustedProxies()
115+
{
116+
$processor = new Processor();
117+
$configuration = new Configuration(true);
118+
$processor->processConfiguration($configuration, array(
119+
array(
120+
'secret' => 's3cr3t',
121+
'trusted_proxies' => 'Not an IP address',
122+
),
123+
));
124+
}
125+
126+
/**
127+
* @group legacy
128+
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
129+
*/
130+
public function testInvalidValueTrustedProxies()
131+
{
132+
$processor = new Processor();
133+
$configuration = new Configuration(true);
134+
135+
$processor->processConfiguration($configuration, array(
136+
array(
137+
'secret' => 's3cr3t',
138+
'trusted_proxies' => array('Not an IP address'),
139+
),
140+
));
141+
}
142+
46143
public function testAssetsCanBeEnabled()
47144
{
48145
$processor = new Processor();
@@ -124,6 +221,7 @@ protected static function getBundleDefaultConfig()
124221
{
125222
return array(
126223
'http_method_override' => true,
224+
'trusted_proxies' => array(),
127225
'ide' => null,
128226
'default_locale' => 'en',
129227
'csrf_protection' => array(

0 commit comments

Comments
 (0)