DataFormatterFactory.php 936 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\JsonRpc;
  12. use Hyperf\Contract\NormalizerInterface;
  13. use Hyperf\Rpc\Context;
  14. use Hyperf\Serializer\Serializer;
  15. use Hyperf\Serializer\SymfonyNormalizer;
  16. use Psr\Container\ContainerInterface;
  17. class DataFormatterFactory
  18. {
  19. public function __invoke(ContainerInterface $container)
  20. {
  21. /** @var NormalizerInterface $normalizer */
  22. $normalizer = $container->get(NormalizerInterface::class);
  23. $context = $container->get(Context::class);
  24. if ($normalizer instanceof SymfonyNormalizer || $normalizer instanceof Serializer) {
  25. return new NormalizeDataFormatter($normalizer, $context);
  26. }
  27. return new DataFormatter($context);
  28. }
  29. }