Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Hydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ interface Hydrator
* @return T
*
* @throws ClassNotSupported if the class is not supported or not found.
* @throws DenormalizationFailure if any normalizers throw an exception.
* @throws TypeMismatch if a TypeError occurs when setting a property value.
* @throws HydratorException Any other thrown exceptions should implement HydratorException.
*
* @template T of object
*/
public function hydrate(string $class, array $data): object;

/** @return array<string, mixed> */
/**
* @return array<string, mixed>
*
* @throws HydratorException
*/
public function extract(object $object): array;
}
4 changes: 3 additions & 1 deletion src/HydratorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Patchlevel\Hydrator;

interface HydratorException
use Throwable;

interface HydratorException extends Throwable
{
}
5 changes: 5 additions & 0 deletions src/HydratorWithContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ interface HydratorWithContext extends Hydrator
* @return T
*
* @throws ClassNotSupported if the class is not supported or not found.
* @throws DenormalizationFailure if any normalizers throw an exception.
* @throws TypeMismatch if a TypeError occurs when setting a property value.
* @throws HydratorException Any other thrown exceptions should implement HydratorException.
*
* @template T of object
*/
Expand All @@ -25,6 +28,8 @@ public function hydrate(string $class, array $data, array $context = []): object
* @param array<string, mixed> $context
*
* @return array<string, mixed>
*
* @throws HydratorException
*/
public function extract(object $object, array $context = []): array;
}
13 changes: 13 additions & 0 deletions src/MetadataHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public function __construct(
*
* @return T
*
* @throws ClassNotSupported if the target class does not exist.
* @throws DenormalizationFailure if any normalizers throw an exception.
* @throws TypeMismatch if a TypeError occurs when setting a property value.
* @throws HydratorException Any other thrown exceptions should implement HydratorException.
*
* @template T of object
*/
public function hydrate(string $class, array $data, array $context = []): object
Expand Down Expand Up @@ -96,6 +101,9 @@ function () use ($metadata, $data, $context): object {
*
* @return T
*
* @throws DenormalizationFailure if any normalizers throw an exception.
* @throws TypeMismatch if a TypeError occurs when setting a property value.
*
* @template T of object
*/
private function doHydrate(ClassMetadata $metadata, array $data, array $context = []): object
Expand Down Expand Up @@ -179,6 +187,11 @@ private function doHydrate(ClassMetadata $metadata, array $data, array $context
* @param array<string, mixed> $context
*
* @return array<string, mixed>
*
* @throws CircularReference
* @throws NormalizationFailure
* @throws NormalizationMissing
* @throws ClassNotFound
*/
public function extract(object $object, array $context = []): array
{
Expand Down
Loading