|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* webtrees-lib: MyArtJaub library for webtrees |
|
5
|
|
|
* |
|
6
|
|
|
* @package MyArtJaub\Webtrees |
|
7
|
|
|
* @subpackage GeoDispersion |
|
8
|
|
|
* @author Jonathan Jaubart <[email protected]> |
|
9
|
|
|
* @copyright Copyright (c) 2021, Jonathan Jaubart |
|
10
|
|
|
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
declare(strict_types=1); |
|
14
|
|
|
|
|
15
|
|
|
namespace MyArtJaub\Webtrees\Module\GeoDispersion\Services; |
|
16
|
|
|
|
|
17
|
|
|
use Fisharebest\Webtrees\Registry; |
|
18
|
|
|
use Fisharebest\Webtrees\Services\ModuleService; |
|
19
|
|
|
use Illuminate\Support\Collection; |
|
20
|
|
|
use MyArtJaub\Webtrees\Contracts\GeoDispersion\MapDefinitionInterface; |
|
21
|
|
|
use MyArtJaub\Webtrees\Contracts\GeoDispersion\ModuleMapDefinitionProviderInterface; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Service for accessing map definitions . |
|
25
|
|
|
*/ |
|
26
|
|
|
class MapDefinitionsService |
|
27
|
|
|
{ |
|
28
|
|
|
private ModuleService $module_service; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Constructor for MapDefinitionsService |
|
32
|
|
|
* |
|
33
|
|
|
* @param ModuleService $module_service |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct(ModuleService $module_service) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->module_service = $module_service; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Find a map definition by ID. |
|
42
|
|
|
* |
|
43
|
|
|
* @param string $id |
|
44
|
|
|
* @return MapDefinitionInterface|NULL |
|
45
|
|
|
*/ |
|
46
|
|
|
public function find(string $id): ?MapDefinitionInterface |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->all()->get($id); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Get all map definitions available. |
|
53
|
|
|
* |
|
54
|
|
|
* {@internal The list is generated based on the modules exposing ModuleMapDefinitionProviderInterface, |
|
55
|
|
|
* and the result is cached} |
|
56
|
|
|
* |
|
57
|
|
|
* @param bool $include_disabled |
|
58
|
|
|
* @return Collection<string, MapDefinitionInterface> |
|
59
|
|
|
*/ |
|
60
|
|
|
public function all(bool $include_disabled = false): Collection |
|
61
|
|
|
{ |
|
62
|
|
|
return Registry::cache()->array()->remember( |
|
63
|
|
|
'maj-geodisp-maps-all', |
|
64
|
|
|
fn() => $this->module_service |
|
65
|
|
|
->findByInterface(ModuleMapDefinitionProviderInterface::class, $include_disabled) |
|
66
|
|
|
->flatMap(fn(ModuleMapDefinitionProviderInterface $module) => $module->listMapDefinition()) |
|
67
|
|
|
->mapWithKeys(fn(MapDefinitionInterface $map) => [ $map->id() => $map ]) |
|
68
|
|
|
); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|