Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a589635

Browse files
committed
deprecated some Console Application methods
1 parent 8f206c8 commit a589635

File tree

6 files changed

+52
-41
lines changed

6 files changed

+52
-41
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ public function renderException(\Exception $e, OutputInterface $output)
625625

626626
$len = $this->stringWidth($title);
627627

628-
$width = $this->getTerminalWidth() ? $this->getTerminalWidth() - 1 : PHP_INT_MAX;
628+
$width = $this->terminal->getWidth() ? $this->terminal->getWidth() - 1 : PHP_INT_MAX;
629629
// HHVM only accepts 32 bits integer in str_split, even when PHP_INT_MAX is a 64 bit integer: https://github.com/facebook/hhvm/issues/1327
630630
if (defined('HHVM_VERSION') && $width > 1 << 31) {
631631
$width = 1 << 31;
@@ -685,34 +685,56 @@ public function renderException(\Exception $e, OutputInterface $output)
685685
}
686686
}
687687

688+
/**
689+
* Returns the current terminal.
690+
*
691+
* @return Terminal
692+
*/
693+
public function getTerminal()
694+
{
695+
return $this->terminal;
696+
}
697+
688698
/**
689699
* Tries to figure out the terminal width in which this application runs.
690700
*
691701
* @return int|null
702+
*
703+
* @deprecated since version 3.2, to be removed in 4.0. Use the getTerminal() method instead.
692704
*/
693705
protected function getTerminalWidth()
694706
{
707+
@trigger_error(sprintf('%s is deprecated as of 3.2 and will be removed in 4.0. Use getTerminal() instead.', __METHOD__, ArgumentResolverInterface::class), E_USER_DEPRECATED);
708+
695709
return $this->terminal->getWidth();
696710
}
697711

698712
/**
699713
* Tries to figure out the terminal height in which this application runs.
700714
*
701715
* @return int|null
716+
*
717+
* @deprecated since version 3.2, to be removed in 4.0. Use the getTerminal() method instead.
702718
*/
703719
protected function getTerminalHeight()
704720
{
721+
@trigger_error(sprintf('%s is deprecated as of 3.2 and will be removed in 4.0. Use getTerminal() instead.', __METHOD__, ArgumentResolverInterface::class), E_USER_DEPRECATED);
722+
705723
return $this->terminal->getHeight();
706724
}
707725

708726
/**
709727
* Tries to figure out the terminal dimensions based on the current environment.
710728
*
711729
* @return array Array containing width and height
730+
*
731+
* @deprecated since version 3.2, to be removed in 4.0. Use the getTerminal() method instead.
712732
*/
713733
public function getTerminalDimensions()
714734
{
715-
return $this->terminal->getDimensions();
735+
@trigger_error(sprintf('%s is deprecated as of 3.2 and will be removed in 4.0. Use getTerminal() instead.', __METHOD__, ArgumentResolverInterface::class), E_USER_DEPRECATED);
736+
737+
return array($this->terminal->getWidth(), $this->terminal->getHeight());
716738
}
717739

718740
/**
@@ -724,10 +746,15 @@ public function getTerminalDimensions()
724746
* @param int $height The height
725747
*
726748
* @return Application The current application
749+
*
750+
* @deprecated since version 3.2, to be removed in 4.0. Use the getTerminal() method instead.
727751
*/
728752
public function setTerminalDimensions($width, $height)
729753
{
730-
$this->terminal->setDimensions($width, $height);
754+
@trigger_error(sprintf('%s is deprecated as of 3.2 and will be removed in 4.0. Use getTerminal() instead.', __METHOD__, ArgumentResolverInterface::class), E_USER_DEPRECATED);
755+
756+
$this->terminal->setWidth($width);
757+
$this->terminal->setHeight($height);
731758

732759
return $this;
733760
}

src/Symfony/Component/Console/Style/SymfonyStyle.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Symfony\Component\Console\Question\ChoiceQuestion;
2626
use Symfony\Component\Console\Question\ConfirmationQuestion;
2727
use Symfony\Component\Console\Question\Question;
28+
use Symfony\Component\Console\Terminal;
2829

2930
/**
3031
* Output decorator helpers for the Symfony Style Guide.
@@ -50,7 +51,8 @@ public function __construct(InputInterface $input, OutputInterface $output)
5051
$this->input = $input;
5152
$this->bufferedOutput = new BufferedOutput($output->getVerbosity(), false, clone $output->getFormatter());
5253
// Windows cmd wraps lines as soon as the terminal width is reached, whether there are following chars or not.
53-
$this->lineLength = min($this->getTerminalWidth() - (int) (DIRECTORY_SEPARATOR === '\\'), self::MAX_LINE_LENGTH);
54+
$width = (new Terminal())->getWidth() ?: self::MAX_LINE_LENGTH;
55+
$this->lineLength = min($width - (int) (DIRECTORY_SEPARATOR === '\\'), self::MAX_LINE_LENGTH);
5456

5557
parent::__construct($output);
5658
}
@@ -401,14 +403,6 @@ private function getProgressBar()
401403
return $this->progressBar;
402404
}
403405

404-
private function getTerminalWidth()
405-
{
406-
$application = new Application();
407-
$dimensions = $application->getTerminalDimensions();
408-
409-
return $dimensions[0] ?: self::MAX_LINE_LENGTH;
410-
}
411-
412406
private function autoPrependBlock()
413407
{
414408
$chars = substr(str_replace(PHP_EOL, "\n", $this->bufferedOutput->fetch()), -2);

src/Symfony/Component/Console/Terminal.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Terminal
1717
private $height;
1818

1919
/**
20-
* Tries to figure out the terminal width in which this application runs.
20+
* Gets the terminal width.
2121
*
2222
* @return int|null
2323
*/
@@ -41,7 +41,7 @@ public function setWidth($width)
4141
}
4242

4343
/**
44-
* Tries to figure out the terminal height in which this application runs.
44+
* Gets the terminal height.
4545
*
4646
* @return int|null
4747
*/

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

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -476,11 +476,9 @@ public function testFindWithDoubleColonInNameThrowsException()
476476

477477
public function testSetCatchExceptions()
478478
{
479-
$application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
479+
$application = new Application();
480480
$application->setAutoExit(false);
481-
$application->expects($this->any())
482-
->method('getTerminalWidth')
483-
->will($this->returnValue(120));
481+
$application->getTerminal()->setWidth(120);
484482
$tester = new ApplicationTester($application);
485483

486484
$application->setCatchExceptions(true);
@@ -514,11 +512,9 @@ public function testAutoExitSetting()
514512

515513
public function testRenderException()
516514
{
517-
$application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
515+
$application = new Application();
518516
$application->setAutoExit(false);
519-
$application->expects($this->any())
520-
->method('getTerminalWidth')
521-
->will($this->returnValue(120));
517+
$application->getTerminal()->setWidth(120);
522518
$tester = new ApplicationTester($application);
523519

524520
$tester->run(array('command' => 'foo'), array('decorated' => false, 'capture_stderr_separately' => true));
@@ -546,11 +542,9 @@ public function testRenderException()
546542
$tester->run(array('command' => 'foo3:bar'), array('decorated' => true, 'capture_stderr_separately' => true));
547543
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3decorated.txt', $tester->getErrorOutput(true), '->renderException() renders a pretty exceptions with previous exceptions');
548544

549-
$application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
545+
$application = new Application();
550546
$application->setAutoExit(false);
551-
$application->expects($this->any())
552-
->method('getTerminalWidth')
553-
->will($this->returnValue(32));
547+
$application->getTerminal()->setWidth(32);
554548
$tester = new ApplicationTester($application);
555549

556550
$tester->run(array('command' => 'foo'), array('decorated' => false, 'capture_stderr_separately' => true));
@@ -559,11 +553,9 @@ public function testRenderException()
559553

560554
public function testRenderExceptionWithDoubleWidthCharacters()
561555
{
562-
$application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
556+
$application = new Application();
563557
$application->setAutoExit(false);
564-
$application->expects($this->any())
565-
->method('getTerminalWidth')
566-
->will($this->returnValue(120));
558+
$application->getTerminal()->setWidth(120);
567559
$application->register('foo')->setCode(function () {
568560
throw new \Exception('エラーメッセージ');
569561
});
@@ -575,11 +567,9 @@ public function testRenderExceptionWithDoubleWidthCharacters()
575567
$tester->run(array('command' => 'foo'), array('decorated' => true, 'capture_stderr_separately' => true));
576568
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception_doublewidth1decorated.txt', $tester->getErrorOutput(true), '->renderException() renders a pretty exceptions with previous exceptions');
577569

578-
$application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
570+
$application = new Application();
579571
$application->setAutoExit(false);
580-
$application->expects($this->any())
581-
->method('getTerminalWidth')
582-
->will($this->returnValue(32));
572+
$application->getTerminal()->setWidth(32);
583573
$application->register('foo')->setCode(function () {
584574
throw new \Exception('コマンドの実行中にエラーが発生しました。');
585575
});
@@ -1023,6 +1013,9 @@ public function testRunWithDispatcherAddingInputOptions()
10231013
$this->assertEquals('some test value', $extraValue);
10241014
}
10251015

1016+
/**
1017+
* @group legacy
1018+
*/
10261019
public function testTerminalDimensions()
10271020
{
10281021
$application = new Application();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ public function testWithSmallScreen()
523523
$output = $this->getOutputStream();
524524

525525
$bar = new ProgressBar($output);
526-
$bar->getTerminal()->setDimensions(12, 50);
526+
$bar->getTerminal()->setWidth(12);
527527
$bar->start();
528528
$bar->advance();
529529

src/Symfony/Component/Console/Tests/TerminalTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@
1515

1616
class TerminalTest extends \PHPUnit_Framework_TestCase
1717
{
18-
public function testGetDimensions()
18+
public function test()
1919
{
2020
$terminal = new Terminal();
21-
$dimensions = $terminal->getDimensions();
22-
$this->assertCount(2, $dimensions);
23-
24-
$terminal->setDimensions(100, 50);
25-
$this->assertSame(array(100, 50), $terminal->getDimensions());
21+
$terminal->setWidth(100);
22+
$terminal->setHeight(50);
2623
$this->assertSame(100, $terminal->getWidth());
2724
$this->assertSame(50, $terminal->getHeight());
2825
}

0 commit comments

Comments
 (0)