forked from LearningLocker/StatementFactory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollection.php
40 lines (29 loc) · 896 Bytes
/
Collection.php
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
<?php namespace Locker\XApi;
use Locker\XApi\Errors\Error as Error;
class Collection extends Atom {
protected $member_type = 'Locker\XApi\Element';
public function setValue($new_value) {
Helpers::checkType('new_value', 'array', $new_value);
$member_type = $this->member_type;
$this->value = array_map(function ($element) use ($member_type) {
return new $member_type($element);
}, $new_value);
return $this;
}
public function getValue() {
$values = [];
foreach ($this->value as $actor) {
$values[] = $actor->getValue();
}
return $values;
}
public function validate() {
$errors = [];
foreach ($this->value as $id => $actor) {
$errors = array_merge($errors, array_map(function (Error $error) use ($id) {
return $error->addTrace((string) $id);
}, $actor->validate()));
}
return $errors;
}
}