-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a way to encode+decode CDATA
- Loading branch information
Showing
6 changed files
with
129 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Soap\Encoding\Encoder\Feature; | ||
|
||
interface CData | ||
{ | ||
} |
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,28 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Soap\Encoding\Encoder\SimpleType; | ||
|
||
use Soap\Encoding\Encoder\Context; | ||
use Soap\Encoding\Encoder\Feature; | ||
use Soap\Encoding\Encoder\XmlEncoder; | ||
use VeeWee\Reflecta\Iso\Iso; | ||
|
||
/** | ||
* This encoder works exactly the same as the string encoder. | ||
* However, it implements the CData feature. | ||
* When writing the data to the XML element, it will be wrapped in a CDATA section. | ||
* | ||
* @psalm-suppress UnusedClass | ||
* @implements XmlEncoder<string, string> | ||
*/ | ||
final class CDataTypeEncoder implements Feature\CData, XmlEncoder | ||
{ | ||
/** | ||
* @return Iso<string, string> | ||
*/ | ||
public function iso(Context $context): Iso | ||
{ | ||
return (new StringTypeEncoder())->iso($context); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Soap\Encoding\Test\Unit\Encoder\SimpleType; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use Soap\Encoding\Encoder\ElementEncoder; | ||
use Soap\Encoding\Encoder\SimpleType\CDataTypeEncoder; | ||
use Soap\Encoding\Test\Unit\Encoder\AbstractEncoderTests; | ||
use Soap\Engine\Metadata\Model\XsdType; | ||
|
||
#[CoversClass(CDataTypeEncoder::class)] | ||
final class CDataTypeEncoderTest extends AbstractEncoderTests | ||
{ | ||
public static function provideIsomorphicCases(): iterable | ||
{ | ||
$baseConfig = [ | ||
'encoder' => $encoder = new CDataTypeEncoder(), | ||
'context' => $context = self::createContext( | ||
XsdType::guess('string') | ||
->withXmlTargetNodeName('root') | ||
), | ||
]; | ||
|
||
yield 'simple' => [ | ||
...$baseConfig, | ||
'xml' => 'hello', | ||
'data' => 'hello', | ||
]; | ||
yield 'special-chars' => [ | ||
...$baseConfig, | ||
'xml' => 'hëllo\'"<>', | ||
'data' => 'hëllo\'"<>', | ||
]; | ||
|
||
$elementEncoder = new ElementEncoder($encoder); | ||
yield 'element-wrapped' => [ | ||
...$baseConfig, | ||
'encoder' => $elementEncoder, | ||
'xml' => '<root><![CDATA[hello]]></root>', | ||
'data' => 'hello', | ||
|
||
]; | ||
yield 'element-wrapped-special-chars' => [ | ||
...$baseConfig, | ||
'encoder' => $elementEncoder, | ||
'xml' => '<root><![CDATA[hëllo\'"<>]]></root>', | ||
'data' => 'hëllo\'"<>', | ||
]; | ||
} | ||
} |
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