8000 Merge branch '2.1' · Ouark/symfony@88ea842 · GitHub
[go: up one dir, main page]

Skip to content

Commit 88ea842

Browse files
committed
Merge branch '2.1'
* 2.1: (28 commits) Delete use of CreationExeption [Form] Fixed error message in PropertyPath to not advice to use a non-existing feature [Form] Fixed creation of multiple money fields with different currencies [Form] Fixed setting the "data" option to an object in "choice" and "entity" type Fixed Serbian plural translations. Fixed IPv6 Check in RequestMatcher Fix typo change what I think is a typo [Console] Fix error when mode is not in PATH [WebProfilerBundle] fixed macro usage (to be forward compatible with Twig 2.x) Change monolog require-dev to use the branch alias instead of dev-master [FrameworkBundle] partially reverted previous merge [2.1] Added missing error return codes in commands Made the router lazy when setting the context [WebProfilerBundle] fixed typos Fix incorrect variable in FileProfilerStorage UnitTest fix UnitTest fix added a unit test fixed symfony#5384 ...
2 parents 6b12fc0 + 82a6694 commit 88ea842

File tree

40 files changed

+302
-98
lines changed

40 files changed

+302
-98
lines changed

UPGRADE-2.1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@
576576
577577
* Custom styling of individual rows of a collection form has been removed for
578578
performance reasons. Instead, all rows now have the same block name, where
579-
the word "entry" replaces the previous occurence of the row index.
579+
the word "entry" replaces the previous occurrence of the row index.
580580
581581
Before:
582582

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"doctrine/orm": ">=2.2.3,<2.4-dev",
6060
"doctrine/data-fixtures": "1.0.*",
6161
"propel/propel1": "dev-master",
62-
"monolog/monolog": "dev-master"
62+
"monolog/monolog": "1.*"
6363
},
6464
"autoload": {
6565
"psr-0": { "Symfony\\": "src/" },

src/Symfony/Bundle/FrameworkBundle/Command/RouterMatchCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
8484

8585
if (!$matches) {
8686
$output->writeln('<fg=red>None of the routes matches</>');
87+
88+
return 1;
8789
}
8890
}
8991
}

src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8282
if ($input->getOption('force') !== true && $input->getOption('dump-messages') !== true) {
8383
$output->writeln('<info>You must choose one of --force or --dump-messages</info>');
8484

85-
return;
85+
return 1;
8686
}
8787

8888
// check format
@@ -92,7 +92,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9292
$output->writeln('<error>Wrong output format</error>');
9393
$output->writeln('Supported formats are '.implode(', ', $supportedFormats).'.');
9494

95-
return;
95+
return 1;
9696
}
9797

9898
// get bundle directory

src/Symfony/Bundle/SecurityBundle/Command/InitAclCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6262
} catch (SchemaException $e) {
6363
$output->writeln("Aborting: " . $e->getMessage());
6464

65-
return;
65+
return 1;
6666
}
6767

6868
foreach ($schema->toSql($connection->getDatabasePlatform()) as $sql) {

src/Symfony/Bundle/TwigBundle/Command/LintCommand.php

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7070
$template .= fread(STDIN, 1024);
7171
}
7272

73-
return $twig->parse($twig->tokenize($template));
73+
return $this->validateTemplate($twig, $output, $template);
7474
}
7575

76 1CF5 76
if (0 !== strpos($filename, '@') && !is_readable($filename)) {
@@ -87,26 +87,39 @@ protected function execute(InputInterface $input, OutputInterface $output)
8787
$files = Finder::create()->files()->in($dir)->name('*.twig');
8888
}
8989

90-
$error = false;
90+
$errors = 0;
9191
foreach ($files as $file) {
92-
try {
93-
$twig->parse($twig->tokenize(file_get_contents($file), (string) $file));
94-
$output->writeln(sprintf("<info>OK</info> in %s", $file));
95-
} catch (\Twig_Error $e) {
96-
$this->renderException($output, $file, $e);
97-
$error = true;
98-
}
92+
$errors += $this->validateTemplate($twig, $output, file_get_contents($file), $file);
93+
}
94+
95+
return $errors > 0 ? 1 : 0;
96+
}
97+
98+
protected function validateTemplate(\Twig_Environment $twig, OutputInterface $output, $template, $file = null)
99+
{
100+
try {
101+
$twig->parse($twig->tokenize($template, $file ? (string) $file : null));
102+
$output->writeln('<info>OK</info>'.($file ? sprintf(' in %s', $file) : ''));
103+
} catch (\Twig_Error $e) {
104+
$this->renderException($output, $template, $e, $file);
105+
106+
return 1;
99107
}
100108

101-
return $error ? 1 : 0;
109+
return 0;
102110
}
103111

104-
protected function renderException(OutputInterface $output, $file, \Twig_Error $exception)
112+
protected function renderException(OutputInterface $output, $template, \Twig_Error $exception, $file = null)
105113
{
106114
$line = $exception->getTemplateLine();
107-
$lines = $this->getContext($file, $line);
115+
$lines = $this->getContext($template, $line);
116+
117+
if ($file) {
118+
$output->writeln(sprintf("<error>KO</error> in %s (line %s)", $file, $line));
119+
} else {
120+
$output->writeln(sprintf("<error>KO</error> (line %s)", $line));
121+
}
108122

109-
$output->writeln(sprintf("<error>KO</error> in %s (line %s)", $file, $line));
110123
foreach ($lines as $no => $code) {
111124
$output->writeln(sprintf(
112125
"%s %-6s %s",
@@ -120,10 +133,9 @@ protected function renderException(OutputInterface $output, $file, \Twig_Error $
120133
}
121134
}
122135

123-
protected function getContext($file, $line, $context = 3)
136+
protected function getContext($template, $line, $context = 3)
124137
{
125-
$fileContent = file_get_contents($file);
126-
$lines = explode("\n", $fileContent);
138+
$lines = explode("\n", $template);
127139

128140
$position = max(0, $line - $context);
129141
$max = min(count($lines), $line - 1 + $context);

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/events.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
{% else %}
1616
<h2>Events</h2>
1717
<p>
18-
<em>No events have been recorded. Are you sure that debugging is enabled in the kernel ?</em>
18+
<em>No events have been recorded. Are you sure that debugging is enabled in the kernel?</em>
1919
</p>
2020
{% endif %}
2121
{% endblock %}

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/time.html.twig

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{% extends '@WebProfiler/Profiler/layout.html.twig' %}
22

3+
{% from _self import display_timeline, dump_events, dump_request_data %}
4+
35
{% if colors is not defined %}
46
{% set colors = {
57
'default': '#aacd4e',
@@ -41,7 +43,7 @@
4143
{{ block('panelContent') }}
4244
{% else %}
4345
<p>
44-
<em>No timing events have been recorded. Are you sure that debugging is enabled in the kernel ?</em>
46+
<em>No timing events have been recorded. Are you sure that debugging is enabled in the kernel?</em>
4547
</p>
4648
{% endif %}
4749
{% endblock %}
@@ -77,7 +79,7 @@
7779

7880
{% set max = collector.events.__section__.endtime %}
7981

80-
{{ _self.display_timeline('timeline_' ~ token, collector.events, colors) }}
82+
{{ display_timeline('timeline_' ~ token, collector.events, colors) }}
8183

8284
{% if profile.children|length %}
8385
{% for child in profile.children %}
@@ -87,7 +89,7 @@
8789
<small> - {{ events.__section__.totaltime }} ms</small>
8890
</h3>
8991

90-
{{ _self.display_timeline('timeline_' ~ child.token, events, colors) }}
92+
{{ display_timeline('timeline_' ~ child.token, events, colors) }}
9193
{% endfor %}
9294
{% endif %}
9395

@@ -388,12 +390,12 @@
388390
var requests_data = {
389391
"max": {{ "%F"|format(collector.events.__section__.endtime) }},
390392
"requests": [
391-
{{ _self.dump_request_data(token, profile, collector.events, collector.events.__section__.origin) }}
393+
{{ dump_request_data(token, profile, collector.events, collector.events.__section__.origin) }}
392394
393395
{% if profile.children|length %}
394396
,
395397
{% for child in profile.children %}
396-
{{ _self.dump_request_data(child.token, child, child.getcollector('time').events, collector.events.__section__.origin) }}{{ loop.last ? '' : ',' }}
398+
{{ dump_request_data(child.token, child, child.getcollector('time').events, collector.events.__section__.origin) }}{{ loop.last ? '' : ',' }}
397399
{% endfor %}
398400
{% endif %}
399401
]
@@ -436,7 +438,7 @@
436438
"id": "{{ token }}",
437439
"left": {{ "%F"|format(events.__section__.origin - origin) }},
438440
"events": [
439-
{{ _self.dump_events(events) }}
441+
{{ dump_events(events) }}
440442
]
441443
}
442444
{% endmacro %}

src/Symfony/Component/Console/Application.php

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,10 @@ public function find($name)
546546
// name
547547
$commands = array();
548548
foreach ($this->commands as $command) {
549-
if ($this->extractNamespace($command->getName()) == $namespace) {
549+
$extractedNamespace = $this->extractNamespace($command->getName());
550+
if ($extractedNamespace === $namespace
551+
|| !empty($namespace) && 0 === strpos($extractedNamespace, $namespace)
552+
) {
550553
$commands[] = $command->getName();
551554
}
552555
}
@@ -566,7 +569,10 @@ public function find($name)
566569
$aliases = array();
567570
foreach ($this->commands as $command) {
568571
foreach ($command->getAliases() as $alias) {
569-
if ($this->extractNamespace($alias) == $namespace) {
572+
$extractedNamespace = $this->extractNamespace($alias);
573+
if ($extractedNamespace === $namespace
574+
|| !empty($namespace) && 0 === strpos($extractedNamespace, $namespace)
575+
) {
570576
$aliases[] = $alias;
571577
}
572578
}
@@ -849,8 +855,7 @@ protected function getTerminalWidth()
849855
return preg_replace('{^(\d+)x.*$}', '$1', $ansicon);
850856
}
851857

852-
exec('mode CON', $execData);
853-
if (preg_match('{columns:\s*(\d+)}i', $execData[4], $matches)) {
858+
if (preg_match('{columns:\s*(\d+)}i', $this->getConsoleMode(), $matches)) {
854859
return $matches[1];
855860
}
856861
}
@@ -872,8 +877,7 @@ protected function getTerminalHeight()
872877
return preg_replace('{^\d+x\d+ \(\d+x(\d+)\)$}', '$1', trim($ansicon));
873878
}
874879

875-
exec('mode CON', $execData);
876-
if (preg_match('{lines:\s*(\d+)}i', $execData[3], $matches)) {
880+
if (preg_match('{lines:\s*(\d+)}i', $this->getConsoleMode(), $matches)) {
877881
return $matches[1];
878882
}
879883
}
@@ -962,6 +966,29 @@ private function getSttyColumns()
962966
}
963967
}
964968

969+
/**
970+
* Runs and parses mode CON if it's available, suppressing any error output
971+
*
972+
* @return string
973+
*/
974+
private function getConsoleMode()
975+
{
976+
if (!function_exists('proc_open')) {
977+
return;
978+
}
979+
980+
$descriptorspec = array(1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
981+
$process = proc_open('mode CON', $descriptorspec, $pipes, null, null, array('suppress_errors' => true));
982+
if (is_resource($process)) {
983+
$info = stream_get_contents($pipes[1]);
984+
fclose($pipes[1]);
985+
fclose($pipes[2]);
986+
proc_close($process);
987+
988+
return $info;
989+
}
990+
}
991+
965992
/**
966993
* Sorts commands in alphabetical order.
967994
*

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public static function setUpBeforeClass()
3333
require_once self::$fixturesPath.'/Foo1Command.php';
3434
require_once self::$fixturesPath.'/Foo2Command.php';
3535
require_once self::$fixturesPath.'/Foo3Command.php';
36+
require_once self::$fixturesPath.'/Foo4Command.php';
3637
}
3738

3839
protected function normalizeLineBreaks($text)
@@ -262,6 +263,19 @@ public function testFindAlternativeExceptionMessage()
262263
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
263264
$this->assertRegExp('/Did you mean one of these/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
264265
}
266+
267+
$application->add(new \Foo3Command());
268+
$application->add(new \Foo4Command());
269+
270+
// Subnamespace + plural
271+
try {
272+
$a = $application->find('foo3:');
273+
$this->fail('->find() should throw an \InvalidArgumentException if a command is ambiguous because of a subnamespace, with alternatives');
274+
} catch (\Exception $e) {
275+
$this->assertInstanceOf('\InvalidArgumentException', $e);
276+
$this->assertRegExp('/foo3:bar/', $e->getMessage());
277+
$this->assertRegExp('/foo3:bar:toh/', $e->getMessage());
278+
}
265279
}
266280

267281
public function testFindAlternativeCommands()
@@ -620,4 +634,4 @@ protected function getDefaultHelperSet()
620634
{
621635
return new HelperSet(array(new FormatterHelper()));
622636
}
623-
}
637+
}

0 commit comments

Comments
 (0)
0