49 lines
1.1 KiB
PHP
49 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Ulmus\Api\Stream;
|
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use Psr\Http\Message\StreamInterface;
|
|
use Ulmus\Api\Common\HttpHeaderEnum;
|
|
use Ulmus\Api\Stream\Stream;
|
|
use Ulmus\Api\Common\StreamOutputInterface;
|
|
|
|
# @TODO
|
|
class XmlStream extends Stream
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
}
|
|
|
|
public static function fromContent(mixed $content) : StreamInterface
|
|
{
|
|
#if ( false === $json = json_encode($content) ) {
|
|
# throw new \InvalidArgumentException(sprintf('Json encoding failed with message `%s`.', json_last_error_msg()));
|
|
# }
|
|
|
|
# @TODO !
|
|
|
|
#return static::fromJsonEncoded($json);
|
|
return static::fromXmlEncoded($content);
|
|
}
|
|
|
|
public static function fromXmlEncoded(string $xml) : StreamInterface
|
|
{
|
|
$obj = static::fromTemp($xml);
|
|
$obj->rewind();
|
|
|
|
return $obj;
|
|
}
|
|
|
|
public function decode(): mixed
|
|
{
|
|
$content = $this->getContents();
|
|
|
|
if ($content === "") {
|
|
return null;
|
|
}
|
|
|
|
return json_decode(json_encode((array) \simplexml_load_string($content)), true);
|
|
}
|
|
} |