-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostTag.php
More file actions
64 lines (54 loc) · 1.67 KB
/
Copy pathPostTag.php
File metadata and controls
64 lines (54 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
declare(strict_types=1);
namespace Light\Blog\Entity;
use Doctrine\ORM\Mapping as ORM;
use Light\App\Entity\AbstractEntity;
use Light\Blog\Repository\PostTagRepository;
#[ORM\Entity(repositoryClass: PostTagRepository::class)]
#[ORM\Table(name: 'post_tag')]
#[ORM\UniqueConstraint(name: 'post_tag_unique', columns: ['post_id', 'tag_id'])]
#[ORM\HasLifecycleCallbacks]
class PostTag extends AbstractEntity
{
#[ORM\ManyToOne(targetEntity: Post::class, inversedBy: 'postTags')]
#[ORM\JoinColumn(name: 'post_id', referencedColumnName: 'id', nullable: false)]
private Post $post;
#[ORM\ManyToOne(targetEntity: Tag::class, inversedBy: 'postTags')]
#[ORM\JoinColumn(name: 'tag_id', referencedColumnName: 'id', nullable: false)]
private Tag $tag;
public function getPost(): Post
{
return $this->post;
}
public function setPost(Post $post): void
{
$this->post = $post;
}
public function getTag(): Tag
{
return $this->tag;
}
public function setTag(Tag $tag): void
{
$this->tag = $tag;
}
/**
* @return array{
* id: non-empty-string,
* post: array{id: non-empty-string, title: string, slug: string},
* tag: array{id: non-empty-string, name: string, slug: string}
* }
*/
public function getArrayCopy(): array
{
return [
'id' => $this->id->toString(),
'post' => [
'id' => $this->post->getId()->toString(),
'title' => $this->post->getTitle(),
'slug' => $this->post->getSlug(),
],
'tag' => $this->tag->getArrayCopy(),
];
}
}