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

Skip to content

Commit e9b6a12

Browse files
committed
Merge branch '2.1'
* 2.1: fixed stringification of array objects in RequestDataCollector (closes symfony#5295) [HttpFoundation] removed the username and password from generated URL as generated by the Request class (closes symfony#5555) [Console] fixed default argument display (closes symfony#5563) Fixing config normalisation example in docblock
2 parents 958c976 + 237629a commit e9b6a12

File tree

7 files changed

+59
-18
lines changed

7 files changed

+59
-18
lines changed

src/Symfony/Component/Config/Definition/Processor.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ public static function normalizeKeys(array $config)
8989
*
9090
* Here is an example.
9191
*
92-
* The configuration is XML:
92+
* The configuration in XML:
9393
*
94-
* <twig:extension id="twig.extension.foo" />
95-
* <twig:extension id="twig.extension.bar" />
94+
* <twig:extension>twig.extension.foo</twig:extension>
95+
* <twig:extension>twig.extension.bar</twig:extension>
9696
*
9797
* And the same configuration in YAML:
9898
*
99-
* twig.extensions: ['twig.extension.foo', 'twig.extension.bar']
99+
* extensions: ['twig.extension.foo', 'twig.extension.bar']
100100
*
101101
* @param array $config A config array
102102
* @param string $key The key to normalize

src/Symfony/Component/Console/Input/InputDefinition.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,10 @@ public function asXml($asDom = false)
526526

527527
private function formatDefaultValue($default)
528528
{
529-
return json_encode($default);
529+
if (version_compare(PHP_VERSION, '5.4', '<')) {
530+
return str_replace('\/', '/', json_encode($default));
531+
}
532+
533+
return json_encode($default, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
530534
}
531535
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<comment>Arguments:</comment>
22
<info>foo </info> The foo argument
33
<info>baz </info> The baz argument<comment> (default: true)</comment>
4-
<info>bar </info> The bar argument<comment> (default: ["bar"])</comment>
4+
<info>bar </info> The bar argument<comment> (default: ["http://foo.com/"])</comment>
55

66
<comment>Options:</comment>
77
<info>--foo</info> (-f) The foo option
88
<info>--baz</info> The baz option<comment> (default: false)</comment>
99
<info>--bar</info> (-b) The bar option<comment> (default: "bar")</comment>
10-
<info>--qux</info> The qux option<comment> (default: ["foo","bar"])</comment><comment> (multiple values allowed)</comment>
10+
<info>--qux</info> The qux option<comment> (default: ["http://foo.com/","bar"])</comment><comment> (multiple values allowed)</comment>
1111
<info>--qux2</info> The qux2 option<comment> (default: {"foo":"bar"})</comment><comment> (multiple values allowed)</comment>

src/Symfony/Component/Console/Tests/Input/InputDefinitionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,11 @@ public function testAsText()
322322
$definition = new InputDefinition(array(
323323
new InputArgument('foo', InputArgument::OPTIONAL, 'The foo argument'),
324324
new InputArgument('baz', InputArgument::OPTIONAL, 'The baz argument', true),
325-
new InputArgument('bar', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'The bar argument', array('bar')),
325+
new InputArgument('bar', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'The bar argument', array('http://foo.com/')),
326326
new InputOption('foo', 'f', InputOption::VALUE_REQUIRED, 'The foo option'),
327327
new InputOption('baz', null, InputOption::VALUE_OPTIONAL, 'The baz option', false),
328328
new InputOption('bar', 'b', InputOption::VALUE_OPTIONAL, 'The bar option', 'bar'),
329-
new InputOption('qux', '', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The qux option', array('foo', 'bar')),
329+
new InputOption('qux', '', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The qux option', array('http://foo.com/', 'bar')),
330330
new InputOption('qux2', '', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The qux2 option', array('foo' => 'bar')),
331331
));
332332
$this->assertStringEqualsFile(self::$fixtures.'/definition_astext.txt', $definition->asText(), '->asText() returns a textual representation of the InputDefinition');

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,11 +795,14 @@ public function getRequestUri()
795795
/**
796796
* Gets the scheme and HTTP host.
797797
*
798+
* If the URL was called with basic authentication, the user
799+
* and the password are not added to the generated string.
800+
*
798801
* @return string The scheme and HTTP host
799802
*/
800803
public function getSchemeAndHttpHost()
801804
{
802-
return $this->getScheme().'://'.(('' != $auth = $this->getUserInfo()) ? $auth.'@' : '').$this->getHttpHost();
805+
return $this->getScheme().'://'.$this->getHttpHost();
803806
}
804807

805808
/**

src/Symfony/Component/HttpKernel/DataCollector/DataCollector.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,45 @@ public function unserialize($data)
3131
{
3232
$this->data = unserialize($data);
3333
}
34+
35+
/**
36+
* Converts a PHP variable to a string.
37+
*
38+
* @param mixed $var A PHP variable
39+
*
40+
* @return string The string representation of the variable
41+
*/
42+
protected function varToString($var)
43+
{
44+
if (is_object($var)) {
45+
return sprintf('Object(%s)', get_class($var));
46+
}
47+
48+
if (is_array($var)) {
49+
$a = array();
50+
foreach ($var as $k => $v) {
51+
$a[] = sprintf('%s => %s', $k, $this->varToString($v));
52+
}
53+
54+
return sprintf("Array(%s)", implode(', ', $a));
55+
}
56+
57+
if (is_resource($var)) {
58+
return sprintf('Resource(%s)', get_resource_type($var));
59+
}
60+
61+
if (null === $var) {
62+
return 'null';
63+
}
64+
65+
if (false === $var) {
66+
return 'false';
67+
}
68+
69+
if (true === $var) {
70+
return 'true';
71+
}
72+
73+
return (string) $var;
74+
}
3475
}

src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,7 @@ public function collect(Request $request, Response $response, \Exception $except
5151

5252
$attributes = array();
5353
foreach ($request->attributes->all() as $key => $value) {
54-
if (is_object($value)) {
55-
$attributes[$key] = sprintf('Object(%s)', get_class($value));
56-
if (is_callable(array($value, '__toString'))) {
57-
$attributes[$key] .= sprintf(' = %s', (string) $value);
58-
}
59-
} else {
60-
$attributes[$key] = $value;
61-
}
54+
$attributes[$key] = $this->varToString($value);
6255
}
6356

6457
$content = null;

0 commit comments

Comments
 (0)
0