ListScreenUninitialized.php
1.12 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
<?php
declare( strict_types=1 );
namespace AC\Admin;
use AC\DefaultColumnsRepository;
use AC\ListScreen;
use AC\ListScreenFactoryInterface;
use AC\Table\ListKeysFactoryInterface;
use AC\Type\ListKey;
class ListScreenUninitialized {
private $default_storage;
private $list_screen_factory;
private $list_keys_factory;
public function __construct(
DefaultColumnsRepository $storage,
ListScreenFactoryInterface $list_screen_factory,
ListKeysFactoryInterface $list_keys_factory
) {
$this->default_storage = $storage;
$this->list_screen_factory = $list_screen_factory;
$this->list_keys_factory = $list_keys_factory;
}
public function find( ListKey $list_key ): ?ListScreen {
if ( $this->default_storage->exists( (string) $list_key ) ) {
return null;
}
if ( ! $this->list_screen_factory->can_create( (string) $list_key ) ) {
return null;
}
return $this->list_screen_factory->create( (string) $list_key );
}
public function find_all(): array {
$list_keys = $this->list_keys_factory->create()->all();
$list_screens = array_map( [ $this, 'find' ], $list_keys );
return array_filter( $list_screens );
}
}