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

Commita095d0b

Browse files
committed
deprecated some Console Application methods
1 parente1acb7e commita095d0b

File tree

5 files changed

+46
-32
lines changed

5 files changed

+46
-32
lines changed

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

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

617617
$len =$this->stringWidth($title);
618618

619-
$width =$this->getTerminalWidth() ?$this->getTerminalWidth() -1 :PHP_INT_MAX;
619+
$width =$this->terminal->getWidth() ?$this->terminal->getWidth() -1 :PHP_INT_MAX;
620620
// 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
621621
if (defined('HHVM_VERSION') &&$width >1 <<31) {
622622
$width =1 <<31;
@@ -676,34 +676,56 @@ public function renderException(\Exception $e, OutputInterface $output)
676676
}
677677
}
678678

679+
/**
680+
* Returns the current terminal.
681+
*
682+
* @return Terminal
683+
*/
684+
publicfunctiongetTerminal()
685+
{
686+
return$this->terminal;
687+
}
688+
679689
/**
680690
* Tries to figure out the terminal width in which this application runs.
681691
*
682692
* @return int|null
693+
*
694+
* @deprecated since version 3.2, to be removed in 4.0. Use the getTerminal() method instead.
683695
*/
684696
protectedfunctiongetTerminalWidth()
685697
{
698+
@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);
699+
686700
return$this->terminal->getWidth();
687701
}
688702

689703
/**
690704
* Tries to figure out the terminal height in which this application runs.
691705
*
692706
* @return int|null
707+
*
708+
* @deprecated since version 3.2, to be removed in 4.0. Use the getTerminal() method instead.
693709
*/
694710
protectedfunctiongetTerminalHeight()
695711
{
712+
@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);
713+
696714
return$this->terminal->getHeight();
697715
}
698716

699717
/**
700718
* Tries to figure out the terminal dimensions based on the current environment.
701719
*
702720
* @return array Array containing width and height
721+
*
722+
* @deprecated since version 3.2, to be removed in 4.0. Use the getTerminal() method instead.
703723
*/
704724
publicfunctiongetTerminalDimensions()
705725
{
706-
return$this->terminal->getDimensions();
726+
@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);
727+
728+
returnarray($this->terminal->getWidth(),$this->terminal->getHeight());
707729
}
708730

709731
/**
@@ -715,10 +737,15 @@ public function getTerminalDimensions()
715737
* @param int $height The height
716738
*
717739
* @return Application The current application
740+
*
741+
* @deprecated since version 3.2, to be removed in 4.0. Use the getTerminal() method instead.
718742
*/
719743
publicfunctionsetTerminalDimensions($width,$height)
720744
{
721-
$this->terminal->setDimensions($width,$height);
745+
@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);
746+
747+
$this->terminal->setWidth($width);
748+
$this->terminal->setHeight($height);
722749

723750
return$this;
724751
}

‎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 outthe terminal width in which this application runs.
20+
*Getsthe terminal width.
2121
*
2222
* @return int|null
2323
*/
@@ -41,7 +41,7 @@ public function setWidth($width)
4141
}
4242

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

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

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

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

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

515513
publicfunctiontestRenderException()
516514
{
517-
$application =$this->getMock('Symfony\Component\Console\Application',array('getTerminalWidth'));
515+
$application =newApplication();
518516
$application->setAutoExit(false);
519-
$application->expects($this->any())
520-
->method('getTerminalWidth')
521-
->will($this->returnValue(120));
517+
$application->getTerminal()->setWidth(120);
522518
$tester =newApplicationTester($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 =newApplication();
550546
$application->setAutoExit(false);
551-
$application->expects($this->any())
552-
->method('getTerminalWidth')
553-
->will($this->returnValue(32));
547+
$application->getTerminal()->setWidth(32);
554548
$tester =newApplicationTester($application);
555549

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

560554
publicfunctiontestRenderExceptionWithDoubleWidthCharacters()
561555
{
562-
$application =$this->getMock('Symfony\Component\Console\Application',array('getTerminalWidth'));
556+
$application =newApplication();
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
thrownew \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 =newApplication();
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
thrownew \Exception('コマンドの実行中にエラーが発生しました。');
585575
});

‎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 =newProgressBar($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 TerminalTestextends \PHPUnit_Framework_TestCase
1717
{
18-
publicfunctiontestGetDimensions()
18+
publicfunctiontest()
1919
{
2020
$terminal =newTerminal();
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)

[8]ページ先頭

©2009-2025 Movatter.jp