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

Skip to content

Commit 3424cc7

Browse files
committed
feature #25928 [DI] Allow binary values in parameters. (bburnichon)
This PR was squashed before being merged into the 4.1-dev branch (closes #25928). Discussion ---------- [DI] Allow binary values in parameters. | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #25916 | License | MIT | Doc PR | none yet This adds `binary` type in container xsd definition file Commits ------- cb23134 [DI] Allow binary values in parameters.
2 parents ea6d861 + cb23134 commit 3424cc7

File tree

7 files changed

+19
-0
lines changed

7 files changed

+19
-0
lines changed

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) && !preg_match('/^[^\x00-\x08\x0B\x0E-\x1A\x1C-\x1F\x7F]*+$/u', $value)) {
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' => 'ðððð',
139+
'binary-control-char' => 'This is a Bell char ',
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)