-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.php
More file actions
140 lines (122 loc) · 3.49 KB
/
Copy pathNode.php
File metadata and controls
140 lines (122 loc) · 3.49 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
/**
* Italix Documents - Node
*
* @package Italix\Documents
*/
declare(strict_types=1);
namespace Italix\Documents;
/**
* A folder or a document in a tree. Immutable; a change produces a new row and
* a new value object.
*/
final class Node
{
public const KIND_FOLDER = 'folder';
public const KIND_DOCUMENT = 'document';
private int $id;
private int $tree_id;
private ?int $parent_id;
private string $kind_c;
private string $name_c;
private string $path_c;
private ?int $latest_version_id;
private ?string $lang_c;
private ?int $translation_of_node_id;
private bool $is_published;
public function __construct(
int $id,
int $tree_id,
?int $parent_id,
string $kind_c,
string $name_c,
string $path_c,
?int $latest_version_id = null,
?string $lang_c = null,
?int $translation_of_node_id = null,
bool $is_published = true
) {
$this->id = $id;
$this->tree_id = $tree_id;
$this->parent_id = $parent_id;
$this->kind_c = $kind_c;
$this->name_c = $name_c;
$this->path_c = $path_c;
$this->latest_version_id = $latest_version_id;
$this->lang_c = $lang_c;
$this->translation_of_node_id = $translation_of_node_id;
$this->is_published = $is_published;
}
/**
* @param array<string, mixed> $row
*/
public static function from_row(array $row): self
{
return new self(
(int) $row['id'],
(int) $row['tree_id'],
$row['parent_id'] === null ? null : (int) $row['parent_id'],
(string) $row['kind_c'],
(string) $row['name_c'],
(string) $row['path_c'],
$row['latest_version_id'] === null ? null : (int) $row['latest_version_id'],
$row['lang_c'] === null || $row['lang_c'] === '' ? null : (string) $row['lang_c'],
$row['translation_of_node_id'] === null ? null : (int) $row['translation_of_node_id'],
(bool) $row['is_published']
);
}
public function id(): int
{
return $this->id;
}
public function tree_id(): int
{
return $this->tree_id;
}
public function parent_id(): ?int
{
return $this->parent_id;
}
public function kind_code(): string
{
return $this->kind_c;
}
public function is_folder(): bool
{
return $this->kind_c === self::KIND_FOLDER;
}
public function name(): string
{
return $this->name_c;
}
public function path(): string
{
return $this->path_c;
}
public function latest_version_id(): ?int
{
return $this->latest_version_id;
}
/** BCP-47, or null for language-neutral content. */
public function lang_code(): ?string
{
return $this->lang_c;
}
public function translation_of_node_id(): ?int
{
return $this->translation_of_node_id;
}
public function is_published(): bool
{
return $this->is_published;
}
public function extension_code(): string
{
return Path::extension_of($this->path_c);
}
}