Skip to content

Commit

Permalink
feature #33789 [Serializer] Deprecate the XmlEncoder::TYPE_CASE_ATTRI…
Browse files Browse the repository at this point in the history
…BUTES constant (pierredup)

This PR was merged into the 4.4 branch.

Discussion
----------

[Serializer] Deprecate the XmlEncoder::TYPE_CASE_ATTRIBUTES constant

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | yes
| Tickets       | N/A
| License       | MIT
| Doc PR        | N/A
| Related       | #33788

Deprecate the `XmlEncoder::TYPE_CASE_ATTRIBUTES` constant in favour of `XmlEncoder::TYPE_CAST_ATTRIBUTES`

Commits
-------

9f51cf4 Deprecate the XmlEncoder::TYPE_CASE_ATTRIBUTES constant
  • Loading branch information
fabpot committed Oct 1, 2019
2 parents 11da6f6 + 9f51cf4 commit 5b7848c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/Symfony/Component/Serializer/CHANGELOG.md
@@ -1,6 +1,12 @@
CHANGELOG
=========

4.4.0
-----

* [DEPRECATION] The `XmlEncoder::TYPE_CASE_ATTRIBUTES` constant is deprecated.
Use `XmlEncoder::TYPE_CAST_ATTRIBUTES` instead

4.3.0
-----

Expand Down
7 changes: 5 additions & 2 deletions src/Symfony/Component/Serializer/Encoder/XmlEncoder.php
Expand Up @@ -51,7 +51,10 @@ class XmlEncoder implements EncoderInterface, DecoderInterface, NormalizationAwa
const REMOVE_EMPTY_TAGS = 'remove_empty_tags';
const ROOT_NODE_NAME = 'xml_root_node_name';
const STANDALONE = 'xml_standalone';

/** @deprecated The constant TYPE_CASE_ATTRIBUTES is deprecated since version 4.4 and will be removed in version 5. Use TYPE_CAST_ATTRIBUTES instead. */
const TYPE_CASE_ATTRIBUTES = 'xml_type_cast_attributes';
const TYPE_CAST_ATTRIBUTES = 'xml_type_cast_attributes';
const VERSION = 'xml_version';

private $defaultContext = [
Expand All @@ -61,7 +64,7 @@ class XmlEncoder implements EncoderInterface, DecoderInterface, NormalizationAwa
self::LOAD_OPTIONS => LIBXML_NONET | LIBXML_NOBLANKS,
self::REMOVE_EMPTY_TAGS => false,
self::ROOT_NODE_NAME => 'response',
self::TYPE_CASE_ATTRIBUTES => true,
self::TYPE_CAST_ATTRIBUTES => true,
];

/**
Expand Down Expand Up @@ -335,7 +338,7 @@ private function parseXmlAttributes(\DOMNode $node, array $context = []): array
}

$data = [];
$typeCastAttributes = (bool) ($context[self::TYPE_CASE_ATTRIBUTES] ?? $this->defaultContext[self::TYPE_CASE_ATTRIBUTES]);
$typeCastAttributes = (bool) ($context[self::TYPE_CAST_ATTRIBUTES] ?? $this->defaultContext[self::TYPE_CAST_ATTRIBUTES]);

foreach ($node->attributes as $attr) {
if (!is_numeric($attr->nodeValue) || !$typeCastAttributes || (isset($attr->nodeValue[1]) && '0' === $attr->nodeValue[0])) {
Expand Down

0 comments on commit 5b7848c

Please sign in to comment.