Total Complexity | 9 |
Total Lines | 57 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
13 | abstract class AbstractTaggable implements TaggableInterface |
||
14 | { |
||
15 | /** |
||
16 | * Override this property in your Entity with definition of ManyToMany relation. |
||
17 | * |
||
18 | * @var ArrayCollection |
||
19 | */ |
||
20 | protected $tags; |
||
21 | |||
22 | /** |
||
23 | * @var string|null |
||
24 | */ |
||
25 | protected $tagsText; |
||
26 | |||
27 | public function __construct() |
||
28 | { |
||
29 | $this->tags = new ArrayCollection(); |
||
30 | } |
||
31 | |||
32 | public function addTag(TagInterface $tag): void |
||
33 | { |
||
34 | $this->tags[] = $tag; |
||
35 | } |
||
36 | |||
37 | public function removeTag(TagInterface $tag): void |
||
38 | { |
||
39 | $this->tags->removeElement($tag); |
||
40 | } |
||
41 | |||
42 | public function hasTag(TagInterface $tag): bool |
||
43 | { |
||
44 | return $this->tags->contains($tag); |
||
45 | } |
||
46 | |||
47 | public function getTags(): iterable |
||
48 | { |
||
49 | return $this->tags; |
||
50 | } |
||
51 | |||
52 | public function getTagNames(): array |
||
53 | { |
||
54 | return empty($this->tagsText) ? [] : \array_map('trim', \explode(',', $this->tagsText)); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Override this method in your Entity and update a field here. |
||
59 | */ |
||
60 | public function setTagsText(?string $tagsText): void |
||
63 | } |
||
64 | |||
65 | public function getTagsText(): ?string |
||
70 | } |
||
71 | } |
||
72 |