Files
Heimdall/vendor/phrity/util-transformer/src/Symfony/NormalizerWrapper.php
T
KodeStar d16b7f60f3 Vendor phrity/websocket dependency and fix v3 exception namespace
The WebSocket support added for TrueNAS JSON-RPC 2.0 requires the
phrity/websocket library to actually be available at runtime. This repo
commits the vendor/ tree (CI does not run composer install), so the
dependency and composer.lock must be committed for class_exists() checks
in the TrueNAS app to succeed.

- composer require phrity/websocket:^3.6 (resolves to 3.7.3) with lock
  and vendor/ committed
- Fix TrueNASWebSocketClient to catch WebSocket\Exception\Exception
  (phrity/websocket v3 namespace) instead of the non-existent
  WebSocket\ConnectionException from the old textalk/websocket v1/v2 API,
  so connection/call failures are logged and wrapped as intended
2026-07-09 22:01:18 +01:00

37 lines
1.0 KiB
PHP

<?php
namespace Phrity\Util\Transformer\Symfony;
use Phrity\Util\Transformer\{
TransformerException,
TransformerInterface,
Type,
};
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
class NormalizerWrapper implements TransformerInterface
{
public function __construct(
private NormalizerInterface $normalizer,
) {
}
public function canTransform(mixed $subject, string|null $type = null): bool
{
if (!$this->normalizer->supportsNormalization($subject)) {
return false;
}
return in_array($type, [null, gettype($this->normalizer->normalize($subject))]);
}
public function transform(mixed $subject, string|null $type = null): mixed
{
if (!$this->canTransform($subject, $type)) {
$subjectType = get_debug_type($subject);
$class = get_debug_type($this->normalizer);
throw new TransformerException("Normalizer {$class} to not support '{$subjectType}'.");
}
return $this->normalizer->normalize($subject);
}
}