Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitf7f23b9

Browse files
committed
Centralize input stream in base Input class
Add StreamableInputInterface
1 parent4256b68 commitf7f23b9

File tree

7 files changed

+135
-55
lines changed

7 files changed

+135
-55
lines changed

‎src/Symfony/Component/Console/Application.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,8 +769,8 @@ protected function configureIO(InputInterface $input, OutputInterface $output)
769769

770770
if (true ===$input->hasParameterOption(array('--no-interaction','-n'),true)) {
771771
$input->setInteractive(false);
772-
}elseif (function_exists('posix_isatty') &&$this->getHelperSet()->has('question')) {
773-
$inputStream =$this->getHelperSet()->get('question')->getInputStream();
772+
}elseif (function_exists('posix_isatty')) {
773+
$inputStream =$input->getStream();
774774
if (!@posix_isatty($inputStream) &&false ===getenv('SHELL_INTERACTIVE')) {
775775
$input->setInteractive(false);
776776
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public function ask(InputInterface $input, OutputInterface $output, Question $qu
5252
return$question->getDefault();
5353
}
5454

55+
if ($stream =$input->getStream()) {
56+
$this->inputStream =$stream;
57+
}
58+
5559
if (!$question->getValidator()) {
5660
return$this->doAsk($output,$question);
5761
}
@@ -74,6 +78,8 @@ public function ask(InputInterface $input, OutputInterface $output, Question $qu
7478
*/
7579
publicfunctionsetInputStream($stream)
7680
{
81+
@trigger_error(sprintf('The setInputStream() method is deprecated since version 3.1 and will be removed in 4.0. Use %s:setStream() instead.', InputInterface::class),E_USER_DEPRECATED);
82+
7783
if (!is_resource($stream)) {
7884
thrownewInvalidArgumentException('Input stream must be a valid resource.');
7985
}
@@ -88,6 +94,8 @@ public function setInputStream($stream)
8894
*/
8995
publicfunctiongetInputStream()
9096
{
97+
@trigger_error(sprintf('The getInputStream() method is deprecated since version 3.1 and will be removed in 4.0. Use %s:getStream() instead.', InputInterface::class),E_USER_DEPRECATED);
98+
9199
return$this->inputStream;
92100
}
93101

‎src/Symfony/Component/Console/Input/Input.php‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525
*
2626
* @author Fabien Potencier <fabien@symfony.com>
2727
*/
28-
abstractclass Inputimplements InputInterface
28+
abstractclass Inputimplements InputInterface, StreamableInputInterface
2929
{
3030
/**
3131
* @var InputDefinition
3232
*/
3333
protected$definition;
34+
protected$stream;
3435
protected$options =array();
3536
protected$arguments =array();
3637
protected$interactive =true;
@@ -233,4 +234,20 @@ public function escapeToken($token)
233234
{
234235
returnpreg_match('{^[\w-]+$}',$token) ?$token :escapeshellarg($token);
235236
}
237+
238+
/**
239+
* {@inheritdoc}
240+
*/
241+
publicfunctionsetStream($stream)
242+
{
243+
$this->stream =$stream;
244+
}
245+
246+
/**
247+
* {@inheritdoc}
248+
*/
249+
publicfunctiongetStream()
250+
{
251+
return$this->stream;
252+
}
236253
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
namespaceSymfony\Component\Console\Input;
13+
14+
/**
15+
* StreamableInputInterface is the interface implemented by all input classes
16+
* that have an input stream.
17+
*
18+
* @author Robin Chalas <robin.chalas@gmail.com>
19+
*/
20+
interface StreamableInputInterfaceextends InputInterface
21+
{
22+
/**
23+
* Sets the input stream to read from when interacting with the user.
24+
*
25+
* This is mainly useful for testing purpose.
26+
*
27+
* @param resource $stream The input stream
28+
*/
29+
publicfunctionsetStream($stream);
30+
31+
/**
32+
* Returns the input stream.
33+
*
34+
* @return resource|null
35+
*/
36+
publicfunctiongetStream();
37+
}

‎src/Symfony/Component/Console/Tests/ApplicationTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ public function testCanCheckIfTerminalIsInteractive()
10991099

11001100
$this->assertFalse($tester->getInput()->hasParameterOption(array('--no-interaction','-n')));
11011101

1102-
$inputStream =$application->getHelperSet()->get('question')->getInputStream();
1102+
$inputStream =$tester->getInput()->getStream();
11031103
$this->assertEquals($tester->getInput()->isInteractive(), @posix_isatty($inputStream));
11041104
}
11051105
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp