8000 Merge branch '3.4' into 4.0 · mssimi/symfony@2871a96 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2871a96

Browse files
Merge branch '3.4' into 4.0
* 3.4: [Bridge/Twig] fix composer.json bug symfony#26086 [FrameworkBundle] Fix using annotation_reader in compiler pass to inject configured cache provider [WebProfilerBundle] Fix anchor CSS [HttpKernel] Send new session cookie from AbstractTestSessionListener after session invalidation [WebProfilerBundle] Tweak default route name updated StopwatchEvent phpdoc due to the additional of optional float precision introduced in 0db8d7f Retro-fit proxy code to make it deterministic for older proxy manager implementations Yaml parser regression with comments and non-strings Fix undiscoverablility of SymfonyTestsListenerForV7 Fixed broken tests [TwigBridge] Apply some changes to support Bootstrap4-stable
2 parents 838fefa + b9c0710 commit 2871a96

File tree

20 files changed

+430
-347
lines changed

20 files changed

+430
-347
lines changed

src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerForV7.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Bridge\PhpUnit;
12+
namespace Symfony\Bridge\PhpUnit\Legacy;
1313

1414
use PHPUnit\Framework\Test;
1515
use PHPUnit\Framework\TestListener;

src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php

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

1414
use ProxyManager\Generator\ClassGenerator;
1515
use ProxyManager\GeneratorStrategy\BaseGeneratorStrategy;
16+
use ProxyManager\Version;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718
use Symfony\Component\DependencyInjection\Definition;
1819
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface;
@@ -88,32 +89,53 @@ public function getProxyFactoryCode(Definition $definition, $id, $factoryCode =
8889
*/
8990
public function getProxyCode(Definition $definition)
9091
{
91-
return preg_replace(
92+
$code = $this->classGenerator->generate($this->generateProxyClass($definition));
93+
94+
$code = preg_replace(
9295
'/(\$this->initializer[0-9a-f]++) && \1->__invoke\(\$this->(valueHolder[0-9a-f]++), (.*?), \1\);/',
9396
'$1 && ($1->__invoke(\$$2, $3, $1) || 1) && $this->$2 = \$$2;',
94-
$this->classGenerator->generate($this->generateProxyClass($definition))
97+
$code
9598
);
99+
100+
if (version_compare(self::getProxyManagerVersion(), '2.2', '<')) {
101+
$code = preg_replace(
102+
'/((?:\$(?:this|initializer|instance)->)?(?:publicProperties|initializer|valueHolder))[0-9a-f]++/',
103+
'${1}'.$this->getIdentifierSuffix($definition),
104+
$code
105+
);
106+
}
107+
108+
return $code;
109+
}
110+
111+
private static function getProxyManagerVersion(): string
112+
{
113+
if (!\class_exists(Version::class)) {
114+
return '0.0.1';
115+
}
116+
117+
return defined(Version::class.'::VERSION') ? Version::VERSION : Version::getVersion();
96118
}
97119

98120
/**
99121
* Produces the proxy class name for the given definition.
100-
*
101-
* @return string
102122
*/
103-
private function getProxyClassName(Definition $definition)
123+
private function getProxyClassName(Definition $definition): string
104124
{
105-
return preg_replace('/^.*\\\\/', '', $definition->getClass()).'_'.substr(hash('sha256', $definition->getClass().$this->salt), -7);
125+
return preg_replace('/^.*\\\\/', '', $definition->getClass()).'_'.$this->getIdentifierSuffix($definition);
106126
}
107127

108-
/**
109-
* @return ClassGenerator
110-
*/
111-
private function generateProxyClass(Definition $definition)
128+
private function generateProxyClass(Definition $definition): ClassGenerator
112129
{
113130
$generatedClass = new ClassGenerator($this->getProxyClassName($definition));
114131

115132
$this->proxyGenerator->generate(new \ReflectionClass($definition->getClass()), $generatedClass);
116133

117134
return $generatedClass;
118135
}
136+
137+
private function getIdentifierSuffix(Definition $definition): string
138+
{
139+
return substr(hash('sha256', $definition->getClass().$this->salt), -7);
140+
}
119141
}

src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ public function testGetProxyCode()
5858
);
5959
}
6060

61+
public function testDeterministicProxyCode()
62+
{
63+
$definition = new Definition(__CLASS__);
64+
$definition->setLazy(true);
65+
66+
$this->assertSame($this->dumper->getProxyCode($definition), $this->dumper->getProxyCode($definition));
67+
}
68< F438 /code>+
6169
public function testGetProxyFactoryCode()
6270
{
6371
$definition = new Definition(__CLASS__);

src/Symfony/Bridge/Twig/Extension/CodeExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,6 @@ protected static function fixCodeMarkup($line)
259259
$line .= '</span>';
260260
}
261261

262-
return $line;
262+
return trim($line);
263263
}
264264
}

src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig

Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,25 @@
33
{# Widgets #}
44

55
{% block money_widget -%}
6-
{% if not valid %}
7-
{% set group_class = ' form-control is-invalid' %}
8-
{% set valid = true %}
9-
{% endif %}
10-
{{- parent() -}}
6+
{%- set prepend = not (money_pattern starts with '{{') -%}
7+
{%- set append = not (money_pattern ends with '}}') -%}
8+
{%- if prepend or append -%}
9+
<div class="input-group{{ group_class|default('') }}">
10+
{%- if prepend -%}
11+
<div class="input-group-prepend">
12+
<span class="input-group-text">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
13+
</div>
14+
{%- endif -%}
15+
{{- block('form_widget_simple') -}}
16+
{%- if append -%}
17+
<div class="input-group-append">
18+
<span class="input-group-text">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span>
19+
</div>
20+
{%- endif -%}
21+
</div>
22+
{%- else -%}
23+
{{- block('form_widget_simple') -}}
24+
{%- endif -%}
1125
{%- endblock money_widget %}
1226

1327
{% block datetime_widget -%}
@@ -39,7 +53,6 @@
3953
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-control is-invalid')|trim}) -%}
4054
{% set valid = true %}
4155
{%- endif -%}
42-
4356
{%- if widget == 'single_text' -%}
4457
{{- block('form_widget_simple') -}}
4558
{%- else -%}
@@ -80,7 +93,9 @@
8093
<div class="input-group{{ not valid ? ' form-control is-invalid' }}">
8194
{% set valid = true %}
8295
{{- block('form_widget_simple') -}}
83-
<span class="input-group-addon">%</span>
96+
<div class="input-group-append">
97+
<span class="input-group-text">%</span>
98+
</div>
8499
</div>
85100
{%- endblock percent_widget %}
86101

@@ -93,7 +108,7 @@
93108

94109
{%- block widget_attributes -%}
95110
{%- if not valid %}
96-
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-control is-invalid')|trim}) %}
111+
{% set attr = attr|merge({class: (attr.class|default('') ~ ' is-invalid')|trim}) %}
97112
{% endif -%}
98113
{{ parent() }}
99114
{%- endblock widget_attributes -%}
@@ -105,55 +120,44 @@
105120

106121
{% block checkbox_widget -%}
107122
{%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%}
108-
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-check-input')|trim}) -%}
109-
{% if 'checkbox-inline' in parent_label_class %}
110-
{{- form_label(form, null, { widget: parent() }) -}}
111-
{% elseif 'form-check-inline' in parent_label_class %}
112-
<div class="form-check{{ not valid ? ' form-control is-invalid' }} form-check-inline">
123+
{%- if 'checkbox-custom' in parent_label_class -%}
124+
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' custom-control-input')|trim}) -%}
125+
<div class="custom-control custom-checkbox{{ 'checkbox-inline' in parent_label_class ? ' custom-control-inline' }}">
113126
{{- form_label(form, null, { widget: parent() }) -}}
114127
</div>
115-
{% else -%}
116-
<div class="form-check{{ not valid ? ' form-control is-invalid' }}">
128+
{%- else -%}
129+
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-check-input')|trim}) -%}
130+
<div class="form-check{{ 'checkbox-inline' in parent_label_class ? ' form-check-inline' }}">
117131
{{- form_label(form, null, { widget: parent() }) -}}
118132
</div>
119133
{%- endif -%}
120134
{%- endblock checkbox_widget %}
121135

122136
{% block radio_widget -%}
123137
{%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%}
124-
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-check-input')|trim}) -%}
125-
{%- if 'radio-inline' in parent_label_class -%}
126-
{{- form_label(form, null, { widget: parent() }) -}}
138+
{%- if 'radio-custom' in parent_label_class -%}
139+
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' custom-control-input')|trim}) -%}
140+
<div class="custom-control custom-radio{{ 'radio-inline' in parent_label_class ? ' custom-control-inline' }}">
141+
{{- form_label(form, null, { widget: parent() }) -}}
142+
</div>
127143
{%- else -%}
128-
<div class="form-check{{ not valid ? ' form-control is-invalid' }}">
144+
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-check-input')|trim}) -%}
145+
<div class="form-check{{ 'radio-inline' in parent_label_class ? ' form-check-inline' }}">
129146
{{- form_label(form, null, { widget: parent() }) -}}
130147
</div>
131148
{%- endif -%}
132149
{%- endblock radio_widget %}
133150

134151
{% block choice_widget_expanded -%}
135-
{% if '-inline' in label_attr.class|default('') -%}
152+
<div {{ block('widget_container_attributes') }}>
136153
{%- for child in form %}
137154
{{- form_widget(child, {
138155
parent_label_class: label_attr.class|default(''),
139156
translation_domain: choice_translation_domain,
140157
valid: valid,
141158
}) -}}
142159
{% endfor -%}
143-
{%- else -%}
144-
{%- if not valid -%}
145-
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-control is-invalid')|trim}) %}
146-
{%- endif -%}
147-
<div {{ block('widget_container_attributes') }}>
148-
{%- for child in form %}
149-
{{- form_widget(child, {
150-
parent_label_class: label_attr.class|default(''),
151-
translation_domain: choice_translation_domain,
152-
valid: true,
153-
}) -}}
154-
{% endfor -%}
155-
</div>
156-
{%- endif %}
160+
</div>
157161
{%- endblock choice_widget_expanded %}
158162

159163
{# Labels #}
@@ -162,7 +166,7 @@
162166
{% if label is not same as(false) -%}
163167
{%- if compound is defined and compound -%}
164168
{%- set element = 'legend' -%}
165-
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' col-form-legend')|trim}) -%}
169+
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' col-form-label')|trim}) -%}
166170
{%- else -%}
167171
{%- set label_attr = label_attr|merge({for: id, class: (label_attr.class|default('') ~ ' form-control-label')|trim}) -%}
168172
{%- endif -%}
@@ -179,19 +183,26 @@
179183
{% set label = name|humanize %}
180184
{%- endif -%}
181185
{%- endif -%}
182-
<{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}{% block form_label_errors %}{{- form_errors(form) -}}{% endblock form_label_errors %}</{{ element|default('label') }}>
186+
<{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}{{- form_errors(form) -}}</{{ element|default('label') }}>
183187
{%- endif -%}
184188
{%- endblock form_label %}
185189

186190
{% block checkbox_radio_label -%}
187191
{#- Do not display the label if widget is not defined in order to prevent double label rendering -#}
188192
{%- if widget is defined -%}
189-
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' form-check-label')|trim}) -%}
193+
{%- if parent_label_class is defined and ('checkbox-custom' in parent_label_class or 'radio-custom' in parent_label_class) -%}
194+
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' custom-control-label')|trim}) -%}
195+
{%- else %}
196+
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' form-check-label')|trim}) -%}
197+
{%- endif %}
198+
{%- if not compound -%}
199+
{% set label_attr = label_attr|merge({'for': id}) %}
200+
{%- endif -%}
190201
{%- if required -%}
191202
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) -%}
192203
{%- endif -%}
193204
{%- if parent_label_class is defined -%}
194-
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ parent_label_class)|trim}) -%}
205+
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ parent_label_class)|replace({'checkbox-inline': '', 'radio-inline': '', 'checkbox-custom': '', 'radio-custom': ''})|trim}) -%}
195206
{%- endif -%}
196207
{%- if label is not same as(false) and label is empty -%}
197208
{%- if label_format is not empty -%}
@@ -203,8 +214,11 @@
203214
{%- set label = name|humanize -%}
204215
{%- endif -%}
205216
{%- endif -%}
217+
218+
{{ widget|raw }}
206219
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
207-
{{- widget|raw }} {{ label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans({}, translation_domain)) -}}
220+
{{- label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans({}, translation_domain)) -}}
221+
{{- form_errors(form) -}}
208222
</label>
209223
{%- endif -%}
210224
{%- endblock checkbox_radio_label %}
@@ -225,12 +239,12 @@
225239

226240
{% block form_errors -%}
227241
{%- if errors|length > 0 -%}
228-
<div class="{% if form is not rootform %}invalid-feedback{% else %}alert alert-danger{% endif %}">
229-
<ul class="list-unstyled mb-0">
230-
{%- for error in errors -%}
231-
<li>{{ error.message }}</li>
232-
{%- endfor -%}
233-
</ul>
234-
</div>
242+
<div class="{% if form is not rootform %}invalid-feedback d-block{% else %}alert alert-danger{% endif %}">
243+
<ul class="list-unstyled mb-0">
244+
{%- for error in errors -%}
245+
<li>{{ error.message }}</li>
246+
{%- endfor -%}
247+
</ul>
248+
</div>
235249
{%- endif %}
236250
{%- endblock form_errors %}

src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_base_layout.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147

148148
{% block choice_label -%}
149149
{# remove the checkbox-inline and radio-inline class, it's only useful for embed labels #}
150-
{%- set label_attr = label_attr|merge({class: label_attr.class|default('')|replace({'checkbox-inline': '', 'radio-inline': ''})|trim}) -%}
150+
{%- set label_attr = label_attr|merge({class: label_attr.class|default('')|replace({'checkbox-inline': '', 'radio-inline': '', 'checkbox-custom': '', 'radio-custom': ''})|trim}) -%}
151151
{{- block('form_label') -}}
152152
{% endblock choice_label %}
153153

src/Symfony/Bridge/Twig/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"symfony/asset": "~3.4|~4.0",
2424
"symfony/dependency-injection": "~3.4|~4.0",
2525
"symfony/finder": "~3.4|~4.0",
26-
"symfony/form": "~3.4|~4.0",
26+
"symfony/form": "^3.4.5|^4.0.5",
2727
"symfony/http-foundation": "~3.4|~4.0",
2828
"symfony/http-kernel": "~3.4|~4.0",
2929
"symfony/polyfill-intl-icu": "~1.0",
@@ -41,7 +41,7 @@
4141
"symfony/workflow": "~3.4|~4.0"
4242
},
4343
"conflict": {
44-
"symfony/form": "<3.4",
44+
"symfony/form": "<3.4.5|<4.0.5,>=4.0",
4545
"symfony/console": "<3.4"
4646
},
4747
"suggest": {

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddAnnotationsCachedReaderPass.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ public function process(ContainerBuilder $container)
2626
{
2727
// "annotations.cached_reader" is wired late so that any passes using
2828
// "annotation_reader" at build time don't get any cache
29-
if ($container->hasDefinition('annotations.cached_reader')) {
30-
$reader = $container->getDefinition('annotations.cached_reader');
29+
foreach ($container->findTaggedServiceIds('annotations.cached_reader') as $id => $tags) {
30+
$reader = $container->getDefinition($id);
3131
$properties = $reader->getProperties();
3232

3333
if (isset($properties['cacheProviderBackup'])) {
3434
$provider = $properties['cacheProviderBackup']->getValues()[0];
3535
unset($properties['cacheProviderBackup']);
3636
$reader->setProperties($properties);
37-
$container->set('annotations.cached_reader', null);
38-
$container->setDefinition('annotations.cached_reader', $reader->replaceArgument(1, $provider));
37+
$container->set($id, null);
38+
$container->setDefinition($id, $reader->replaceArgument(1, $provider));
3939
}
4040
}
4141
}

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
class UnusedTagsPass implements CompilerPassInterface
2323
{
2424
private $whitelist = array(
25+
'annotations.cached_reader',
2526
'cache.pool.clearer',
2627
'console.command',
2728
'container.hot_path',

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,9 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
11161116
->replaceArgument(2, $config['debug'])
11171117
// temporary property to lazy-reference the cache provider without using it until AddAnnotationsCachedReaderPass runs
11181118
->setProperty('cacheProviderBackup', new ServiceClosureArgument(new Reference($cacheService)))
1119+
->addTag('annotations.cached_reader')
11191120
;
1121+
11201122
$container->setAlias('annotation_reader', 'annotations.cached_reader')->setPrivate(true);
11211123
$container->setAlias(Reader::class, new Alias('annotations.cached_reader', false));
11221124
} else {

0 commit comments

Comments
 (0)
0