35 lines
786 B
PHP
35 lines
786 B
PHP
<?php
|
|
|
|
namespace Domain\Normalizer\Decorator;
|
|
|
|
use Domain\Normalizer\Normalizer;
|
|
|
|
abstract class Decorator implements Normalizer
|
|
{
|
|
abstract protected function getAdditionalHeaders(): array;
|
|
|
|
abstract public function makePass(array $data): array;
|
|
|
|
private function __construct(
|
|
private Normalizer $parent
|
|
)
|
|
{
|
|
}
|
|
|
|
public static function decorate(Normalizer $normalizer): static
|
|
{
|
|
return new static($normalizer);
|
|
}
|
|
|
|
final public function getHeaders(): array
|
|
{
|
|
return array_merge($this->parent->getHeaders(), $this->getAdditionalHeaders());
|
|
}
|
|
|
|
final public function normalize(object $object): array
|
|
{
|
|
$normalized = $this->parent->normalize($object);
|
|
return $this->makePass($normalized);
|
|
}
|
|
}
|