vendor/overblog/graphql-bundle/src/Upload/Type/GraphQLUploadType.php line 21

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Overblog\GraphQLBundle\Upload\Type;
  4. use GraphQL\Error\InvariantViolation;
  5. use GraphQL\Type\Definition\ScalarType;
  6. use ReturnTypeWillChange;
  7. use Symfony\Component\HttpFoundation\File\File;
  8. use function get_class;
  9. use function gettype;
  10. use function is_object;
  11. use function sprintf;
  12. class GraphQLUploadType extends ScalarType
  13. {
  14. /**
  15. * @param string $name
  16. */
  17. public function __construct(string $name = null)
  18. {
  19. parent::__construct([
  20. 'name' => $name,
  21. 'description' => sprintf(
  22. 'The `%s` scalar type represents a file upload object that resolves an object containing `stream`, `filename`, `mimetype` and `encoding`.',
  23. $name
  24. ),
  25. ]);
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. #[ReturnTypeWillChange]
  31. public function parseValue($value)
  32. {
  33. if (null !== $value && !$value instanceof File) {
  34. throw new InvariantViolation(sprintf(
  35. 'Upload should be null or instance of "%s" but %s given.',
  36. File::class,
  37. is_object($value) ? get_class($value) : gettype($value)
  38. ));
  39. }
  40. return $value;
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function serialize($value): void
  46. {
  47. throw new InvariantViolation(sprintf('%s scalar serialization unsupported.', $this->name));
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public function parseLiteral($valueNode, array $variables = null): void
  53. {
  54. throw new InvariantViolation(sprintf('%s scalar literal unsupported.', $this->name));
  55. }
  56. }