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($id) |
34
|
|
|
{ |
35
|
|
|
$this->id = $id; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function withActor(Actor $actor) |
39
|
|
|
{ |
40
|
|
|
$this->actor = $actor; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function withVerb(Verb $verb) |
44
|
|
|
{ |
45
|
|
|
$this->verb = $verb; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function withObject(Object $object) |
49
|
|
|
{ |
50
|
|
|
$this->object = $object; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function withResult(Result $result = null) |
54
|
|
|
{ |
55
|
|
|
$this->result = $result; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function withContext(Context $context = null) |
59
|
|
|
{ |
60
|
|
|
$this->context = $context; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function withCreated(\DateTime $created = null) |
64
|
|
|
{ |
65
|
|
|
$this->created = $created; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function withStored(\DateTime $stored = null) |
69
|
|
|
{ |
70
|
|
|
$this->stored = $stored; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function withAuthority(Actor $authority = null) |
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
|
|
|
* @return Statement |
84
|
|
|
* |
85
|
|
|
* @throws InvalidStateException |
86
|
|
|
*/ |
87
|
|
|
public function createStatement() |
88
|
|
|
{ |
89
|
|
|
if (null === $this->actor) { |
90
|
|
|
throw new InvalidStateException('A statement actor is missing.'); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
if (null === $this->verb) { |
94
|
|
|
throw new InvalidStateException('A statement verb is missing.'); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
if (null === $this->object) { |
98
|
|
|
throw new InvalidStateException('A statement object is missing.'); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
return new Statement($this->id, $this->actor, $this->verb, $this->object, $this->result, $this->authority, $this->created, $this->stored, $this->context); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|