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

Skip to content

Commit 594925a

Browse files
Merge branch '3.4' into 4.0
* 3.4: [HttpKernel] Make ServiceValueResolver work if controller namespace starts with a backslash in routing Add d-block to bootstrap 4 alerts [Console] Don't go past exact matches when autocompleting [DI] Improve error message for non-autowirable scalar argument Disable autoloader call on interface_exists check [Validator] Fix LazyLoadingMetadataFactory with PSR6Cache for non classname if tested values isn't an existing class [HttpKernel] Dont create mock cookie for new sessions in tests
2 parents 2bec0e1 + 0a02fb1 commit 594925a

File tree

15 files changed

+110
-18
lines changed

15 files changed

+110
-18
lines changed

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

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

268268
{% block form_errors -%}
269269
{%- if errors|length > 0 -%}
270-
<span class="{% if form is not rootform %}invalid-feedback d-block{% else %}alert alert-danger{% endif %}">
270+
<span class="{% if form is not rootform %}invalid-feedback{% else %}alert alert-danger{% endif %} d-block">
271271
{%- for error in errors -%}
272272
<span class="mb-0 d-block">
273273
<span class="initialism form-error-icon badge badge-danger">{{ 'Error'|trans({}, 'validators') }}</span> <span class="form-error-message">{{ error.message }}</span>

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.7|^4.0.7",
26+
"symfony/form": "^3.4.9|^4.0.9",
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.7|<4.0.7,>=4.0",
44+
"symfony/form": "<3.4.9|<4.0.9,>=4.0",
4545
"symfony/console": "<3.4"
4646
},
4747
"suggest": {

src/Symfony/Component/Console/Helper/QuestionHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ private function autocomplete(OutputInterface $output, Question $question, $inpu
261261

262262
foreach ($autocomplete as $value) {
263263
// If typed characters match the beginning chunk of value (e.g. [AcmeDe]moBundle)
264-
if (0 === strpos($value, $ret) && $i !== strlen($value)) {
264+
if (0 === strpos($value, $ret)) {
265265
$matches[$numMatches++] = $value;
266266
}
267267
}

src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,29 @@ public function testAskWithAutocompleteWithNonSequentialKeys()
157157
$this->assertEquals('AsseticBundle', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
158158
}
159159

160+
public function testAskWithAutocompleteWithExactMatch()
161+
{
162+
if (!$this->hasSttyAvailable()) {
163+
$this->markTestSkipped('`stty` is required to test autocomplete functionality');
164+
}
165+
166+
$inputStream = $this->getInputStream("b\n");
167+
168+
$possibleChoices = array(
169+
'a' => 'berlin',
170+
'b' => 'copenhagen',
171+
'c' => 'amsterdam',
172+
);
173+
174+
$dialog = new QuestionHelper();
175+
$dialog->setHelperSet(new HelperSet(array(new FormatterHelper())));
176+
177+
$question = new ChoiceQuestion('Please select a city', $possibleChoices);
178+
$question->setMaxAttempts(1);
179+
180+
$this->assertSame('b', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
181+
}
182+
160183
public function testAutocompleteWithTrailingBackslash()
161184
{
162185
if (!$this->hasSttyAvailable()) {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,10 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
179179
if ($parameter->isOptional()) {
180180
continue;
181181
}
182-
throw new AutowiringFailedException($this->currentId, sprintf('Cannot autowire service "%s": argument "$%s" of method "%s()" must have a type-hint or be given a value explicitly.', $this->currentId, $parameter->name, $class !== $this->currentId ? $class.'::'.$method : $method));
182+
$type = ProxyHelper::getTypeHint($reflectionMethod, $parameter, false);
183+
$type = $type ? sprintf('is type-hinted "%s"', $type) : 'has no type-hint';
184+
185+
throw new AutowiringFailedException($this->currentId, sprintf('Cannot autowire service "%s": argument "$%s" of method "%s()" %s, you should configure its value explicitly.', $this->currentId, $parameter->name, $class !== $this->currentId ? $class.'::'.$method : $method, $type));
183186
}
184187

185188
// specifically pass the default value

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ public function testSomeSpecificArgumentsAreSet()
373373
// args are: A, Foo, Dunglas
374374
->setArguments(array(
375375
1 => new Reference('foo'),
376+
3 => array('bar'),
376377
));
377378

378379
(new ResolveClassPass())->process($container);
@@ -384,19 +385,38 @@ public function testSomeSpecificArgumentsAreSet()
384385
new TypedReference(A::class, A::class, MultipleArguments::class),
385386
new Reference('foo'),
386387
new TypedReference(Dunglas::class, Dunglas::class, MultipleArguments::class),
388+
array('bar'),
387389
),
388390
$definition->getArguments()
389391
);
390392
}
391393

392394
/**
393395
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
394-
* @expectedExceptionMessage Cannot autowire service "arg_no_type_hint": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\MultipleArguments::__construct()" must have a type-hint or be given a value explicitly.
396+
* @expectedExceptionMessage Cannot autowire service "arg_no_type_hint": argument "$bar" of method "Symfony\Component\DependencyInjection\Tests\Compiler\MultipleArguments::__construct()" is type-hinted "array", you should configure its value explicitly.
395397
*/
396398
public function testScalarArgsCannotBeAutowired()
397399
{
398400
$container = new ContainerBuilder();
399401

402+
$container->register(A::class);
403+
$container->register(Dunglas::class);
404+
$container->register('arg_no_type_hint', __NAMESPACE__.'\MultipleArguments')
405+
->setArguments(array(1 => 'foo'))
406+
->setAutowired(true);
407+
408+
(new ResolveClassPass())->process($container);
409+
(new AutowirePass())->process($container);
410+
}
411+
412+
/**
413+
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
414+
* @expectedExceptionMessage Cannot autowire service "arg_no_type_hint": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\MultipleArguments::__construct()" has no type-hint, you should configure its value explicitly.
415+
*/
416+
public function testNoTypeArgsCannotBeAutowired()
417+
{
418+
$container = new ContainerBuilder();
419+
400420
$container->register(A::class);
401421
$container->register(Dunglas::class);
402422
$container->register('arg_no_type_hint', __NAMESPACE__.'\MultipleArguments')

src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/autowiring_classes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function __construct(A $k)
181181
}
182182
class MultipleArguments
183183
{
184-
public function __construct(A $k, $foo, Dunglas $dunglas)
184+
public function __construct(A $k, $foo, Dunglas $dunglas, array $bar)
185185
{
186186
}
187187
}

src/Symfony/Component/Form/Tests/AbstractBootstrap4HorizontalLayoutTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testRow()
3232
[
3333
./label[@for="name"]
3434
[
35-
./span[@class="alert alert-danger"]
35+
./span[@class="alert alert-danger d-block"]
3636
[./span[@class="mb-0 d-block"]
3737
[./span[.="[trans]Error[/trans]"]]
3838
[./span[.="[trans]Error![/trans]"]]

src/Symfony/Component/Form/Tests/AbstractBootstrap4LayoutTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testRow()
3232
[
3333
./label[@for="name"]
3434
[
35-
./span[@class="alert alert-danger"]
35+
./span[@class="alert alert-danger d-block"]
3636
[./span[@class="mb-0 d-block"]
3737
[./span[.="[trans]Error[/trans]"]]
3838
[./span[.="[trans]Error![/trans]"]]
@@ -161,7 +161,7 @@ public function testErrors()
161161

162162
$this->assertMatchesXpath($html,
163163
'/span
164-
[@class="alert alert-danger"]
164+
[@class="alert alert-danger d-block"]
165165
[
166166
./span[@class="mb-0 d-block"]
167167
[./span[.="[trans]Error[/trans]"]]

src/Symfony/Component/HttpKernel/Controller/ArgumentResolver/ServiceValueResolver.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,15 @@ public function supports(Request $request, ArgumentMetadata $argument)
3939

4040
if (\is_array($controller) && \is_callable($controller, true) && \is_string($controller[0])) {
4141
$controller = $controller[0].'::'.$controller[1];
42+
} elseif (!\is_string($controller) || '' === $controller) {
43+
return false;
4244
}
4345

44-
return \is_string($controller) && $this->container->has($controller) && $this->container->get($controller)->has($argument->getName());
46+
if ('\\' === $controller[0]) {
47+
$controller = ltrim($controller, '\\');
48+
}
49+
50+
return $this->container->has($controller) && $this->container->get($controller)->has($argument->getName());
4551
}
4652

4753
/**
@@ -53,6 +59,10 @@ public function resolve(Request $request, ArgumentMetadata $argument)
5359
$controller = $controller[0].'::'.$controller[1];
5460
}
5561

62+
if ('\\' === $controller[0]) {
63+
$controller = ltrim($controller, '\\');
64+
}
65+
5666
yield $this->container->get($controller)->get($argument->getName());
5767
}
5868
}

0 commit comments

Comments
 (0)
0