1<?php
2
3declare(strict_types=1);
4
5namespace JMS\Serializer\Exclusion;
6
7use JMS\Serializer\Context;
8use JMS\Serializer\Metadata\ClassMetadata;
9use JMS\Serializer\Metadata\PropertyMetadata;
10
11final class VersionExclusionStrategy implements ExclusionStrategyInterface
12{
13    /**
14     * @var string
15     */
16    private $version;
17
18    public function __construct(string $version)
19    {
20        $this->version = $version;
21    }
22
23    /**
24     * {@inheritDoc}
25     */
26    public function shouldSkipClass(ClassMetadata $metadata, Context $navigatorContext): bool
27    {
28        return false;
29    }
30
31    /**
32     * {@inheritDoc}
33     */
34    public function shouldSkipProperty(PropertyMetadata $property, Context $navigatorContext): bool
35    {
36        if ((null !== $version = $property->sinceVersion) && version_compare($this->version, $version, '<')) {
37            return true;
38        }
39
40        if ((null !== $version = $property->untilVersion) && version_compare($this->version, $version, '>')) {
41            return true;
42        }
43
44        return false;
45    }
46}
47