10000 Merge branch '2.5' · symfony/symfony@3e21c4d · GitHub
[go: up one dir, main page]

Skip to content

Commit 3e21c4d

Browse files
committed
Merge branch '2.5'
* 2.5: Update validators.eu.xlf fixed CS remove unused imports [Validator] Added markObjectAsInitialized() and isObjectInitialized() to ExecutionContextInterface [Validator] Fixed doc block [Routing] simplify the XML schema file Unify null comparisons [EventDispatcher] don't count empty listeners [Process] Fix unit tests in sigchild environment [Process] fix signal handling in wait() [BrowserKit] refactor code and fix unquoted regex Fixed server HTTP_HOST port uri conversion [HttpFoundation] moved test file to the right directory [Validator] Made sure that context changes don't leak out of (Contextual)ValidatorInterface [MonologBridge] fixed Console handler priorities Bring code into standard [Process] Add test to verify fix for issue #11421 [Process] Fixes issue #11421 [DependencyInjection] Pass a Scope instance instead of a scope name.
2 parents 7af2563 + 7e175ef commit 3e21c4d

File tree

42 files changed

+382
-84
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+382
-84
lines changed

src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function __construct(ContainerInterface $container)
4949
public function dispatchEvent($eventName, EventArgs $eventArgs = null)
5050
{
5151
if (isset($this->listeners[$eventName])) {
52-
$eventArgs = $eventArgs === null ? EventArgs::getEmptyInstance() : $eventArgs;
52+
$eventArgs = null === $eventArgs ? EventArgs::getEmptyInstance() : $eventArgs;
5353

5454
$initialized = isset($this->initialized[$eventName]);
5555

src/Symfony/Bridge/Monolog/Handler/ConsoleHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ public function onTerminate(ConsoleTerminateEvent $event)
139139
public static function getSubscribedEvents()
140140
{
141141
return array(
142-
ConsoleEvents::COMMAND => 'onCommand',
143-
ConsoleEvents::TERMINATE => 'onTerminate'
142+
ConsoleEvents::COMMAND => array('onCommand', 255),
143+
ConsoleEvents::TERMINATE => array('onTerminate', -255),
144144
);
145145
}
146146

src/Symfony/Bridge/Monolog/Tests/Handler/ConsoleHandlerTest.php

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

1414
use Monolog\Logger;
1515
use Symfony\Bridge\Monolog\Handler\ConsoleHandler;
16+
use Symfony\Component\Console\ConsoleEvents;
17+
use Symfony\Component\Console\Event\ConsoleCommandEvent;
18+
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
1619
use Symfony\Component\Console\Output\OutputInterface;
20+
use Symfony\Component\Console\Output\BufferedOutput;
21+
use Symfony\Component\EventDispatcher\EventDispatcher;
22+
use Symfony\Component\Console\Command\Command;
1723

1824
/**
1925
* Tests the ConsoleHandler and also the ConsoleFormatter.
@@ -156,4 +162,42 @@ public function testWritingAndFormatting()
156162

157163
$this->assertTrue($handler->handle($errorRecord), 'The handler finished handling the log as bubble is false.');
158164
}
165+
166+
public function testLogsFromListeners()
167+
{
168+
$output = new BufferedOutput();
169+
$output->setVerbosity(OutputInterface::VERBOSITY_DEBUG);
170+
171+
$handler = new ConsoleHandler(null, false);
172+
173+
$logger = new Logger('app');
174+
$logger->pushHandler($handler);
175+
176+
$dispatcher = new EventDispatcher();
177+
$dispatcher->addListener(ConsoleEvents::COMMAND, function () use ($logger) {
178+
$logger->addInfo('Before command message.');
179+
});
180+
$dispatcher->addListener(ConsoleEvents::TERMINATE, function () use ($logger) {
181+
$logger->addInfo('Before terminate message.');
182+
});
183+
184+
$dispatcher->addSubscriber($handler);
185+
186+
$dispatcher->addListener(ConsoleEvents::COMMAND, function () use ($logger) {
187+
$logger->addInfo('After command message.');
188+
});
189+
$dispatcher->addListener(ConsoleEvents::TERMINATE, function () use ($logger) {
190+
$logger->addInfo('After terminate message.');
191+
});
192+
193+
$event = new ConsoleCommandEvent(new Command('foo'), $this->getMock('Symfony\Component\Console\Input\InputInterface'), $output);
194+
$dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
195+
$this->assertContains('Before command message.', $out = $output->fetch());
196+
$this->assertContains('After command message.', $out);
197+
198+
$event = new ConsoleTerminateEvent(new Command('foo'), $this->getMock('Symfony\Component\Console\Input\InputInterface'), $output, 0);
199+
$dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
200+
$this->assertContains('Before terminate message.', $out = $output->fetch());
201+
$this->assertContains('After terminate message.', $out);
202+
}
159203
}

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function getConfigTreeBuilder()
4141
->end()
4242
->arrayNode('trusted_proxies')
4343
->beforeNormalization()
44-
->ifTrue(function ($v) { return !is_array($v) && !is_null($v); })
44+
->ifTrue(function ($v) { return !is_array($v) && null !== $v; })
4545
->then(function ($v) { return is_bool($v) ? array() : preg_split('/\s*,\s*/', $v); })
4646
->end()
4747
->prototype('scalar')

src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget_collapsed.html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<select
2-
<?php if ($required && $empty_value === null && $empty_value_in_choices === false && $multiple === false):
2+
<?php if ($required && null === $empty_value && $empty_value_in_choices === false && $multiple === false):
33
$required = false;
44
endif; ?>
55
<?php echo $view['form']->block($form, 'widget_attributes', array(

src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ protected static function getPhpUnitXmlDir()
4545
}
4646

4747
$dir = static::getPhpUnitCliConfigArgument();
48-
if ($dir === null &&
48+
if (null === $dir &&
4949
(is_file(getcwd().DIRECTORY_SEPARATOR.'phpunit.xml') ||
5050
is_file(getcwd().DIRECTORY_SEPARATOR.'phpunit.xml.dist'))) {
5151
$dir = getcwd();
5252
}
5353

5454
// Can't continue
55-
if ($dir === null) {
55+
if (null === $dir) {
5656
throw new \RuntimeException('Unable to guess the Kernel directory.');
5757
}
5858

@@ -90,7 +90,7 @@ private static function getPhpUnitCliConfigArgument()
9090
}
9191

9292
/**
93-
* Attempts to guess the Kernel location.
93+
* Attempts to guess the kernel location.
9494
*
9595
* When the Kernel is located, the file is required.
9696
*
@@ -117,7 +117,7 @@ protected static function getKernelClass()
117117
$finder->name('*Kernel.php')->depth(0)->in($dir);
118118
$results = iterator_to_array($finder);
119119
if (!count($results)) {
120-
throw new \RuntimeException('Either set KERNEL_DIR in your phpunit.xml according to http://symfony.com/doc/current/book/testing.html#your-first-functional-test or override the KernelTestCase::createKernel() method.');
120+
throw new \RuntimeException('Either set KERNEL_DIR in your phpunit.xml according to http://symfony.com/doc/current/book/testing.html#your-first-functional-test or override the WebTestCase::createKernel() method.');
121121
}
122122

123123
$file = current($results);
@@ -141,7 +141,7 @@ protected static function bootKernel(array $options = array())
141141
static::$kernel->boot();
142142
}
143143

144-
/**
144+
/**
145145
* Creates a Kernel.
146146
*
147147
* Available options:

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/SerializerPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function testServicesAreOrderedAccordingToPriority()
9696
'Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SerializerPass',
9797
'findAndSortTaggedServices'
9898
);
99-
$method->setAccessible(TRUE);
99+
$method->setAccessible(true);
100100

101101
$actual = $method->invoke($serializerPass, 'tag', $container);
102102

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@
370370
this.getThreshold = function() {
371371
var threshold = Sfjs.getPreference(_storagePrefix + 'threshold');
372372
373-
if (threshold === null) {
373+
if (null === threshold) {
374374
return _threshold;
375375
}
376376

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,20 @@
6868
menu = document.getElementById('navigation'), savedState = Sfjs.getPreference('menu/displayState'),
6969
displayState, elem, className;
7070
71-
if (savedState == null) {
71+
if (null === savedState) {
7272
savedState = 'block';
7373
}
7474
75-
displayState = state || (savedState == 'block' ? 'none' : 'block');
75+
displayState = state || ('block' === savedState ? 'none' : 'block');
7676
77-
if (typeof doSave === 'undefined') {
77+
if ('undefined' === typeof doSave) {
7878
doSave = true;
7979
}
8080
8181
document.getElementById('searchBar').style.display = displayState;
8282
document.getElementById('adminBar').style.display = displayState;
8383
84-
if (displayState == 'block') {
84+
if ('block' === displayState) {
8585
Sfjs.removeClass(menu, 'collapsed-menu');
8686
Sfjs.removeClass(menu.parentNode.parentNode, 'collapsed-menu-parents');
8787
@@ -107,7 +107,7 @@
107107
}
108108
109109
window.setTimeout(function() {
110-
if (document.getElementById('menu-profiler') == null) {
110+
if (null === document.getElementById('menu-profiler')) {
111111
return;
112112
}
113113
@@ -119,12 +119,12 @@
119119
}
120120
121121
for (elem in menuItems) {
122-
if (typeof(menuItems[elem].children) != 'undefined' &&
122+
if (typeof(menuItems[elem].children) !== 'undefined' &&
123123
menuItems[elem].children.length > 0) {
124124
child = menuItems[elem].children[0]
125125
126-
if (child.getAttribute('title') == '' ||
127-
child.getAttribute('title') == null) {
126+
if ('' === child.getAttribute('title') ||
127+
null === child.getAttribute('title')) {
128128
value = child.text.replace(/^\s+/g, '').split('\n')[0].replace(/\s+$/g, '');
129129
child.setAttribute('title', value);
130130
}

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public function request($method, $uri, array $parameters = array(), array $files
297297
$uri = $this->getAbsoluteUri($uri);
298298

299299
if (isset($server['HTTP_HOST'])) {
300-
$uri = preg_replace('{^(https?\://)'.parse_url($uri, PHP_URL_HOST).'}', '${1}'.$server['HTTP_HOST'], $uri);
300+
$uri = preg_replace('{^(https?\://)'.preg_quote($this->extractHost($uri)).'}', '${1}'.$server['HTTP_HOST'], $uri);
301301
}
302302

303303
if (isset($server['HTTPS'])) {
@@ -310,12 +310,7 @@ public function request($method, $uri, array $parameters = array(), array $files
310310
$server['HTTP_REFERER'] = $this->history->current()->getUri();
311311
}
312312

313-
$server['HTTP_HOST'] = parse_url($uri, PHP_URL_HOST);
314-
315-
if ($port = parse_url($uri, PHP_URL_PORT)) {
316-
$server['HTTP_HOST'] .= ':'.$port;
317-
}
318-
313+
$server['HTTP_HOST'] = $this->extractHost($uri);
319314
$server['HTTPS'] = 'https' == parse_url($uri, PHP_URL_SCHEME);
320315

321316
$this->internalRequest = new Request($uri, $method, $parameters, $files, $this->cookieJar->allValues($uri), $server, $content);
@@ -610,4 +605,15 @@ private function updateServerFromUri($server, $uri)
610605

611606
return $server;
612607
}
608+
609+
private function extractHost($uri)
610+
{
611+
$host = parse_url($uri, PHP_URL_HOST);
612+
613+
if ($port = parse_url($uri, PHP_URL_PORT)) {
614+
return $host.':'.$port;
615+
}
616+
617+
return $host;
618+
}
613619
}

src/Symfony/Component/BrowserKit/Tests/ClientTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,24 @@ public function testRequestURIConversion()
210210
$this->assertEquals('http://www.example.com/foo/bar', $client->getRequest()->getUri(), '->request() uses the previous request for relative URLs');
211211
}
212212

213+
public function testRequestURIConversionByServerHost()
214+
{
215+
$client = new TestClient();
216+
217+
$server = array('HTTP_HOST' => 'www.exampl+e.com:8000');
218+
$parameters = array();
219+
$files = array();
220+
221+
$client->request('GET', 'http://exampl+e.com', $parameters, $files, $server);
222+
$this->assertEquals('http://www.exampl+e.com:8000', $client->getRequest()->getUri(), '->request() uses HTTP_HOST to add port');
223+
224+
$client->request('GET', 'http://exampl+e.com:8888', $parameters, $files, $server);
225+
$this->assertEquals('http://www.exampl+e.com:8000', $client->getRequest()->getUri(), '->request() uses HTTP_HOST to modify existing port');
226+
227+
$client->request('GET', 'http://exampl+e.com:8000', $parameters, $files, $server);
228+
$this->assertEquals('http://www.exampl+e.com:8000', $client->getRequest()->getUri(), '->request() uses HTTP_HOST respects correct set port');
229+
}
230+
213231
public function testRequestReferer()
214232
{
215233
$client = new TestClient();

src/Symfony/Component/Config/Tests/Definition/Builder/ExprBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ protected function finalizeTestBuilder($testBuilder, $config = null)
182182
->end()
183183
->end()
184184
->buildTree()
185-
->finalize($config === null ? array('key'=>'value') : $config)
185+
->finalize(null === $config ? array('key'=>'value') : $config)
186186
;
187187
}
188188

src/Symfony/Component/DependencyInjection/Dumper/GraphvizDumper.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\DependencyInjection\ContainerInterface;
1919
use Symfony\Component\DependencyInjection\ContainerBuilder;
2020
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
21+
use Symfony\Component\DependencyInjection\Scope;
2122

2223
/**
2324
* GraphvizDumper dumps a service container as a graphviz file.
@@ -200,8 +201,8 @@ private function cloneContainer()
200201
$container->setDefinitions($this->container->getDefinitions());
201202
$container->setAliases($this->container->getAliases());
202203
$container->setResources($this->container->getResources());
203-
foreach ($this->container->getScopes() as $scope) {
204-
$container->addScope($scope);
204+
foreach ($this->container->getScopes() as $scope => $parentScope) {
205+
$container->addScope(new Scope($scope, $parentScope));
205206
}
206207
foreach ($this->container->getExtensions() as $extension) {
207208
$container->registerExtension($extension);

src/Symfony/Component/DependencyInjection/Tests/Dumper/GraphvizDumperTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,11 @@ public function testDumpWithUnresolvedParameter()
7070

7171
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services17.dot')), $dumper->dump(), '->dump() dumps services');
7272
}
73+
74+
public function testDumpWithScopes()
75+
{
76+
$container = include self::$fixturesPath.'/containers/container18.php';
77+
$dumper = new GraphvizDumper($container);
78+
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services18.dot')), $dumper->dump(), '->dump() dumps services');
79+
}
7380
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
use Symfony\Component\DependencyInjection\ContainerBuilder;
4+
use Symfony\Component\DependencyInjection\Scope;
5+
6+
$container = new ContainerBuilder();
7+
$container->addScope(new Scope('request'));
8+
$container->
9+
register('foo', 'FooClass')->
10+
setScope('request')
11+
;
12+
$container->compile();
13+
14+
return $container;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
digraph sc {
2+
ratio="compress"
3+
node [fontsize="11" fontname="Arial" shape="record"];
4+
edge [fontsize="9" fontname="Arial" color="grey" arrowhead="open" arrowsize="0.5"];
5+
6+
node_foo [label="foo\nFooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
7+
node_service_container [label="service_container\nSymfony\\Component\\DependencyInjection\\ContainerBuilder\n", shape=record, fillcolor="#9999ff", style="filled"];
8+
}

src/Symfony/Component/EventDispatcher/EventDispatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function getListeners($eventName = null)
7474
}
7575
}
7676

77-
return $this->sorted;
77+
return array_filter($this->sorted);
7878
}
7979

8080
/**

src/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,28 @@ public function testWorkaroundForPhpBug62976()
274274
$dispatcher->removeListener('bug.62976', function () {});
275275
$this->assertTrue($dispatcher->hasListeners('bug.62976'));
276276
}
277+
278+
public function testHasListenersWhenAddedCallbackListenerIsRemoved()
279+
{
280+
$listener = function () {};
281+
$this->dispatcher->addListener('foo', $listener);
282+
$this->dispatcher->removeListener('foo', $listener);
283+
$this->assertFalse($this->dispatcher->hasListeners());
284+
}
285+
286+
public function testGetListenersWhenAddedCallbackListenerIsRemoved()
287+
{
288+
$listener = function () {};
289+
$this->dispatcher->addListener('foo', $listener);
290+
$this->dispatcher->removeListener('foo', $listener);
291+
$this->assertSame(array(), $this->dispatcher->getListeners());
292+
}
293+
294+
public function testHasListenersWithoutEventsReturnsFalseAfterHasListenersWithEventHasBeenCalled()
295+
{
296+
$this->assertFalse($this->dispatcher->hasListeners('foo'));
297+
$this->assertFalse($this->dispatcher->hasListeners());
298+
}
277299
}
278300

279301
class CallableClass

src/Symfony/Component/Finder/Adapter/AbstractFindAdapter.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Symfony\Component\Finder\Shell\Shell;
1717
use Symfony\Component\Finder\Expression\Expression;
1818
use Symfony\Component\Finder\Shell\Command;
19-
use Symfony\Component\Finder\Iterator\SortableIterator;
2019
use Symfony\Component\Finder\Comparator\NumberComparator;
2120
use Symfony\Component\Finder\Comparator\DateComparator;
2221

0 commit comments

Comments
 (0)
0