8000 Merge branch '3.0' into 3.1 · symfony/symfony@c968257 · GitHub
[go: up one dir, main page]

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

Appearance settings

Commit c968257

Browse files
committed
Merge branch '3.0' into 3.1
* 3.0: [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 6f7ed8c + 26f2c87 commit c968257

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
@@ -300,14 +300,14 @@ public function mergeApplicationDefinition($mergeArgs = true)
300300
return;
301301
}
302302

303+
$this->definition->addOptions($this->application->getDefinition()->getOptions());
304+
303305
if ($mergeArgs) {
304306
$currentArguments = $this->definition->getArguments();
305307
$this->definition->setArguments($this->application->getDefinition()->getArguments());
306308
$this->definition->addArguments($currentArguments);
307309
}
308310

309-
$this->definition->addOptions($this->application->getDefinition()->getOptions());
310-
311311
$this->applicationDefinitionMerged = true;
312312
if ($mergeArgs) {
313313
$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
@@ -733,6 +733,33 @@ public function testRunReturnsExitCodeOneForExceptionCodeZero()
733733
$this->assertSame(1, $exitCode, '->run() returns exit code 1 when exception code is 0');
734734
}
735735

736+
/**
737+
* @expectedException \LogicException
738+
* @expectedExceptionMessage An option with shortcut "e" already exists.
739+
*/
740+
public function testAddingOptionWithDuplicateShortcut()
741+
{
742+
$dispatcher = new EventDispatcher();
743+
$application = new Application();
744+
$application->setAutoExit(false);
745+
$application->setCatchExceptions(false);
746+
$application->setDispatcher($dispatcher);
747+
748+
$application->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'Environment'));
749+
750+
$application
751+
->register('foo')
752+
->setAliases(['f'])
753+
->setDefinition(array(new InputOption('survey', 'e', InputOption::VALUE_REQUIRED, 'My option with a shortcut.')))
754+
->setCode(function (InputInterface $input, OutputInterface $output) {})
755+
;
756+
757+
$input = new ArrayInput(array('command' => 'foo'));
758+
$output = new NullOutput();
759+
760+
$application->run($input, $output);
761+
}
762+
736763
/**
737764
* @expectedException \LogicException
738765
* @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