8000 feature #14288 [Console] Add getters for Application::$autoExit and $… · symfony/symfony@4f26a2e · GitHub
[go: up one dir, main page]

Skip to content

Commit 4f26a2e

Browse files
committed
feature #14288 [Console] Add getters for Application::$autoExit and $catchExceptions (VasekPurchart)
This PR was submitted for the 2.7 branch but it was merged into the 3.1-dev branch instead (closes #14288). Discussion ---------- [Console] Add getters for Application::$autoExit and $catchExceptions There is currently no way to retrieve this information from Application (afaik) and since this can be set from outside (and is even part of the `@api`) it should be retrievable. This might come handy for example when working with an Application instance inside your code - for example when creating a Console exception listener - then you need information about how the application was run. | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- 5d191d3 [Console] Add getters for Application:: and
2 parents 26ad4ff + 5d191d3 commit 4f26a2e

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,16 @@ public function getHelp()
239239
return $this->getLongVersion();
240240
}
241241

242+
/**
243+
* Gets whether to catch exceptions or not during commands execution.
244+
*
245+
* @return bool Whether to catch exceptions or not during commands execution
246+
*/
247+
public function areExceptionsCaught()
248+
{
249+
return $this->catchExceptions;
250+
}
251+
242252
/**
243253
* Sets whether to catch exceptions or not during commands execution.
244254
*
@@ -249,6 +259,16 @@ public function setCatchExceptions($boolean)
249259
$this->catchExceptions = (bool) $boolean;
250260
}
251261

262+
/**
263+
* Gets whether to automatically exit after a command execution or not.
264+
*
265+
* @return bool Whether to automatically exit after a command execution or not
266+
*/
267+
public function isAutoExitEnabled()
268+
{
269+
return $this->autoExit;
270+
}
271+
252272
/**
253273
* Sets whether to automatically exit after a command execution or not.
254274
*

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ public function testSetCatchExceptions()
484484
$tester = new ApplicationTester($application);
485485

486486
$application->setCatchExceptions(true);
487+
$this->assertTrue($application->areExceptionsCaught());
487488
$tester->run(array('command' => 'foo'), array('decorated' => false));
488489
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception1.txt', $tester->getDisplay(true), '->setCatchExceptions() sets the catch exception flag');
489490

@@ -497,6 +498,15 @@ public function testSetCatchExceptions()
497498
}
498499
}
499500

501+
public function testAutoExitSetting()
502+
{
503+
$application = new Application();
504+
$this->assertTrue($application->isAutoExitEnabled());
505+
606D
506+
$application->setAutoExit(false);
507+
$this->assertFalse($application->isAutoExitEnabled());
508+
}
509+
500510
public function testRenderException()
501511
{
502512
$application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));

0 commit comments

Comments
 (0)
0