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

Skip to content

[Console] Add getters for Application::$autoExit and $catchExceptions #14288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,16 @@ public function getHelp()
return $this->getLongVersion();
}

/**
* Gets whether to catch exceptions or not during commands execution.
*
* @return bool Whether to catch exceptions or not during commands execution
*/
public function areExceptionsCaught()
{
return $this->catchExceptions;
}

/**
* Sets whether to catch exceptions or not during commands execution.
*
Expand All @@ -266,6 +276,16 @@ public function setCatchExceptions($boolean)
$this->catchExceptions = (bool) $boolean;
}

/**
* Gets whether to automatically exit after a command execution or not.
*
* @return bool Whether to automatically exit after a command execution or not
*/
public function isAutoExitEnabled()
{
return $this->autoExit;
}

/**
* Sets whether to automatically exit after a command execution or not.
*
Expand Down Expand Up @@ -717,7 +737,7 @@ public function renderException($e, $output)
'args' => array(),
));

for ($i = 0, $count = count($trace); $i < $count; $i++) {
for ($i = 0, $count = count($trace); $i < $count; ++$i) {
$class = isset($trace[$i]['class']) ? $trace[$i]['class'] : '';
$type = isset($trace[$i]['type']) ? $trace[$i]['type'] : '';
$function = $trace[$i]['function'];
Expand Down Expand Up @@ -1086,7 +1106,7 @@ private function findAlternatives($name, $collection)
}
}

$alternatives = array_filter($alternatives, function ($lev) use ($threshold) { return $lev < 2*$threshold; });
$alternatives = array_filter($alternatives, function ($lev) use ($threshold) { return $lev < 2 * $threshold; });
asort($alternatives);

return array_keys($alternatives);
Expand Down
12 changes: 11 additions & 1 deletion src/Symfony/Component/Console/Tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ public function testSetCatchExceptions()
$tester = new ApplicationTester($application);

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

Expand All @@ -490,6 +491,15 @@ public function testSetCatchExceptions()
}
}

public function testAutoExitSetting()
{
$application = new Application();
$this->assertTrue($application->isAutoExitEnabled());

$application->setAutoExit(false);
$this->assertFalse($application->isAutoExitEnabled());
}

/**
* @group legacy
*/
Expand Down Expand Up @@ -679,7 +689,7 @@ public function testRun()
}

/**
* Issue #9285
* Issue #9285.
*
* If the "verbose" option is just before an argument in ArgvInput,
* an argument value should not be treated as verbosity value.
Expand Down