1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace sweetrdf\InMemoryStoreSqlite\Rdf; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the sweetrdf/InMemoryStoreSqlite package and licensed under |
7
|
|
|
* the terms of the GPL-3 license. |
8
|
|
|
* |
9
|
|
|
* (c) Konrad Abicht <[email protected]> |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please view the LICENSE |
12
|
|
|
* file that was distributed with this source code. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
use Exception; |
16
|
|
|
use rdfInterface\Literal as iLiteral; |
17
|
|
|
use rdfInterface\Term; |
18
|
|
|
use Stringable; |
19
|
|
|
use sweetrdf\InMemoryStoreSqlite\NamespaceHelper; |
20
|
|
|
|
21
|
|
|
class Literal implements iLiteral |
22
|
|
|
{ |
23
|
|
|
private int | float | string | bool | Stringable $value; |
24
|
|
|
|
25
|
|
|
private ?string $lang; |
26
|
|
|
|
27
|
|
|
private ?string $datatype; |
28
|
|
|
|
29
|
6 |
|
public function __construct( |
30
|
|
|
int | float | string | bool | Stringable $value, |
31
|
|
|
?string $lang = null, |
32
|
|
|
?string $datatype = null |
33
|
|
|
) { |
34
|
6 |
|
$this->value = $value; |
35
|
|
|
// TODO later check with feedback on |
36
|
|
|
// https://github.com/sweetrdf/rdfInterface/issues/14 |
37
|
6 |
|
$this->lang = !empty($lang) ? $lang : null; |
38
|
6 |
|
$this->datatype = $datatype ?? NamespaceHelper::NAMESPACE_XSD.'string'; |
39
|
6 |
|
} |
40
|
|
|
|
41
|
2 |
|
public function __toString(): string |
42
|
|
|
{ |
43
|
2 |
|
$langtype = ''; |
44
|
2 |
|
if (!empty($this->lang)) { |
45
|
2 |
|
$langtype = '@'.$this->lang; |
46
|
2 |
|
} elseif (!empty($this->datatype)) { |
47
|
2 |
|
$langtype = "^^<$this->datatype>"; |
48
|
|
|
} |
49
|
|
|
|
50
|
2 |
|
return '"'.$this->value.'"'.$langtype; |
51
|
|
|
} |
52
|
|
|
|
53
|
2 |
|
public function getValue(): int | float | string | bool | Stringable |
54
|
|
|
{ |
55
|
2 |
|
return $this->value; |
56
|
|
|
} |
57
|
|
|
|
58
|
2 |
|
public function getLang(): ?string |
59
|
|
|
{ |
60
|
2 |
|
return $this->lang; |
61
|
|
|
} |
62
|
|
|
|
63
|
2 |
|
public function getDatatype(): string |
64
|
|
|
{ |
65
|
2 |
|
return $this->datatype; |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
1 |
|
public function getType(): string |
69
|
|
|
{ |
70
|
1 |
|
return \rdfInterface\TYPE_LITERAL; |
71
|
|
|
} |
72
|
|
|
|
73
|
1 |
|
public function equals(Term $term): bool |
74
|
|
|
{ |
75
|
1 |
|
return $this == $term; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function withValue(int | float | string | bool | Stringable $value): self |
79
|
|
|
{ |
80
|
|
|
throw new Exception('withValue not implemented yet'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function withLang(?string $lang): self |
84
|
|
|
{ |
85
|
|
|
throw new Exception('withLang not implemented yet'); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function withDatatype(?string $datatype): self |
89
|
|
|
{ |
90
|
|
|
throw new Exception('withDatatype not implemented yet'); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|