|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Blackmine\Model\Project; |
|
4
|
|
|
|
|
5
|
|
|
use Blackmine\Collection\HierarchyCollection; |
|
6
|
|
|
use Blackmine\Collection\IdentityCollection; |
|
7
|
|
|
use Blackmine\Model\FetchableInterface; |
|
8
|
|
|
use Blackmine\Model\Identity; |
|
9
|
|
|
use Blackmine\Model\Issue\Attachment; |
|
10
|
|
|
use Blackmine\Model\ParentableInterface; |
|
11
|
|
|
use Blackmine\Model\User\User; |
|
12
|
|
|
use Blackmine\Mutator\MutableInterface; |
|
13
|
|
|
use Blackmine\Mutator\Mutation\AddSubkeyMutation; |
|
14
|
|
|
use Blackmine\Mutator\Mutation\RemoveKeyMutation; |
|
15
|
|
|
use Blackmine\Mutator\Mutation\RenameKeyMutation; |
|
16
|
|
|
use Blackmine\Repository\Projects\WikiPages; |
|
17
|
|
|
use Carbon\CarbonImmutable; |
|
18
|
|
|
use Doctrine\Common\Collections\Collection; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @method void setTitle(string $title) |
|
22
|
|
|
* @method void setText(string $text) |
|
23
|
|
|
* @method void setComments(string $comments) |
|
24
|
|
|
* @method void setAuthor(User $author) |
|
25
|
|
|
* @method void setRevisions(IdentityCollection $revisions) |
|
26
|
|
|
* |
|
27
|
|
|
* @method string getTitle() |
|
28
|
|
|
* @method string getText() |
|
29
|
|
|
* @method int getVersion() |
|
30
|
|
|
* @method string getComments() |
|
31
|
|
|
* @method IdentityCollection getAttachments() |
|
32
|
|
|
* @method IdentityCollection getRevisions() |
|
33
|
|
|
* @method CarbonImmutable getCreatedOn() |
|
34
|
|
|
* @method CarbonImmutable getUpdatedOn() |
|
35
|
|
|
* |
|
36
|
|
|
* @method void addAttachment(Attachment $attachment) |
|
37
|
|
|
* @method void removeAttachment(Attachment $attachment) |
|
38
|
|
|
* @method void removeRevision(WikiPage $revision); |
|
39
|
|
|
*/ |
|
40
|
|
|
class WikiPage extends Identity implements FetchableInterface, MutableInterface, ParentableInterface |
|
41
|
|
|
{ |
|
42
|
|
|
public const ENTITY_NAME = "wiki_page"; |
|
43
|
|
|
|
|
44
|
|
|
protected string $title; |
|
45
|
|
|
protected string $text; |
|
46
|
|
|
protected int $version; |
|
47
|
|
|
protected string $comments; |
|
48
|
|
|
|
|
49
|
|
|
protected ?WikiPage $parent = null; |
|
50
|
|
|
protected User $author; |
|
51
|
|
|
|
|
52
|
|
|
protected ?IdentityCollection $attachments; |
|
53
|
|
|
protected ?IdentityCollection $revisions; |
|
54
|
|
|
protected ?HierarchyCollection $children; |
|
55
|
|
|
|
|
56
|
|
|
protected CarbonImmutable $created_on; |
|
57
|
|
|
protected CarbonImmutable $updated_on; |
|
58
|
|
|
|
|
59
|
|
|
public function __construct(protected ?int $id = null) |
|
60
|
|
|
{ |
|
61
|
|
|
$this->attachments = new IdentityCollection(); |
|
62
|
|
|
$this->revisions = new IdentityCollection(); |
|
63
|
|
|
$this->children = new HierarchyCollection(parent_field: "title"); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function getId(): mixed |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->title; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public static function getRepositoryClass(): ?string |
|
72
|
|
|
{ |
|
73
|
|
|
return WikiPages::class; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function getMutations(): array |
|
77
|
|
|
{ |
|
78
|
|
|
return [ |
|
79
|
|
|
"parent_id" => [ |
|
80
|
|
|
AddSubkeyMutation::class => ["title"], |
|
81
|
|
|
RenameKeyMutation::class => ["parent"], |
|
82
|
|
|
], |
|
83
|
|
|
"attachments" => [RenameKeyMutation::class => ["uploads"]], |
|
84
|
|
|
"created_on" => [RemoveKeyMutation::class => []], |
|
85
|
|
|
"updated_on" => [RemoveKeyMutation::class => []] |
|
86
|
|
|
]; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function addRevision(WikiPage $revision): void |
|
90
|
|
|
{ |
|
91
|
|
|
if (!$this->revisions->contains($revision)) { |
|
|
|
|
|
|
92
|
|
|
$this->revisions->add($revision); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
public function getParent(): ?ParentableInterface |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->parent; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function setParent(ParentableInterface | array $parent): void |
|
103
|
|
|
{ |
|
104
|
|
|
$this->parent = $this->normalizeValue("parent", __CLASS__, $parent); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function getChildren(): Collection |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->children; |
|
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
public function addChild(ParentableInterface $child): void |
|
113
|
|
|
{ |
|
114
|
|
|
$child->setParent($this); |
|
115
|
|
|
$this->children->addDirect($child); |
|
|
|
|
|
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
public function removeChild(ParentableInterface $child): void |
|
119
|
|
|
{ |
|
120
|
|
|
if ($this->children->contains($child)) { |
|
121
|
|
|
$this->children->removeElement($child); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function isPersisted(): bool |
|
126
|
|
|
{ |
|
127
|
|
|
return is_initialized($this, "version") && $this->version > 0; |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.