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

Skip to content

Commit b75755c

Browse files
Merge branch '2.7' into 2.8
* 2.7: [Config] Fix enum default value in Yaml dumper Finnish translation fix [CssSelector] Optimize regexs matching simple selectors Fix the phpdoc in the CssSelector TranslatorInterface [Console] Add clock mock to fix transient test on HHVM [DomCrawler] Optimize the regex used to find namespace prefixes [EventDispatcher] skip one lazy loading call [EventDispatcher] fix memory leak in a getListeners Default to stderr for console helpers (only merge if #15794 gets merged)
2 parents 74c24a5 + b6604f3 commit b75755c

File tree

22 files changed

+129
-84
lines changed

22 files changed

+129
-84
lines changed

src/Symfony/Component/Config/Definition/Dumper/YamlReferenceDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private function writeNode(NodeInterface $node, $depth = 0)
9393
}
9494
} elseif ($node instanceof EnumNode) {
9595
$comments[] = 'One of '.implode('; ', array_map('json_encode', $node->getValues()));
96-
$default = '~';
96+
$default = $node->hasDefaultValue() ? Inline::dump($node->getDefaultValue()) : '~';
9797
} else {
9898
$default = '~';
9999

src/Symfony/Component/Config/Tests/Definition/Dumper/XmlReferenceDumperTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ private function getConfigurationAsString()
3737
return str_replace("\n", PHP_EOL, <<<EOL
3838
<!-- Namespace: http://example.org/schema/dic/acme_root -->
3939
<!-- scalar-required: Required -->
40+
<!-- enum-with-default: One of "this"; "that" -->
4041
<!-- enum: One of "this"; "that" -->
4142
<config
4243
boolean="true"
@@ -48,6 +49,7 @@ private function getConfigurationAsString()
4849
scalar-array-empty=""
4950
scalar-array-defaults="elem1,elem2"
5051
scalar-required=""
52+
enum-with-default="this"
5153
enum=""
5254
>
5355

src/Symfony/Component/Config/Tests/Definition/Dumper/YamlReferenceDumperTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ private function F438 getConfigurationAsString()
4343
- elem1
4444
- elem2
4545
scalar_required: ~ # Required
46+
enum_with_default: this # One of "this"; "that"
4647
enum: ~ # One of "this"; "that"
4748
4849
# some info

src/Symfony/Component/Config/Tests/Fixtures/Configuration/ExampleConfiguration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function getConfigTreeBuilder()
3434
->scalarNode('scalar_array_empty')->defaultValue(array())->end()
3535
->scalarNode('scalar_array_defaults')->defaultValue(array('elem1', 'elem2'))->end()
3636
->scalarNode('scalar_required')->isRequired()->end()
37+
->enumNode('enum_with_default')->values(array('this', 'that'))->defaultValue('this')->end()
3738
->enumNode('enum')->values(array('this', 'that'))->end()
3839
->arrayNode('array')
3940
->info('some info')

src/Symfony/Component/Console/Helper/ProcessHelper.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Console\Helper;
1313

14+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1415
use Symfony\Component\Console\Output\OutputInterface;
1516
use Symfony\Component\Process\Exception\ProcessFailedException;
1617
use Symfony\Component\Process\Process;
@@ -37,6 +38,10 @@ class ProcessHelper extends Helper
3738
*/
3839
public function run(OutputInterface $output, $cmd, $error = null, $callback = null, $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE)
3940
{
41+
if ($output instanceof ConsoleOutputInterface) {
42+
$output = $output->getErrorOutput();
43+
}
44+
4045
$formatter = $this->getHelperSet()->get('debug_formatter');
4146

4247
if (is_array($cmd)) {
@@ -109,6 +114,10 @@ public function mustRun(OutputInterface $output, $cmd, $error = null, $callback
109114
*/
110115
public function wrapCallback(OutputInterface $output, Process $process, $callback = null)
111116
{
117+
if ($output instanceof ConsoleOutputInterface) {
118+
$output = $output->getErrorOutput();
119+
}
120+
112121
$formatter = $this->getHelperSet()->get('debug_formatter');
113122

114123
$that = $this;

src/Symfony/Component/Console/Helper/ProgressBar.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Console\Helper;
1313

14+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1415
use Symfony\Component\Console\Output\OutputInterface;
1516

1617
/**
@@ -54,6 +55,10 @@ class ProgressBar
5455
*/
5556
public function __construct(OutputInterface $output, $max = 0)
5657
{
58+
if ($output instanceof ConsoleOutputInterface) {
59+
$output = $output->getErrorOutput();
60+
}
61+
5762
$this->output = $output;
5863
$this->setMaxSteps($max);
5964

src/Symfony/Component/Console/Helper/QuestionHelper.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Console\Helper;
1313

1414
use Symfony\Component\Console\Input\InputInterface;
15+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1516
use Symfony\Component\Console\Output\OutputInterface;
1617
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
1718
use Symfony\Component\Console\Question\Question;
@@ -41,6 +42,10 @@ class QuestionHelper extends Helper
4142
*/
4243
public function ask(InputInterface $input, OutputInterface $output, Question $question)
4344
{
45+
if ($output instanceof ConsoleOutputInterface) {
46+
$output = $output->getErrorOutput();
47+
}
48+
4449
if (!$input->isInteractive()) {
4550
return $question->getDefault();
4651
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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\Helper;
13+
14+
use Symfony\Component\Console\Tests;
15+
16+
function time()
17+
{
18+
return Tests\time();
19+
}
20+
21+
namespace Symfony\Component\Console\Tests;
22+
23+
function with_clock_mock($enable = null)
24+
{
25+
static $enabled;
26+
27+
if (null === $enable) {
28+
return $enabled;
29+
}
30+
31+
$enabled = $enable;
32+
}
33+
34+
function time()
35+
{
36+
if (!with_clock_mock()) {
37+
return \time();
38+
}
39+
40+
return $_SERVER['REQUEST_TIME'];
41+
}

src/Symfony/Component/Console/Tests/Helper/LegacyProgressHelperTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,25 @@
1313

1414
use Symfony\Component\Console\Helper\ProgressHelper;
1515
use Symfony\Component\Console\Output\StreamOutput;
16+
use Symfony\Component\Console\Tests;
17+
18+
require_once __DIR__.'/../ClockMock.php';
1619

1720
/**
1821
* @group legacy
1922
*/
2023
class LegacyProgressHelperTest extends \PHPUnit_Framework_TestCase
2124
{
25+
protected function setUp()
26+
{
27+
Tests\with_clock_mock(true);
28+
}
29+
30+
protected function tearDown()
31+
{
32+
Tests\with_clock_mock(false);
33+
}
34+
2235
public function testAdvance()
2336
{
2437
$progress = new ProgressHelper();

src/Symfony/Component/CssSelector/Parser/Shortcut/ClassParser.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@ public function parse($source)
3333
{
3434
// Matches an optional namespace, optional element, and required class
3535
// $source = 'test|input.ab6bd_field';
36-
// $matches = array (size=5)
37-
// 0 => string 'test:input.ab6bd_field' (length=22)
38-
// 1 => string 'test:' (length=5)
39-
// 2 => string 'test' (length=4)
40-
// 3 => string 'input' (length=5)
41-
// 4 => string 'ab6bd_field' (length=11)
42-
if (preg_match('/^(([a-z]+)\|)?([\w-]+|\*)?\.([\w-]+)$/i', trim($source), $matches)) {
36+
// $matches = array (size=4)
37+
// 0 => string 'test|input.ab6bd_field' (length=22)
38+
// 1 => string 'test' (length=4)
39+
// 2 => string 'input' (length=5)
40+
// 3 => string 'ab6bd_field' (length=11)
41+
if (preg_match('/^(?:([a-z]++)\|)?+([\w-]++|\*)?+\.([\w-]++)$/i', trim($source), $matches)) {
4342
return array(
44-
new SelectorNode(new ClassNode(new ElementNode($matches[2] ?: null, $matches[3] ?: null), $matches[4])),
43+
new SelectorNode(new ClassNode(new ElementNode($matches[1] ?: null, $matches[2] ?: null), $matches[3])),
4544
);
4645
}
4746

src/Symfony/Component/CssSelector/Parser/Shortcut/ElementParser.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,12 @@ public function parse($source)
3232
{
3333
// Matches an optional namespace, required element or `*`
3434
// $source = 'testns|testel';
35-
// $matches = array (size=4)
36-
// 0 => string 'testns:testel' (length=13)
37-
// 1 => string 'testns:' (length=7)
38-
// 2 => string 'testns' (length=6)
39-
// 3 => string 'testel' (length=6)
40-
if (preg_match('/^(([a-z]+)\|)?([\w-]+|\*)$/i', trim($source), $matches)) {
41-
return array(new SelectorNode(new ElementNode($matches[2] ?: null, $matches[3])));
35+
// $matches = array (size=3)
36+
// 0 => string 'testns|testel' (length=13)
37+
// 1 => string 'testns' (length=6)
38+
// 2 => string 'testel' (length=6)
39+
if (preg_match('/^(?:([a-z]++)\|)?([\w-]++|\*)$/i', trim($source), $matches)) {
40+
return array(new SelectorNode(new ElementNode($matches[1] ?: null, $matches[2])));
4241
}
4342

4443
return array();

src/Symfony/Component/CssSelector/Parser/Shortcut/HashParser.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@ public function parse($source)
3333
{
3434
// Matches an optional namespace, optional element, and required id
3535
// $source = 'test|input#ab6bd_field';
36-
// $matches = array (size=5)
37-
// 0 => string 'test:input#ab6bd_field' (length=22)
38-
// 1 => string 'test:' (length=5)
39-
// 2 => string 'test' (length=4)
40-
// 3 => string 'input' (length=5)
41-
// 4 => string 'ab6bd_field' (length=11)
42-
if (preg_match('/^(([a-z]+)\|)?([\w-]+|\*)?#([\w-]+)$/i', trim($source), $matches)) {
36+
// $matches = array (size=4)
37+
// 0 => string 'test|input#ab6bd_field' (length=22)
38+
// 1 => string 'test' (length=4)
39+
// 2 => string 'input' (length=5)
40+
// 3 => string 'ab6bd_field' (length=11)
41+
if (preg_match('/^(?:([a-z]++)\|)?+([\w-]++|\*)?+#([\w-]++)$/i', trim($source), $matches)) {
4342
return array(
44-
new SelectorNode(new HashNode(new ElementNode($matches[2] ?: null, $matches[3] ?: null), $matches[4])),
43+
new SelectorNode(new HashNode(new ElementNode($matches[1] ?: null, $matches[2] ?: null), $matches[3])),
4544
);
4645
}
4746

src/Symfony/Component/CssSelector/XPath/TranslatorInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ interface TranslatorInterface
2929
* @param string $cssExpr
3030
* @param string $prefix
3131
*
32-
* @return XPathExpr
32+
* @return string
3333
*/
3434
public function cssToXPath($cssExpr, $prefix = 'descendant-or-self::');
3535

@@ -39,7 +39,7 @@ public function cssToXPath($cssExpr, $prefix = 'descendant-or-self::');
3939
* @param SelectorNode $selector
4040
* @param string $prefix
4141
*
42-
* @return XPathExpr
42+
* @return string
4343
*/
4444
public function selectorToXPath(SelectorNode $selector, $prefix = 'descendant-or-self::');
4545
}

src/Symfony/Component/DomCrawler/Crawler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,13 +1036,13 @@ private function discoverNamespace(\DOMXPath $domxpath, $prefix)
10361036
}
10371037

10381038
/**
1039-
* @param $xpath
1039+
* @param string $xpath
10401040
*
10411041
* @return array
10421042
*/
10431043
private function findNamespacePrefixes($xpath)
10441044
{
1045-
if (preg_match_all('/(?P<prefix>[a-z_][a-z_0-9\-\.]*):[^"\/:]/i', $xpath, $matches)) {
1045+
if (preg_match_all('/(?P<prefix>[a-z_][a-z_0-9\-\.]*+):[^"\/:]/i', $xpath, $matches)) {
10461046
return array_unique($matches['prefix']);
10471047
}
10481048

src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function removeListener($eventName, F438 $listener)
100100
}
101101

102102
/**
103-
* @see EventDispatcherInterface::hasListeners()
103+
* {@inheritdoc}
104104
*/
105105
public function hasListeners($eventName = null)
106106
{
@@ -116,7 +116,7 @@ public function hasListeners($eventName = null)
116116
}
117117

118118
/**
119-
* @see EventDispatcherInterface::getListeners()
119+
* {@inheritdoc}
120120
*/
121121
public function getListeners($eventName = null, $withPriorities = false)
122122
{
@@ -152,21 +152,6 @@ public function addSubscriberService($serviceId, $class)
152152
}
153153
}
154154

155-
/**
156-
* {@inheritdoc}
157-
*
158-
* Lazily loads listeners for this event from the dependency injection
159-
* container.
160-
*
161-
* @throws \InvalidArgumentException if the service is not defined
162-
*/
163-
public function dispatch($eventName, Event $event = null)
164-
{
165-
$this->lazyLoad($eventName);
166-
167-
return parent::dispatch($eventName, $event);
168-
}
169-
170155
public function getContainer()
171156
{
172157
return $this->container;

0 commit comments

Comments
 (0)
0