|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Doctrine\Tests\ORM\Functional\Ticket\GH12225; |
| 6 | + |
| 7 | +use DateTimeImmutable; |
| 8 | +use Doctrine\Common\Collections\ArrayCollection; |
| 9 | +use Doctrine\Common\Collections\Collection; |
| 10 | +use Doctrine\ORM\Mapping\Column; |
| 11 | +use Doctrine\ORM\Mapping\DiscriminatorColumn; |
| 12 | +use Doctrine\ORM\Mapping\DiscriminatorMap; |
| 13 | +use Doctrine\ORM\Mapping\Entity; |
| 14 | +use Doctrine\ORM\Mapping\GeneratedValue; |
| 15 | +use Doctrine\ORM\Mapping\Id; |
| 16 | +use Doctrine\ORM\Mapping\Index; |
| 17 | +use Doctrine\ORM\Mapping\InheritanceType; |
| 18 | +use Doctrine\ORM\Mapping\ManyToOne; |
| 19 | +use Doctrine\ORM\Mapping\OneToMany; |
| 20 | +use Doctrine\ORM\Mapping\Table; |
| 21 | + |
| 22 | +/** |
| 23 | + * @Entity |
| 24 | + * @Table(name="gh_12225_directory", indexes={@Index(columns={"dir_key"})}) |
| 25 | + * @InheritanceType("SINGLE_TABLE") |
| 26 | + * @DiscriminatorColumn(name="type", type="string") |
| 27 | + * @DiscriminatorMap({"main" = ConcreteDirectory::class}) |
| 28 | + */ |
| 29 | +#[Entity] |
| 30 | +#[Table(name: 'gh_12225_directory')] |
| 31 | +#[Index(columns: ['dir_key'])] |
| 32 | +#[InheritanceType('SINGLE_TABLE')] |
| 33 | +#[DiscriminatorColumn(name: 'type', type: 'string')] |
| 34 | +#[DiscriminatorMap(['main' => ConcreteDirectory::class])] |
| 35 | +class AbstractDirectory |
| 36 | +{ |
| 37 | + /** |
| 38 | + * @var int |
| 39 | + * @Id |
| 40 | + * @GeneratedValue |
| 41 | + * @Column(name="id", type="integer") |
| 42 | + */ |
| 43 | + #[Id] |
| 44 | + #[GeneratedValue] |
| 45 | + #[Column(name: 'id', type: 'integer')] |
| 46 | + private $id; |
| 47 | + |
| 48 | + /** |
| 49 | + * @var string |
| 50 | + * @Column(name="dir_key", type="string") |
| 51 | + */ |
| 52 | + #[Column(name: 'dir_key', type: 'string')] |
| 53 | + private $dirKey; |
| 54 | + |
| 55 | + /** |
| 56 | + * @var DateTimeImmutable|null |
| 57 | + * @Column(name="deleted_at", type="datetime_immutable", nullable=true) |
| 58 | + */ |
| 59 | + #[Column(name: 'deleted_at', type: 'datetime_immutable', nullable: true)] |
| 60 | + private $deletedAt = null; |
| 61 | + |
| 62 | + /** |
| 63 | + * @var AbstractDirectory|null |
| 64 | + * @ManyToOne(targetEntity=AbstractDirectory::class, fetch="LAZY", inversedBy="directories") |
| 65 | + */ |
| 66 | + #[ManyToOne(targetEntity: self::class, fetch: 'LAZY', inversedBy: 'directories')] |
| 67 | + private $parent = null; |
| 68 | + |
| 69 | + /** |
| 70 | + * @var Collection<string, self> |
| 71 | + * @OneToMany(mappedBy="parent", targetEntity=AbstractDirectory::class, fetch="EXTRA_LAZY", indexBy="dirKey") |
| 72 | + */ |
| 73 | + #[OneToMany(mappedBy: 'parent', targetEntity: self::class, fetch: 'EXTRA_LAZY', indexBy: 'dirKey')] |
| 74 | + private $children; |
| 75 | + |
| 76 | + public function __construct(string $dirKey) |
| 77 | + { |
| 78 | + $this->dirKey = $dirKey; |
| 79 | + $this->children = new ArrayCollection(); |
| 80 | + } |
| 81 | + |
| 82 | + public function getId(): int |
| 83 | + { |
| 84 | + return $this->id; |
| 85 | + } |
| 86 | + |
| 87 | + public function getDirKey(): string |
| 88 | + { |
| 89 | + return $this->dirKey; |
| 90 | + } |
| 91 | + |
| 92 | + public function getDeletedAt(): ?DateTimeImmutable |
| 93 | + { |
| 94 | + return $this->deletedAt; |
| 95 | + } |
| 96 | + |
| 97 | + public function setDeletedAt(?DateTimeImmutable $deletedAt): AbstractDirectory |
| 98 | + { |
| 99 | + $this->deletedAt = $deletedAt; |
| 100 | + |
| 101 | + return $this; |
| 102 | + } |
| 103 | + |
| 104 | + public function getParent(): ?AbstractDirectory |
| 105 | + { |
| 106 | + return $this->parent; |
| 107 | + } |
| 108 | + |
| 109 | + public function setParent(?AbstractDirectory $parent): AbstractDirectory |
| 110 | + { |
| 111 | + $this->parent = $parent; |
| 112 | + |
| 113 | + return $this; |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * @return Collection<string, self> |
| 118 | + */ |
| 119 | + public function getChildren(): Collection |
| 120 | + { |
| 121 | + return $this->children; |
| 122 | + } |
| 123 | +} |
0 commit comments