Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ae1684c

Browse files
committed
Allow binary values in parameters.
1 parent a8dc953 commit ae1684c

File tree

8 files changed

+25
-1
lines changed

8 files changed

+25
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,12 @@ private function export($value)
18111811

18121812
private function doExport($value, $resolveEnv = false)
18131813
{
1814-
if (is_string($value) && false !== strpos($value, "\n")) {
1814+
if (is_string($value) && \in_array(preg_match('/[^\s\P{Cc}]/u', $value), array(false, 1), true)) {
1815+
$toHex = function (&$values, $char) {
1816+
return $values.sprintf('\\x%02x', ord($char));
1817+
};
1818+
$export = '"'.array_reduce(str_split($value), $toHex, '').'"';
1819+
} elseif (is_string($value) && false !== strpos($value, "\n")) {
18151820
$cleanParts = explode("\n", $value);
18161821
$cleanParts = array_map(function ($part) { return var_export($part, true); }, $cleanParts);
18171822
$export = implode('."\n".', $cleanParts);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ private function convertParameters(array $parameters, $type, \DOMElement $parent
298298
$element->setAttribute('type', 'expression');
299299
$text = $this->document->createTextNode(self::phpToXml((string) $value));
300300
$element->appendChild($text);
301+
} elseif (is_string($value) && \in_array(preg_match('/[^\s\P{Cc}]/u', $value), array(false, 1), true)) {
302+
$element->setAttribute('type', 'binary');
303+
$text = $this->document->createTextNode(self::phpToXml(base64_encode($value)));
304+
$element->appendChild($text);
301305
} else {
302306
if (in_array($value, array('null', 'true', 'false'), true)) {
303307
$element->setAttribute('type', 'string');

src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,12 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $file, $lowercase =
511511
}
512512
$arguments[$key] = new TaggedIteratorArgument($arg->getAttribute('tag'));
513513
break;
514+
case 'binary':
515+
if (false === $value = base64_decode($arg->nodeValue)) {
516+
throw new InvalidArgumentException(sprintf('Tag "<%s>" with type="binary" is not a valid base64 encoded string.', $name));
517+
}
518+
$arguments[$key] = $value;
519+
break;
514520
case 'string':
515521
$arguments[$key] = $arg->nodeValue;
516522
break;

src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@
246246
<xsd:enumeration value="collection" />
247247
<xsd:enumeration value="string" />
248248
<xsd:enumeration value="constant" />
249+
<xsd:enumeration value="binary" />
249250
</xsd:restriction>
250251
</xsd:simpleType>
251252

src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container8.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
'bar' => 'foo is %%foo bar',
1010
'escape' => '@escapeme',
1111
'values' => array(true, false, null, 0, 1000.3, 'true', 'false', 'null'),
12+
'binary' => "\xf0\xf0\xf0\xf0",
13+
'binary-control-char' => "This is a Bell char \x07",
1214
)));
1315

1416
return $container;

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ protected function getDefaultParameters()
135135
6 => 'false',
136136
7 => 'null',
137137
),
138+
'binary' => "\xf0\xf0\xf0\xf0",
139+
'binary-control-char' => "\x54\x68\x69\x73\x20\x69\x73\x20\x61\x20\x42\x65\x6c\x6c\x20\x63\x68\x61\x72\x20\x07",
138140
);
139141
}
140142
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services8.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
<parameter type="string">false</parameter>
1919
<parameter type="string">null</parameter>
2020
</parameter>
21+
<parameter key="binary" type="binary">8PDw8A==</parameter>
22+
<parameter key="binary-control-char" type="binary">VGhpcyBpcyBhIEJlbGwgY2hhciAH</parameter>
2123
</parameters>
2224
<services>
2325
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerInterface" public="true" synthetic="true"/>

src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services8.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ parameters:
44
bar: 'foo is %%foo bar'
55
escape: '@@escapeme'
66
values: [true, false, null, 0, 1000.3, 'true', 'false', 'null']
7+
binary: !!binary 8PDw8A==
8+
binary-control-char: !!binary VGhpcyBpcyBhIEJlbGwgY2hhciAH
79

810
services:
911
service_container:

0 commit comments

Comments
 (0)