| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <[email protected]> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | |
| 12 | namespace Symfony\Component\Serializer\Normalizer; |
| 13 | |
| 14 | use Symfony\Component\Serializer\Exception\BadMethodCallException; |
| 15 | use Symfony\Component\Serializer\Exception\ExceptionInterface; |
| 16 | use Symfony\Component\Serializer\Exception\ExtraAttributesException; |
| 17 | use Symfony\Component\Serializer\Exception\InvalidArgumentException; |
| 18 | use Symfony\Component\Serializer\Exception\LogicException; |
| 19 | use Symfony\Component\Serializer\Exception\RuntimeException; |
| 20 | use Symfony\Component\Serializer\Exception\UnexpectedValueException; |
| 21 | |
| 22 | /** |
| 23 | * @author Jordi Boggiano <[email protected]> |
| 24 | */ |
| 25 | interface DenormalizerInterface |
| 26 | { |
| 27 | public const COLLECT_DENORMALIZATION_ERRORS = 'collect_denormalization_errors'; |
| 28 | |
| 29 | /** |
| 30 | * Denormalizes data back into an object of the given class. |
| 31 | * |
| 32 | * @template TObject of object |
| 33 | * |
| 34 | * @param mixed $data Data to restore |
| 35 | * @param class-string<TObject>|string $type The expected class to instantiate |
| 36 | * @param string|null $format Format the given data was extracted from |
| 37 | * @param array<string, mixed> $context Options available to the denormalizer |
| 38 | * |
| 39 | * @return ($type is class-string<TObject> ? TObject : mixed) |
| 40 | * |
| 41 | * @throws BadMethodCallException Occurs when the normalizer is not called in an expected context |
| 42 | * @throws InvalidArgumentException Occurs when the arguments are not coherent or not supported |
| 43 | * @throws UnexpectedValueException Occurs when the item cannot be hydrated with the given data |
| 44 | * @throws ExtraAttributesException Occurs when the item doesn't have attribute to receive given data |
| 45 | * @throws LogicException Occurs when the normalizer is not supposed to denormalize |
| 46 | * @throws RuntimeException Occurs if the class cannot be instantiated |
| 47 | * @throws ExceptionInterface Occurs for all the other cases of errors |
| 48 | */ |
| 49 | public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed; |
| 50 | |
| 51 | /** |
| 52 | * Checks whether the given class is supported for denormalization by this normalizer. |
| 53 | * |
| 54 | * @param mixed $data Data to denormalize from |
| 55 | * @param string $type The class to which the data should be denormalized |
| 56 | * @param string|null $format The format being deserialized from |
| 57 | * @param array<string, mixed> $context Options available to the denormalizer |
| 58 | */ |
| 59 | public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool; |
| 60 | |
| 61 | /** |
| 62 | * Returns the types potentially supported by this denormalizer. |
| 63 | * |
| 64 | * For each supported formats (if applicable), the supported types should be |
| 65 | * returned as keys, and each type should be mapped to a boolean indicating |
| 66 | * if the result of supportsDenormalization() can be cached or not |
| 67 | * (a result cannot be cached when it depends on the context or on the data.) |
| 68 | * A null value means that the denormalizer does not support the corresponding |
| 69 | * type. |
| 70 | * |
| 71 | * Use type "object" to match any classes or interfaces, |
| 72 | * and type "*" to match any types. |
| 73 | * |
| 74 | * @return array<class-string|'*'|'object'|string, bool|null> |
| 75 | */ |
| 76 | public function getSupportedTypes(?string $format): array; |
| 77 | } |