Skip to content

Commit df8a30b

Browse files
Merge branch '2.8' into 3.1
* 2.8: do not depend on a fixed date in layout tests [Console] Escape default value when dumping help [Console] OS X Can't call cli_set_process_title php without superuser Fixed @return when returning this or static #bis Polish translation improvement in Validator component [Console] Descriptors should use Helper::strlen [Config] Improve PHPdoc / IDE autocomplete [Debug] Wrap call to ->log in a try catch block [Debug] UndefinedMethodFatalErrorHandler - Handle anonymous classes [SecurityBundle] Made collection of user provider unique when injecting them to the RemberMeService
2 parents 8b8ad9b + 15fafb7 commit df8a30b

27 files changed

+583
-13
lines changed

Command/Command.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,14 @@ public function run(InputInterface $input, OutputInterface $output)
227227

228228
if (null !== $this->processTitle) {
229229
if (function_exists('cli_set_process_title')) {
230-
cli_set_process_title($this->processTitle);
230+
if (false === @cli_set_process_title($this->processTitle)) {
231+
if ('Darwin' === PHP_OS) {
232+
$output->writeln('<comment>Running "cli_get_process_title" as an unprivileged user is not supported on MacOS.</comment>');
233+
} else {
234+
$error = error_get_last();
235+
trigger_error($error['message'], E_USER_WARNING);
236+
}
237+
}
231238
} elseif (function_exists('setproctitle')) {
232239
setproctitle($this->processTitle);
233240
} elseif (OutputInterface::VERBOSITY_VERY_VERBOSE === $output->getVerbosity()) {

Descriptor/MarkdownDescriptor.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Console\Application;
1515
use Symfony\Component\Console\Command\Command;
16+
use Symfony\Component\Console\Helper\Helper;
1617
use Symfony\Component\Console\Input\InputArgument;
1718
use Symfony\Component\Console\Input\InputDefinition;
1819
use Symfony\Component\Console\Input\InputOption;
@@ -94,7 +95,7 @@ protected function describeCommand(Command $command, array $options = array())
9495

9596
$this->write(
9697
$command->getName()."\n"
97-
.str_repeat('-', strlen($command->getName()))."\n\n"
98+
.str_repeat('-', Helper::strlen($command->getName()))."\n\n"
9899
.'* Description: '.($command->getDescription() ?: '<none>')."\n"
99100
.'* Usage:'."\n\n"
100101
.array_reduce(array_merge(array($command->getSynopsis()), $command->getAliases(), $command->getUsages()), function ($carry, $usage) {
@@ -121,7 +122,7 @@ protected function describeApplication(Application $application, array $options
121122
$describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
122123
$description = new ApplicationDescription($application, $describedNamespace);
123124

124-
$this->write($application->getName()."\n".str_repeat('=', strlen($application->getName())));
125+
$this->write($application->getName()."\n".str_repeat('=', Helper::strlen($application->getName())));
125126

126127
foreach ($description->getNamespaces() as $namespace) {
127128
if (ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {

Descriptor/TextDescriptor.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use Symfony\Component\Console\Application;
1515
use Symfony\Component\Console\Command\Command;
16+
use Symfony\Component\Console\Formatter\OutputFormatter;
17+
use Symfony\Component\Console\Helper\Helper;
1618
use Symfony\Component\Console\Input\InputArgument;
1719
use Symfony\Component\Console\Input\InputDefinition;
1820
use Symfony\Component\Console\Input\InputOption;
@@ -37,7 +39,7 @@ protected function describeInputArgument(InputArgument $argument, array $options
3739
$default = '';
3840
}
3941

40-
$totalWidth = isset($options['total_width']) ? $options['total_width'] : strlen($argument->getName());
42+
$totalWidth = isset($options['total_width']) ? $options['total_width'] : Helper::strlen($argument->getName());
4143
$spacingWidth = $totalWidth - strlen($argument->getName());
4244

4345
$this->writeText(sprintf(' <info>%s</info> %s%s%s',
@@ -75,7 +77,7 @@ protected function describeInputOption(InputOption $option, array $options = arr
7577
sprintf('--%s%s', $option->getName(), $value)
7678
);
7779

78-
$spacingWidth = $totalWidth - strlen($synopsis);
80+
$spacingWidth = $totalWidth - Helper::strlen($synopsis);
7981

8082
$this->writeText(sprintf(' <info>%s</info> %s%s%s%s',
8183
$synopsis,
@@ -94,7 +96,7 @@ protected function describeInputDefinition(InputDefinition $definition, array $o
9496
{
9597
$totalWidth = $this->calculateTotalWidthForOptions($definition->getOptions());
9698
foreach ($definition->getArguments() as $argument) {
97-
$totalWidth = max($totalWidth, strlen($argument->getName()));
99+
$totalWidth = max($totalWidth, Helper::strlen($argument->getName()));
98100
}
99101

100102
if ($definition->getArguments()) {
@@ -206,7 +208,7 @@ protected function describeApplication(Application $application, array $options
206208

207209
foreach ($namespace['commands'] as $name) {
208210
$this->writeText("\n");
209-
$spacingWidth = $width - strlen($name);
211+
$spacingWidth = $width - Helper::strlen($name);
210212
$this->writeText(sprintf(' <info>%s</info>%s%s', $name, str_repeat(' ', $spacingWidth), $description->getCommand($name)->getDescription()), $options);
211213
}
212214
}
@@ -235,6 +237,16 @@ private function writeText($content, array $options = array())
235237
*/
236238
private function formatDefaultValue($default)
237239
{
240+
if (is_string($default)) {
241+
$default = OutputFormatter::escape($default);
242+
} elseif (is_array($default)) {
243+
foreach ($default as $key => $value) {
244+
if (is_string($value)) {
245+
$default[$key] = OutputFormatter::escape($value);
246+
}
247+
}
248+
}
249+
238250
return str_replace('\\\\', '\\', json_encode($default, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
239251
}
240252

@@ -248,9 +260,9 @@ private function getColumnWidth(array $commands)
248260
$widths = array();
249261

250262
foreach ($commands as $command) {
251-
$widths[] = strlen($command->getName());
263+
$widths[] = Helper::strlen($command->getName());
252264
foreach ($command->getAliases() as $alias) {
253-
$widths[] = strlen($alias);
265+
$widths[] = Helper::strlen($alias);
254266
}
255267
}
256268

@@ -267,10 +279,10 @@ private function calculateTotalWidthForOptions($options)
267279
$totalWidth = 0;
268280
foreach ($options as $option) {
269281
// "-" + shortcut + ", --" + name
270-
$nameLength = 1 + max(strlen($option->getShortcut()), 1) + 4 + strlen($option->getName());
282+
$nameLength = 1 + max(strlen($option->getShortcut()), 1) + 4 + Helper::strlen($option->getName());
271283

272284
if ($option->acceptValue()) {
273-
$valueLength = 1 + strlen($option->getName()); // = + value
285+
$valueLength = 1 + Helper::strlen($option->getName()); // = + value
274286
$valueLength += $option->isValueOptional() ? 2 : 0; // [ + ]
275287

276288
$nameLength += $valueLength;

Helper/Table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function getStyle()
152152
* @param int $columnIndex Column index
153153
* @param TableStyle|string $name The style name or a TableStyle instance
154154
*
155-
* @return self
155+
* @return $this
156156
*/
157157
public function setColumnStyle($columnIndex, $name)
158158
{

Tests/Command/CommandTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ public function testRunWithProcessTitle()
328328
$command->setProcessTitle('foo');
329329
$this->assertSame(0, $command->run(new StringInput(''), new NullOutput()));
330330
if (function_exists('cli_set_process_title')) {
331+
if (null === @cli_get_process_title() && 'Darwin' === PHP_OS) {
332+
$this->markTestSkipped('Running "cli_get_process_title" as an unprivileged user is not supported on MacOS.');
333+
}
331334
$this->assertEquals('foo', cli_get_process_title());
332335
}
333336
}

Tests/Descriptor/AbstractDescriptorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ abstract protected function getDescriptor();
8686

8787
abstract protected function getFormat();
8888

89-
private function getDescriptionTestData(array $objects)
89+
protected function getDescriptionTestData(array $objects)
9090
{
9191
$data = array();
9292
foreach ($objects as $name => $object) {

Tests/Descriptor/MarkdownDescriptorTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,27 @@
1212
namespace Symfony\Component\Console\Tests\Descriptor;
1313

1414
use Symfony\Component\Console\Descriptor\MarkdownDescriptor;
15+
use Symfony\Component\Console\Tests\Fixtures\DescriptorApplicationMbString;
16+
use Symfony\Component\Console\Tests\Fixtures\DescriptorCommandMbString;
1517

1618
class MarkdownDescriptorTest extends AbstractDescriptorTest
1719
{
20+
public function getDescribeCommandTestData()
21+
{
22+
return $this->getDescriptionTestData(array_merge(
23+
ObjectsProvider::getCommands(),
24+
array('command_mbstring' => new DescriptorCommandMbString())
25+
));
26+
}
27+
28+
public function getDescribeApplicationTestData()
29+
{
30+
return $this->getDescriptionTestData(array_merge(
31+
ObjectsProvider::getApplications(),
32+
array('application_mbstring' => new DescriptorApplicationMbString())
33+
));
34+
}
35+
1836
protected function getDescriptor()
1937
{
2038
return new MarkdownDescriptor();

Tests/Descriptor/ObjectsProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public static function getInputArguments()
3131
'input_argument_2' => new InputArgument('argument_name', InputArgument::IS_ARRAY, 'argument description'),
3232
'input_argument_3' => new InputArgument('argument_name', InputArgument::OPTIONAL, 'argument description', 'default_value'),
3333
'input_argument_4' => new InputArgument('argument_name', InputArgument::REQUIRED, "multiline\nargument description"),
34+
'input_argument_with_style' => new InputArgument('argument_name', InputArgument::OPTIONAL, 'argument description', '<comment>style</>'),
3435
);
3536
}
3637

@@ -43,6 +44,8 @@ public static function getInputOptions()
4344
'input_option_4' => new InputOption('option_name', 'o', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'option description', array()),
4445
'input_option_5' => new InputOption('option_name', 'o', InputOption::VALUE_REQUIRED, "multiline\noption description"),
4546
'input_option_6' => new InputOption('option_name', array('o', 'O'), InputOption::VALUE_REQUIRED, 'option with multiple shortcuts'),
47+
'input_option_with_style' => new InputOption('option_name', 'o', InputOption::VALUE_REQUIRED, 'option description', '<comment>style</>'),
48+
'input_option_with_style_array' => new InputOption('option_name', 'o', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'option description', array('<comment>Hello</comment>', '<info>world</info>')),
4649
);
4750
}
4851

Tests/Descriptor/TextDescriptorTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,27 @@
1212
namespace Symfony\Component\Console\Tests\Descriptor;
1313

1414
use Symfony\Component\Console\Descriptor\TextDescriptor;
15+
use Symfony\Component\Console\Tests\Fixtures\DescriptorApplicationMbString;
16+
use Symfony\Component\Console\Tests\Fixtures\DescriptorCommandMbString;
1517

1618
class TextDescriptorTest extends AbstractDescriptorTest
1719
{
20+
public function getDescribeCommandTestData()
21+
{
22+
return $this->getDescriptionTestData(array_merge(
23+
ObjectsProvider::getCommands(),
24+
array('command_mbstring' => new DescriptorCommandMbString())
25+
));
26+
}
27+
28+
public function getDescribeApplicationTestData()
29+
{
30+
return $this->getDescriptionTestData(array_merge(
31+
ObjectsProvider::getApplications(),
32+
array('application_mbstring' => new DescriptorApplicationMbString())
33+
));
34+
}
35+
1836
protected function getDescriptor()
1937
{
2038
return new TextDescriptor();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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+
namespace Symfony\Component\Console\Tests\Fixtures;
13+
14+
use Symfony\Component\Console\Application;
15+
16+
class DescriptorApplicationMbString extends Application
17+
{
18+
public function __construct()
19+
{
20+
parent::__construct('MbString åpplicätion');
21+
22+
$this->add(new DescriptorCommandMbString());
23+
}
24+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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+
namespace Symfony\Component\Console\Tests\Fixtures;
13+
14+
use Symfony\Component\Console\Command\Command;
15+
use Symfony\Component\Console\Input\InputArgument;
16+
use Symfony\Component\Console\Input\InputOption;
17+
18+
class DescriptorCommandMbString extends Command
19+
{
20+
protected function configure()
21+
{
22+
$this
23+
->setName('descriptor:åèä')
24+
->setDescription('command åèä description')
25+
->setHelp('command åèä help')
26+
->addUsage('-o|--option_name <argument_name>')
27+
->addUsage('<argument_name>')
28+
->addArgument('argument_åèä', InputArgument::REQUIRED)
29+
->addOption('option_åèä', 'o', InputOption::VALUE_NONE)
30+
;
31+
}
32+
}

0 commit comments

Comments
 (0)