8000 Merge branch '2.7' into 2.8 · symfony/symfony@e89e165 · GitHub
[go: up one dir, main page]

Skip to content

Commit e89e165

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: [Console] SymfonyStyle: Align multi-line/very-long-line blocks [Console][DX] Fixed ambiguous error message when using a duplicate option shortcut Fix js comment in profiler
2 parents 5cb0ad3 + 13394f8 commit e89e165

File tree

9 files changed

+88
-8
lines changed

9 files changed

+88
-8
lines changed

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@
8383
requestStack = [],
8484
8585
extractHeaders = function(xhr, stackElement) {
86-
// Here we avoid to call xhr.getResponseHeader in order to
87-
// prevent polluting the console with CORS security errors
86+
/* Here we avoid to call xhr.getResponseHeader in order to */
87+
/* prevent polluting the console with CORS security errors */
8888
var allHeaders = xhr.getAllResponseHeaders();
8989
var ret;
9090

src/Symfony/Component/Console/Command/Command.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,14 +307,14 @@ public function mergeApplicationDefinition($mergeArgs = true)
307307
return;
308308
}
309309

310+
$this->definition->addOptions($this->application->getDefinition()->getOptions());
311+
310312
if ($mergeArgs) {
311313
$currentArguments = $this->definition->getArguments();
312314
$this->definition->setArguments($this->application->getDefinition()->getArguments());
313315
$this->definition->addArguments($currentArguments);
314316
}
315317

316-
$this->definition->addOptions($this->application->getDefinition()->getOptions());
317-
318318
$this->applicationDefinitionMerged = true;
319319
if ($mergeArgs) {
320320
$this->applicationDefinitionMergedWithArgs = true;

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,36 @@ public function block($messages, $type = null, $style = null, $prefix = ' ', $pa
6868
{
6969
$this->autoPrependBlock();
7070
$messages = is_array($messages) ? array_values($messages) : array($messages);
71+
$indentLength = 0;
7172
$lines = array();
7273

73-
// add type
7474
if (null !== $type) {
75-
$messages[0] = sprintf('[%s] %s', $type, $messages[0]);
75+
$typePrefix = sprintf('[%s] ', $type);
76+
$indentLength = strlen($typePrefix);
77+
$lineIndentation = str_repeat(' ', $indentLength);
7678
}
7779

7880
// wrap and add newlines for each element
7981
foreach ($messages as $key => $message) {
8082
$message = OutputFormatter::escape($message);
81-
$lines = array_merge($lines, explode(PHP_EOL, wordwrap($message, $this->lineLength - Helper::strlen($prefix), PHP_EOL, true)));
83+
$lines = array_merge($lines, explode(PHP_EOL, wordwrap($message, $this->lineLength - Helper::strlen($prefix) - $indentLength, PHP_EOL, true)));
84+
85+
// prefix each line with a number of spaces equivalent to the type length
86+
if (null !== $type) {
87+
foreach ($lines as &$line) {
88+
$line = $lineIndentation === substr($line, 0, $indentLength) ? $line : $lineIndentation.$line;
89+
}
90+
}
8291

8392
if (count($messages) > 1 && $key < count($messages) - 1) {
8493
$lines[] = '';
8594
}
8695
}
8796

97+
if (null !== $type) {
98+
$lines[0] = substr_replace($lines[0], $typePrefix, 0, $indentLength);
99+
}
100+
88101
if ($padding && $this->isDecorated()) {
89102
array_unshift($lines, '');
90103
$lines[] = '';

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,33 @@ public function testRunReturnsExitCodeOneForExceptionCodeZero()
734734
$this->assertSame(1, $exitCode, '->run() returns exit code 1 when exception code is 0');
735735
}
736736

737+
/**
738+
* @expectedException \LogicException
739+
* @expectedExceptionMessage An option with shortcut "e" already exists.
740+
*/
741+
public function testAddingOptionWithDuplicateShortcut()
742+
{
743+
$dispatcher = new EventDispatcher();
744+
$application = new Application();
745+
$application->setAutoExit(false);
746+
$application->setCatchExceptions(false);
747+
$application->setDispatcher($dispatcher);
748+
749+
$application->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'Environment'));
750+
751+
$application
752+
->register('foo')
753+
->setAliases(['f'])
754+
->setDefinition(array(new InputOption('survey', 'e', InputOption::VALUE_REQUIRED, 'My option with a shortcut.')))
755+
->setCode(function (InputInterface $input, OutputInterface $output) {})
756+
;
757+
758+
$input = new ArrayInput(array('command' => 'foo'));
759+
$output = new NullOutput();
760+
761+
$application->run($input, $output);
762+
}
763+
737764
/**
738765
* @expectedException \LogicException
739766
* @dataProvider getAddingAlreadySetDefinitionElementData
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
use Symfony\Component\Console\Input\InputInterface;
4+
use Symfony\Component\Console\Output\OutputInterface;
5+
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
6+
7+
//Ensure that all lines are aligned to the begin of the first line in a very long line block
8+
return function (InputInterface $input, OutputInterface $output) {
9+
$output = new SymfonyStyleWithForcedLineLength($input, $output);
10+
$output->block(
11+
'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum',
12+
'CUSTOM',
13+
'fg=white;bg=green',
14+
'X ',
15+
true
16+
);
17+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
use Symfony\Component\Console\Input\InputInterface;
4+
use Symfony\Component\Console\Output\OutputInterface;
5+
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
6+
7+
//Ensure that all lines are aligned to the begin of the first line in a multi-line block
8+
return function (InputInterface $input, OutputInterface $output) {
9+
$output = new SymfonyStyleWithForcedLineLength($input, $output);
10+
$output->block(['Custom block', 'Second custom block line'], 'CUSTOM', 'fg=white;bg=green', 'X ', true);
11+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
X [CUSTOM] Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
3+
X dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
4+
X commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat
5+
X nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit
6+
X anim id est laborum
7+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
X [CUSTOM] Custom block
3+
X
4+
X Second custom block line
5+

src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function inputCommandToOutputFilesProvider()
5757

5858
public function testLongWordsBlockWrapping()
5959
{
60-
$word = 'Lopadotemachoselachogaleokranioleipsanodrimhypotrimmatosilphioparaomelitokatakechymenokichlepikossyphophattoperisteralektryonoptekephalliokigklopeleiolagoiosiraiobaphetraganopterygon';
60+
$word = 'Lopadotemachoselachogaleokranioleipsanodrimhypotrimmatosilphioparaomelitokatakechymenokichlepikossyphophattoperisteralektryonoptekephalliokigklopeleiolagoiosiraiobaphetraganopterygovgollhjvhvljfezefeqifzeiqgiqzhrsdgihqzridghqridghqirshdghdghieridgheirhsdgehrsdvhqrsidhqshdgihrsidvqhneriqsdvjzergetsrfhgrstsfhsetsfhesrhdgtesfhbzrtfbrztvetbsdfbrsdfbrn';
6161
$wordLength = strlen($word);
6262
$maxLineLength = SymfonyStyle::MAX_LINE_LENGTH - 3;
6363

0 commit comments

Comments
 (0)
0