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\Common\Exception\UnsupportedOperationException; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* xAPI statement extensions. |
18
|
|
|
* |
19
|
|
|
* @author Christian Flothmann <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
final class Extensions implements \ArrayAccess |
22
|
|
|
{ |
23
|
|
|
private $extensions; |
24
|
|
|
|
25
|
|
|
public function __construct(array $extensions) |
26
|
|
|
{ |
27
|
|
|
$this->extensions = $extensions; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
|
|
public function offsetExists($offset) |
34
|
|
|
{ |
35
|
|
|
return isset($this->extensions[$offset]); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritdoc} |
40
|
|
|
*/ |
41
|
|
|
public function offsetGet($offset) |
42
|
|
|
{ |
43
|
|
|
if (!isset($this->extensions[$offset])) { |
44
|
|
|
throw new \InvalidArgumentException(sprintf('No extension for key "%s" registered.', $offset)); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $this->extensions[$offset]; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
|
|
public function offsetSet($offset, $value) |
54
|
|
|
{ |
55
|
|
|
throw new UnsupportedOperationException('xAPI statement extensions are immutable.'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inheritdoc} |
60
|
|
|
*/ |
61
|
|
|
public function offsetUnset($offset) |
62
|
|
|
{ |
63
|
|
|
throw new UnsupportedOperationException('xAPI statement extensions are immutable.'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function getExtensions() |
67
|
|
|
{ |
68
|
|
|
return $this->extensions; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function equals(Extensions $otherExtensions) |
72
|
|
|
{ |
73
|
|
|
if (count($this->extensions) !== count($otherExtensions->extensions)) { |
74
|
|
|
return false; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
foreach ($this->extensions as $key => $value) { |
78
|
|
|
if (!array_key_exists($key, $otherExtensions->extensions)) { |
79
|
|
|
return false; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
if ($this->extensions[$key] != $otherExtensions[$key]) { |
83
|
|
|
return false; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return true; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|