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
<?php
declare(strict_types=1);
namespace Kreait\Firebase\Messaging;
use Kreait\Firebase\Exception\Messaging\InvalidArgument;
final class Topic implements \JsonSerializable
{
private string $value;
private function __construct(string $value)
{
$this->value = $value;
}
public static function fromValue(string $value): self
{
$value = \trim((string) \preg_replace('@^/topic/@', '', $value), '/');
if (\preg_match('/[^a-zA-Z0-9-_.~]$/', $value)) {
throw new InvalidArgument(\sprintf('Malformed topic name "%s".', $value));
}
return new self($value);
}
public function value(): string
{
return $this->value;
}
public function __toString(): string
{
return $this->value;
}
public function jsonSerialize(): string
{
return $this->value;
}
}