Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make SimpleNormalizer::normalizeArray public. #8

Merged
merged 2 commits into from
Jun 5, 2024
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
1.2.2
=====

* (improvement) Make `SimpleNormalizer::normalizeArray` public.


1.2.1
=====

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ public function normalize (object $value, array $context, SimpleNormalizer $norm

return $normalizer->normalize(
$value->value,
\array_replace($context, $value->context),
array_replace($context, $value->context),
);
}


/**
* @inheritDoc
*/
Expand Down
19 changes: 9 additions & 10 deletions src/Normalizer/SimpleNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public function __construct (
private readonly ServiceLocator $objectNormalizers,
) {}


/**
*/
public function normalize (mixed $value, array $context = []) : mixed
Expand All @@ -35,38 +34,39 @@ public function normalize (mixed $value, array $context = []) : mixed
{
try
{
$className = \get_class($value);
$className = $value::class;

if (\class_exists(ClassUtils::class))
if (class_exists(ClassUtils::class))
{
$className = ClassUtils::getRealClass($className);
}

$normalizer = $this->objectNormalizers->get($className);
\assert($normalizer instanceof SimpleObjectNormalizerInterface);

return $normalizer->normalize($value, $context, $this);
}
catch (ServiceNotFoundException $exception)
{
throw new ObjectTypeNotSupportedException(\sprintf(
throw new ObjectTypeNotSupportedException(sprintf(
"Can't normalize type %s",
\get_debug_type($value),
get_debug_type($value),
), 0, $exception);
}
}

throw new UnsupportedTypeException(\sprintf(
throw new UnsupportedTypeException(sprintf(
"Can't normalize type %s",
\get_debug_type($value),
get_debug_type($value),
));
}

/**
*/
private function normalizeArray (array $array, array $context) : array
public function normalizeArray (array $array, array $context) : array
{
$result = [];
$isList = \array_is_list($array);
$isList = array_is_list($array);

foreach ($array as $key => $value)
{
Expand All @@ -93,7 +93,6 @@ private function normalizeArray (array $array, array $context) : array
return $result;
}


/**
* Normalizes a map of values.
* Will JSON-encode to `{}` when empty.
Expand Down
Loading