for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Remorhaz\JSON\Data\Export;
use Remorhaz\JSON\Data\Value\ValueInterface;
use Throwable;
use function json_encode;
use const JSON_THROW_ON_ERROR;
use const JSON_UNESCAPED_SLASHES;
use const JSON_UNESCAPED_UNICODE;
/**
* @todo Don't use decoder
*/
final class ValueEncoder implements ValueEncoderInterface
{
private $decoder;
public function __construct(ValueDecoderInterface $decoder)
$this->decoder = $decoder;
}
public function exportValue(ValueInterface $value): string
$decodedValue = $this
->decoder
->exportValue($value);
try {
return json_encode(
$decodedValue,
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR
);
} catch (Throwable $e) {
throw new Exception\EncodingFailedException($decodedValue, $e);