Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #38534 [Serializer] make XmlEncoder stateless thus reentrant (con…
…norhu) This PR was merged into the 4.4 branch. Discussion ---------- [Serializer] make XmlEncoder stateless thus reentrant | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #37354 | License | MIT Changing dom property of XmlEncoder to stackable. It fixes a DOMException "Wrong document error". When you calling XmlEncoder->encode() in parallel createDomDocument replaces the DomDocument object. Test code: https://github.com/connorhu/symfony-serializer/blob/master/test.php Commits ------- 693f9ab [Serializer] make XmlEncoder stateless thus reentrant
- Loading branch information
Showing
6 changed files
with
186 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/Symfony/Component/Serializer/Tests/Fixtures/EnvelopeNormalizer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Serializer\Tests\Fixtures; | ||
|
||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | ||
|
||
/** | ||
* @author Karoly Gossler <connor@connor.hu> | ||
*/ | ||
class EnvelopeNormalizer implements NormalizerInterface | ||
{ | ||
private $serializer; | ||
|
||
public function normalize($envelope, $format = null, array $context = []) | ||
{ | ||
$xmlContent = $this->serializer->serialize($envelope->message, 'xml'); | ||
|
||
$encodedContent = base64_encode($xmlContent); | ||
|
||
return [ | ||
'message' => $encodedContent, | ||
]; | ||
} | ||
|
||
public function supportsNormalization($data, $format = null) | ||
{ | ||
return $data instanceof EnvelopeObject; | ||
} | ||
|
||
public function setSerializer($serializer) | ||
{ | ||
$this->serializer = $serializer; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Symfony/Component/Serializer/Tests/Fixtures/EnvelopeObject.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Serializer\Tests\Fixtures; | ||
|
||
/** | ||
* @author Karoly Gossler <connor@connor.hu> | ||
*/ | ||
class EnvelopeObject | ||
{ | ||
public $message; | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Symfony/Component/Serializer/Tests/Fixtures/EnvelopedMessage.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Serializer\Tests\Fixtures; | ||
|
||
/** | ||
* @author Karoly Gossler <connor@connor.hu> | ||
*/ | ||
class EnvelopedMessage | ||
{ | ||
public $text; | ||
} |
32 changes: 32 additions & 0 deletions
32
src/Symfony/Component/Serializer/Tests/Fixtures/EnvelopedMessageNormalizer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Serializer\Tests\Fixtures; | ||
|
||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | ||
|
||
/** | ||
* @author Karoly Gossler <connor@connor.hu> | ||
*/ | ||
class EnvelopedMessageNormalizer implements NormalizerInterface | ||
{ | ||
public function normalize($message, $format = null, array $context = []) | ||
{ | ||
return [ | ||
'text' => $message->text, | ||
]; | ||
} | ||
|
||
public function supportsNormalization($data, $format = null) | ||
{ | ||
return $data instanceof EnvelopedMessage; | ||
} | ||
} |