Skip to content

Commit

Permalink
Merge pull request #8 from 21TORR/next
Browse files Browse the repository at this point in the history
Make SimpleNormalizer::normalizeArray public.
  • Loading branch information
apfelbox authored Jun 5, 2024
2 parents 6c92699 + 130de49 commit 8252477
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
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

0 comments on commit 8252477

Please sign in to comment.