1<?php
2
3declare(strict_types=1);
4
5namespace JMS\Serializer\Naming;
6
7use JMS\Serializer\Metadata\PropertyMetadata;
8
9/**
10 * Naming strategy which uses an annotation to translate the property name.
11 *
12 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
13 */
14final class SerializedNameAnnotationStrategy implements PropertyNamingStrategyInterface
15{
16    /**
17     * @var PropertyNamingStrategyInterface
18     */
19    private $delegate;
20
21    public function __construct(PropertyNamingStrategyInterface $namingStrategy)
22    {
23        $this->delegate = $namingStrategy;
24    }
25
26    /**
27     * {@inheritDoc}
28     */
29    public function translateName(PropertyMetadata $property): string
30    {
31        if (null !== $name = $property->serializedName) {
32            return $name;
33        }
34
35        return $this->delegate->translateName($property);
36    }
37}
38