@@ 18-53 (lines=36) @@ | ||
15 | /** |
|
16 | * @author Sascha-Oliver Prolic <[email protected]> |
|
17 | */ |
|
18 | class KeySearchResults implements CreatableFromArray, \IteratorAggregate |
|
19 | { |
|
20 | /** |
|
21 | * @var KeySearchResult[] |
|
22 | */ |
|
23 | private $searchResults = []; |
|
24 | ||
25 | /** |
|
26 | * @param array $data |
|
27 | * |
|
28 | * @return KeySearchResults |
|
29 | */ |
|
30 | public static function createFromArray(array $data) |
|
31 | { |
|
32 | $self = new self(); |
|
33 | ||
34 | foreach ($data as $searchResult) { |
|
35 | $self->addSearchResult(KeySearchResult::createFromArray($searchResult)); |
|
36 | } |
|
37 | ||
38 | return $self; |
|
39 | } |
|
40 | ||
41 | /** |
|
42 | * @return KeySearchResult[]|\Iterator |
|
43 | */ |
|
44 | public function getIterator(): \Iterator |
|
45 | { |
|
46 | return new \ArrayIterator($this->searchResults); |
|
47 | } |
|
48 | ||
49 | private function addSearchResult(KeySearchResult $searchResult) |
|
50 | { |
|
51 | $this->searchResults[] = $searchResult; |
|
52 | } |
|
53 | } |
|
54 |
@@ 18-53 (lines=36) @@ | ||
15 | /** |
|
16 | * @author Sascha-Oliver Prolic <[email protected]> |
|
17 | */ |
|
18 | class Index implements CreatableFromArray, \IteratorAggregate |
|
19 | { |
|
20 | /** |
|
21 | * @var Translation[] |
|
22 | */ |
|
23 | private $translations = []; |
|
24 | ||
25 | /** |
|
26 | * @param array $data |
|
27 | * |
|
28 | * @return Index |
|
29 | */ |
|
30 | public static function createFromArray(array $data) |
|
31 | { |
|
32 | $self = new self(); |
|
33 | ||
34 | foreach ($data as $translation) { |
|
35 | $self->addTranslation(Translation::createFromArray($translation)); |
|
36 | } |
|
37 | ||
38 | return $self; |
|
39 | } |
|
40 | ||
41 | /** |
|
42 | * @return Translation[]|\Iterator |
|
43 | */ |
|
44 | public function getIterator(): \Iterator |
|
45 | { |
|
46 | return new \ArrayIterator($this->translations); |
|
47 | } |
|
48 | ||
49 | private function addTranslation(Translation $translation) |
|
50 | { |
|
51 | $this->translations[] = $translation; |
|
52 | } |
|
53 | } |
|
54 |