Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit eda7aad

Browse filesBrowse files
committed
Merge branch '5.0'
* 5.0: [FrameworkBundle] start session on flashbag injection [Validator] Remove commas in translations [Console] Fallback to default answers when unable to read input
2 parents b4f03d0 + af72aa1 commit eda7aad
Copy full SHA for eda7aad

File tree

Expand file treeCollapse file tree

11 files changed

+154
-43
lines changed
Filter options
Expand file treeCollapse file tree

11 files changed

+154
-43
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
<service id="session" class="Symfony\Component\HttpFoundation\Session\Session" public="true">
1515
<argument type="service" id="session.storage" />
16-
<argument type="service" id="session.attribute_bag" />
17-
<argument type="service" id="session.flash_bag" />
1816
</service>
1917

2018
<service id="Symfony\Component\HttpFoundation\Session\SessionInterface" alias="session" />
@@ -37,10 +35,14 @@
3735
<argument type="service" id="session.storage.metadata_bag" />
3836
</service>
3937

40-
<service id="session.flash_bag" class="Symfony\Component\HttpFoundation\Session\Flash\FlashBag" />
38+
<service id="session.flash_bag" class="Symfony\Component\HttpFoundation\Session\Flash\FlashBag">
39+
<factory service="session" method="getFlashBag"/>
40+
</service>
4141
<service id="Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface" alias="session.flash_bag" />
4242

43-
<service id="session.attribute_bag" class="Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag" />
43+
<service id="session.attribute_bag" class="Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag">
44+
<factory service="session" method="getAttributeBag"/>
45+
</service>
4446

4547
<service id="session.storage.mock_file" class="Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage">
4648
<argument>%kernel.cache_dir%/sessions</argument>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller;
4+
5+
use Symfony\Component\HttpFoundation\RedirectResponse;
6+
use Symfony\Component\HttpFoundation\Request;
7+
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
8+
use Symfony\Component\Routing\RouterInterface;
9+
10+
class InjectedFlashbagSessionController
11+
{
12+
/**
13+
* @var FlashBagInterface
14+
*/
15+
private $flashBag;
16+
17+
/**
18+
* @var RouterInterface
19+
*/
20+
private $router;
21+
22+
public function __construct(
23+
FlashBagInterface $flashBag,
24+
RouterInterface $router
25+
) {
26+
$this->flashBag = $flashBag;
27+
$this->router = $router;
28+
}
29+
30+
public function setFlashAction(Request $request, $message)
31+
{
32+
$this->flashBag->add('notice', $message);
33+
34+
return new RedirectResponse($this->router->generate('session_showflash'));
35+
}
36+
}

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Resources/config/routing.yml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Resources/config/routing.yml
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ session_setflash:
1818
path: /session_setflash/{message}
1919
defaults: { _controller: Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\SessionController::setFlashAction }
2020

21+
injected_flashbag_session_setflash:
22+
path: injected_flashbag/session_setflash/{message}
23+
defaults: { _controller: TestBundle:InjectedFlashbagSession:setFlash}
24+
2125
session_showflash:
2226
path: /session_showflash
2327
defaults: { _controller: Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\SessionController::showFlashAction }

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,29 @@ public function testFlash($config, $insulate)
6969
$this->assertStringContainsString('No flash was set.', $crawler->text());
7070
}
7171

72+
/**
73+
* Tests flash messages work when flashbag service is injected to the constructor.
74+
*
75+
* @dataProvider getConfigs
76+
*/
77+
public function testFlashOnInjectedFlashbag($config, $insulate)
78+
{
79+
$client = $this->createClient(['test_case' => 'Session', 'root_config' => $config]);
80+
if ($insulate) {
81+
$client->insulate();
82+
}
83+
84+
// set flash
85+
$client->request('GET', '/injected_flashbag/session_setflash/Hello%20world.');
86+
87+
// check flash displays on redirect
88+
$this->assertStringContainsString('Hello world.', $client->followRedirect()->text());
89+
90+
// check flash is gone
91+
$crawler = $client->request('GET', '/session_showflash');
92+
$this->assertStringContainsString('No flash was set.', $crawler->text());
93+
}
94+
7295
/**
7396
* See if two separate insulated clients can run without
7497
* polluting each other's session data.

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Session/config.yml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Session/config.yml
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ services:
55
Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\SubRequestController:
66
tags:
77
- { name: controller.service_arguments, action: indexAction, argument: handler, id: fragment.handler }
8+
9+
Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\InjectedFlashbagSessionController:
10+
autowire: true
11+
tags: ['controller.service_arguments']
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Console\Exception;
13+
14+
/**
15+
* Represents failure to read input from stdin.
16+
*
17+
* @author Gabriel Ostrolucký <gabriel.ostrolucky@gmail.com>
18+
*/
19+
class MissingInputException extends RuntimeException implements ExceptionInterface
20+
{
21+
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Helper/QuestionHelper.php
+52-33Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Console\Helper;
1313

14+
use Symfony\Component\Console\Exception\MissingInputException;
1415
use Symfony\Component\Console\Exception\RuntimeException;
1516
use Symfony\Component\Console\Formatter\OutputFormatter;
1617
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
@@ -49,44 +50,32 @@ public function ask(InputInterface $input, OutputInterface $output, Question $qu
4950
}
5051

5152
if (!$input->isInteractive()) {
52-
$default = $question->getDefault();
53-
54-
if (null === $default) {
55-
return $default;
56-
}
57-
58-
if ($validator = $question->getValidator()) {
59-
return \call_user_func($question->getValidator(), $default);
60-
} elseif ($question instanceof ChoiceQuestion) {
61-
$choices = $question->getChoices();
62-
63-
if (!$question->isMultiselect()) {
64-
return isset($choices[$default]) ? $choices[$default] : $default;
65-
}
66-
67-
$default = explode(',', $default);
68-
foreach ($default as $k => $v) {
69-
$v = $question->isTrimmable() ? trim($v) : $v;
70-
$default[$k] = isset($choices[$v]) ? $choices[$v] : $v;
71-
}
72-
}
73-
74-
return $default;
53+
return $this->getDefaultAnswer($question);
7554
}
7655

7756
if ($input instanceof StreamableInputInterface && $stream = $input->getStream()) {
7857
$this->inputStream = $stream;
7958
}
8059

81-
if (!$question->getValidator()) {
82-
return $this->doAsk($output, $question);
83-
}
60+
try {
61+
if (!$question->getValidator()) {
62+
return $this->doAsk($output, $question);
63+
}
8464

85-
$interviewer = function () use ($output, $question) {
86-
return $this->doAsk($output, $question);
87-
};
65+
$interviewer = function () use ($output, $question) {
66+
return $this->doAsk($output, $question);
67+
};
8868

89-
return $this->validateAttempts($interviewer, $output, $question);
69+
return $this->validateAttempts($interviewer, $output, $question);
70+
} catch (MissingInputException $exception) {
71+
$input->setInteractive(false);
72+
73+
if (null === $fallbackOutput = $this->getDefaultAnswer($question)) {
74+
throw $exception;
75+
}
76+
77+
return $fallbackOutput;
78+
}
9079
}
9180

9281
/**
@@ -135,7 +124,7 @@ private function doAsk(OutputInterface $output, Question $question)
135124
if (false === $ret) {
136125
$ret = fgets($inputStream, 4096);
137126
if (false === $ret) {
138-
throw new RuntimeException('Aborted.');
127+
throw new MissingInputException('Aborted.');
139128
}
140129
if ($question->isTrimmable()) {
141130
$ret = trim($ret);
@@ -159,6 +148,36 @@ private function doAsk(OutputInterface $output, Question $question)
159148
return $ret;
160149
}
161150

151+
/**
152+
* @return mixed
153+
*/
154+
private function getDefaultAnswer(Question $question)
155+
{
156+
$default = $question->getDefault();
157+
158+
if (null === $default) {
159+
return $default;
160+
}
161+
162+
if ($validator = $question->getValidator()) {
163+
return \call_user_func($question->getValidator(), $default);
164+
} elseif ($question instanceof ChoiceQuestion) {
165+
$choices = $question->getChoices();
166+
167+
if (!$question->isMultiselect()) {
168+
return isset($choices[$default]) ? $choices[$default] : $default;
169+
}
170+
171+
$default = explode(',', $default);
172+
foreach ($default as $k => $v) {
173+
$v = $question->isTrimmable() ? trim($v) : $v;
174+
$default[$k] = isset($choices[$v]) ? $choices[$v] : $v;
175+
}
176+
}
177+
178+
return $default;
179+
}
180+
162181
/**
163182
* Outputs the question prompt.
164183
*/
@@ -239,7 +258,7 @@ private function autocomplete(OutputInterface $output, Question $question, $inpu
239258
// as opposed to fgets(), fread() returns an empty string when the stream content is empty, not false.
240259
if (false === $c || ('' === $ret && '' === $c && null === $question->getDefault())) {
241260
shell_exec(sprintf('stty %s', $sttyMode));
242-
throw new RuntimeException('Aborted.');
261+
throw new MissingInputException('Aborted.');
243262
} elseif ("\177" === $c) { // Backspace Character
244263
if (0 === $numMatches && 0 !== $i) {
245264
--$i;
@@ -406,7 +425,7 @@ private function getHiddenResponse(OutputInterface $output, $inputStream, bool $
406425
shell_exec(sprintf('stty %s', $sttyMode));
407426

408427
if (false === $value) {
409-
throw new RuntimeException('Aborted.');
428+
throw new MissingInputException('Aborted.');
410429
}
411430
if ($trimmable) {
412431
$value = trim($value);

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -696,23 +696,23 @@ public function testChoiceOutputFormattingQuestionForUtf8Keys()
696696

697697
public function testAskThrowsExceptionOnMissingInput()
698698
{
699-
$this->expectException('Symfony\Component\Console\Exception\RuntimeException');
699+
$this->expectException('Symfony\Component\Console\Exception\MissingInputException');
700700
$this->expectExceptionMessage('Aborted.');
701701
$dialog = new QuestionHelper();
702702
$dialog->ask($this->createStreamableInputInterfaceMock($this->getInputStream('')), $this->createOutputInterface(), new Question('What\'s your name?'));
703703
}
704704

705705
public function testAskThrowsExceptionOnMissingInputForChoiceQuestion()
706706
{
707-
$this->expectException('Symfony\Component\Console\Exception\RuntimeException');
707+
$this->expectException('Symfony\Component\Console\Exception\MissingInputException');
708708
$this->expectExceptionMessage('Aborted.');
709709
$dialog = new QuestionHelper();
710710
$dialog->ask($this->createStreamableInputInterfaceMock($this->getInputStream('')), $this->createOutputInterface(), new ChoiceQuestion('Choice', ['a', 'b']));
711711
}
712712

713713
public function testAskThrowsExceptionOnMissingInputWithValidator()
714714
{
715-
$this->expectException('Symfony\Component\Console\Exception\RuntimeException');
715+
$this->expectException('Symfony\Component\Console\Exception\MissingInputException');
716716
$this->expectExceptionMessage('Aborted.');
717717
$dialog = new QuestionHelper();
718718

‎src/Symfony/Component/Console/Tests/phpt/uses_stdin_as_interactive_input.phpt

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/phpt/uses_stdin_as_interactive_input.phpt
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ require $vendor.'/vendor/autoload.php';
1818
(new Application())
1919
->register('app')
2020
->setCode(function(InputInterface $input, OutputInterface $output) {
21-
$output->writeln((new QuestionHelper())->ask($input, $output, new Question('Foo?')));
21+
$output->writeln((new QuestionHelper())->ask($input, $output, new Question('Foo?', 'foo')));
22+
$output->writeln((new QuestionHelper())->ask($input, $output, new Question('Bar?', 'bar')));
2223
})
2324
->getApplication()
2425
->setDefaultCommand('app', true)
2526
->run()
2627
;
2728
--EXPECT--
2829
Foo?Hello World
30+
Bar?bar

‎src/Symfony/Component/Validator/Resources/translations/validators.es.xlf

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Resources/translations/validators.es.xlf
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
</trans-unit>
193193
<trans-unit id="51">
194194
<source>No temporary folder was configured in php.ini.</source>
195-
<target>Ninguna carpeta temporal fue configurada en php.ini.</target>
195+
<target>Ninguna carpeta temporal fue configurada en php.ini o la carpeta configurada no existe.</target>
196196
</trans-unit>
197197
<trans-unit id="52">
198198
<source>Cannot write temporary file to disk.</source>

‎src/Symfony/Component/Validator/Resources/translations/validators.pl.xlf

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Resources/translations/validators.pl.xlf
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
</trans-unit>
193193
<trans-unit id="51">
194194
<source>No temporary folder was configured in php.ini.</source>
195-
<target>Nie skonfigurowano folderu tymczasowego w php.ini, lub skonfigurowany folder nie istnieje.</target>
195+
<target>Nie skonfigurowano folderu tymczasowego w php.ini lub skonfigurowany folder nie istnieje.</target>
196196
</trans-unit>
197197
<trans-unit id="52">
198198
<source>Cannot write temporary file to disk.</source>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.