|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the xAPI package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Christian Flothmann <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Xabbuh\XApi\Model; |
|
13
|
|
|
|
|
14
|
|
|
use Xabbuh\XApi\Model\Exception\InvalidStateException; |
|
15
|
|
|
|
|
16
|
|
|
/* |
|
17
|
|
|
* Statement factory eases the creation of complex xAPI statements. |
|
18
|
|
|
* |
|
19
|
|
|
* @author Christian Flothmann <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
final class StatementFactory |
|
22
|
|
|
{ |
|
23
|
|
|
private $id; |
|
24
|
|
|
private $actor; |
|
25
|
|
|
private $verb; |
|
26
|
|
|
private $object; |
|
27
|
|
|
private $result; |
|
28
|
|
|
private $context; |
|
29
|
|
|
private $created; |
|
30
|
|
|
private $stored; |
|
31
|
|
|
private $authority; |
|
32
|
|
|
|
|
33
|
|
|
public function withId(StatementId $id): void |
|
34
|
|
|
{ |
|
35
|
|
|
$this->id = $id; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function withActor(Actor $actor): void |
|
39
|
|
|
{ |
|
40
|
|
|
$this->actor = $actor; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function withVerb(Verb $verb): void |
|
44
|
|
|
{ |
|
45
|
|
|
$this->verb = $verb; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function withObject(StatementObject $object): void |
|
49
|
|
|
{ |
|
50
|
|
|
$this->object = $object; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function withResult(Result $result = null): void |
|
54
|
|
|
{ |
|
55
|
|
|
$this->result = $result; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function withContext(Context $context = null): void |
|
59
|
|
|
{ |
|
60
|
|
|
$this->context = $context; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function withCreated(\DateTime $created = null): void |
|
64
|
|
|
{ |
|
65
|
|
|
$this->created = $created; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function withStored(\DateTime $stored = null): void |
|
69
|
|
|
{ |
|
70
|
|
|
$this->stored = $stored; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function withAuthority(Actor $authority = null): void |
|
74
|
|
|
{ |
|
75
|
|
|
$this->authority = $authority; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Returns a statement based on the current configuration. |
|
80
|
|
|
* |
|
81
|
|
|
* Multiple calls to this method will return different instances. |
|
82
|
|
|
* |
|
83
|
|
|
* @throws InvalidStateException |
|
84
|
|
|
*/ |
|
85
|
|
|
public function createStatement(): Statement |
|
86
|
|
|
{ |
|
87
|
|
|
if (null === $this->actor) { |
|
88
|
|
|
throw new InvalidStateException('A statement actor is missing.'); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
if (null === $this->verb) { |
|
92
|
|
|
throw new InvalidStateException('A statement verb is missing.'); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
if (null === $this->object) { |
|
96
|
|
|
throw new InvalidStateException('A statement object is missing.'); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
return new Statement($this->id, $this->actor, $this->verb, $this->object, $this->result, $this->authority, $this->created, $this->stored, $this->context); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|