Collection.php
1.29 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace ACP\ListScreenRepository;
use AC;
use AC\ListScreen;
use AC\ListScreenCollection;
use AC\Type\ListScreenId;
final class Collection implements AC\ListScreenRepository {
/**
* @var ListScreenCollection
*/
private $list_screens;
public function __construct( ListScreenCollection $list_screens ) {
$this->list_screens = $list_screens;
// Since this is in memory only, enforce read only
foreach ( $list_screens as $list_screen ) {
$list_screen->set_read_only( true );
}
}
/**
* @param array $args
*
* @return ListScreenCollection
*/
public function find_all( array $args = [] ) {
$args = array_merge( [
self::KEY => null,
], $args );
$list_screens = new ListScreenCollection();
foreach ( $this->list_screens as $list_screen ) {
if ( $args[ self::KEY ] && $list_screen->get_key() !== $args[ self::KEY ] ) {
continue;
}
$list_screens->add( $list_screen );
}
return $list_screens;
}
/**
* @param ListScreenId $id
*
* @return ListScreen|null
*/
public function find( ListScreenId $id ) {
foreach ( $this->list_screens as $list_screen ) {
if ( $id->equals( $list_screen->get_id() ) ) {
return $list_screen;
}
}
return null;
}
public function exists( ListScreenId $id ) {
return null !== $this->find( $id );
}
}