|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Baguette\Mastodon\Service; |
|
4
|
|
|
|
|
5
|
|
|
use Respect\Validation\Validator as v; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Toot |
|
9
|
|
|
* |
|
10
|
|
|
* @author USAMI Kenta <[email protected]> |
|
11
|
|
|
* @copyright 2017 Baguette HQ |
|
12
|
|
|
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL-3.0 |
|
13
|
|
|
* @property-read string $toot_string |
|
14
|
|
|
* @property-read int[] $media_ids |
|
15
|
|
|
* @property-read int|null $in_reply_to_id |
|
16
|
|
|
* @property-read string $visibility |
|
17
|
|
|
* @property-read bool|null $sensitive |
|
18
|
|
|
* @property-read string|null $spoiler_text |
|
19
|
|
|
*/ |
|
20
|
|
|
class Toot |
|
21
|
|
|
{ |
|
22
|
|
|
use \Teto\Object\PrivateGetter; |
|
23
|
|
|
use \Teto\Object\ReadOnly; |
|
24
|
|
|
|
|
25
|
|
|
const VISIBILITY_DIRECT = 'direct'; |
|
26
|
|
|
const VISIBILITY_PRIVATE = 'private'; |
|
27
|
|
|
const VISIBILITY_UNLISTED = 'unlisted'; |
|
28
|
|
|
const VISIBILITY_PUBLIC = 'public'; |
|
29
|
|
|
|
|
30
|
|
|
private static $VISIBILITIES = [ |
|
|
|
|
|
|
31
|
|
|
Toot::VISIBILITY_PUBLIC, |
|
32
|
|
|
Toot::VISIBILITY_UNLISTED, |
|
33
|
|
|
Toot::VISIBILITY_PRIVATE, |
|
34
|
|
|
Toot::VISIBILITY_DIRECT, |
|
35
|
|
|
]; |
|
36
|
|
|
|
|
37
|
|
|
/** @var string */ |
|
38
|
|
|
private $toot_string; |
|
39
|
|
|
/** @var int[] */ |
|
40
|
|
|
private $media_ids = []; |
|
41
|
|
|
/** @var int|null */ |
|
42
|
|
|
private $in_reply_to_id; |
|
43
|
|
|
/** @var string|null */ |
|
44
|
|
|
private $visibility; |
|
45
|
|
|
/** @var bool|null */ |
|
46
|
|
|
private $sensitive; |
|
|
|
|
|
|
47
|
|
|
/** @var string|null */ |
|
48
|
|
|
private $spoiler_text; |
|
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param string[] $scopes |
|
|
|
|
|
|
52
|
|
|
*/ |
|
53
|
2 |
|
public function __construct($toot_string, array $options) |
|
54
|
|
|
{ |
|
55
|
2 |
|
v::stringType()->assert($toot_string); |
|
56
|
2 |
|
$this->toot_string = $toot_string; |
|
57
|
|
|
|
|
58
|
2 |
|
if (isset($options['media_ids'])) { |
|
59
|
|
|
$ids = []; |
|
60
|
|
|
foreach ($options['media_ids'] as $id) { |
|
61
|
|
|
v::intType()->assert($id); |
|
62
|
|
|
$ids[] = $id; |
|
63
|
|
|
} |
|
64
|
|
|
$this->media_ids = $ids; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
2 |
|
if (isset($options['in_reply_to_id'])) { |
|
68
|
|
|
v::intType()->assert($options['in_reply_to_id']); |
|
69
|
|
|
$this->in_reply_to_id = $options['in_reply_to_id']; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
2 |
|
if (isset($options['visibility'])) { |
|
73
|
|
|
v::in(Toot::$VISIBILITIES)->assert($options['visibility']); |
|
74
|
|
|
$this->visibility = $options['visibility']; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
2 |
|
if (isset($options['senstitive'])) { |
|
78
|
|
|
v::bool()->assert($options['senstitive']); |
|
79
|
|
|
$this->senstitive = $options['senstitive']; |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
2 |
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @return string |
|
85
|
|
|
*/ |
|
86
|
|
|
public function __toString() |
|
87
|
|
|
{ |
|
88
|
|
|
if ($this->visibility === Toot::VISIBILITY_PUBLIC) { |
|
89
|
|
|
return $this->toot_string; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
return "[{$this->visibility}]"; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.