vendor/api-platform/core/src/Metadata/Link.php line 17

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the API Platform project.
  4.  *
  5.  * (c) Kévin Dunglas <dunglas@gmail.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace ApiPlatform\Metadata;
  12. #[\Attribute(\Attribute::TARGET_PROPERTY \Attribute::TARGET_METHOD \Attribute::TARGET_PARAMETER)]
  13. final class Link
  14. {
  15.     public function __construct(private ?string $parameterName null, private ?string $fromProperty null, private ?string $toProperty null, private ?string $fromClass null, private ?string $toClass null, private ?array $identifiers null, private ?bool $compositeIdentifier null, private ?string $expandedValue null)
  16.     {
  17.         // For the inverse property shortcut
  18.         if ($this->parameterName && class_exists($this->parameterName)) {
  19.             $this->fromClass $this->parameterName;
  20.         }
  21.     }
  22.     public function getParameterName(): ?string
  23.     {
  24.         return $this->parameterName;
  25.     }
  26.     public function withParameterName(string $parameterName): self
  27.     {
  28.         $self = clone $this;
  29.         $self->parameterName $parameterName;
  30.         return $self;
  31.     }
  32.     public function getFromClass(): ?string
  33.     {
  34.         return $this->fromClass;
  35.     }
  36.     public function withFromClass(string $fromClass): self
  37.     {
  38.         $self = clone $this;
  39.         $self->fromClass $fromClass;
  40.         return $self;
  41.     }
  42.     public function getToClass(): ?string
  43.     {
  44.         return $this->toClass;
  45.     }
  46.     public function withToClass(string $toClass): self
  47.     {
  48.         $self = clone $this;
  49.         $self->toClass $toClass;
  50.         return $self;
  51.     }
  52.     public function getFromProperty(): ?string
  53.     {
  54.         return $this->fromProperty;
  55.     }
  56.     public function withFromProperty(string $fromProperty): self
  57.     {
  58.         $self $this;
  59.         $self->fromProperty $fromProperty;
  60.         return $self;
  61.     }
  62.     public function getToProperty(): ?string
  63.     {
  64.         return $this->toProperty;
  65.     }
  66.     public function withToProperty(string $toProperty): self
  67.     {
  68.         $self = clone $this;
  69.         $self->toProperty $toProperty;
  70.         return $self;
  71.     }
  72.     public function getIdentifiers(): ?array
  73.     {
  74.         return $this->identifiers;
  75.     }
  76.     public function withIdentifiers(array $identifiers): self
  77.     {
  78.         $self = clone $this;
  79.         $self->identifiers $identifiers;
  80.         return $self;
  81.     }
  82.     public function getCompositeIdentifier(): ?bool
  83.     {
  84.         return $this->compositeIdentifier;
  85.     }
  86.     public function withCompositeIdentifier(bool $compositeIdentifier): self
  87.     {
  88.         $self = clone $this;
  89.         $self->compositeIdentifier $compositeIdentifier;
  90.         return $self;
  91.     }
  92.     public function getExpandedValue(): ?string
  93.     {
  94.         return $this->expandedValue;
  95.     }
  96.     public function withExpandedValue(string $expandedValue): self
  97.     {
  98.         $self = clone $this;
  99.         $self->expandedValue $expandedValue;
  100.         return $self;
  101.     }
  102.     public function withLink(self $link): self
  103.     {
  104.         $self = clone $this;
  105.         if (!$self->getToProperty() && ($toProperty $link->getToProperty())) {
  106.             $self->toProperty $toProperty;
  107.         }
  108.         if (!$self->getCompositeIdentifier() && ($compositeIdentifier $link->getCompositeIdentifier())) {
  109.             $self->compositeIdentifier $compositeIdentifier;
  110.         }
  111.         if (!$self->getFromClass() && ($fromClass $link->getFromClass())) {
  112.             $self->fromClass $fromClass;
  113.         }
  114.         if (!$self->getToClass() && ($toClass $link->getToClass())) {
  115.             $self->toClass $toClass;
  116.         }
  117.         if (!$self->getIdentifiers() && ($identifiers $link->getIdentifiers())) {
  118.             $self->identifiers $identifiers;
  119.         }
  120.         if (!$self->getFromProperty() && ($fromProperty $link->getFromProperty())) {
  121.             $self->fromProperty $fromProperty;
  122.         }
  123.         if (!$self->getParameterName() && ($parameterName $link->getParameterName())) {
  124.             $self->parameterName $parameterName;
  125.         }
  126.         if (!$self->getExpandedValue() && ($expandedValue $link->getExpandedValue())) {
  127.             $self->expandedValue $expandedValue;
  128.         }
  129.         return $self;
  130.     }
  131. }