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\Services\ModuleService; |
18
|
|
|
use Illuminate\Contracts\Container\BindingResolutionException; |
19
|
|
|
use Illuminate\Support\Collection; |
20
|
|
|
use MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface; |
21
|
|
|
use MyArtJaub\Webtrees\Contracts\GeoDispersion\ModuleGeoAnalysisProviderInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Service for accessing available geographical dispersion analyses. |
25
|
|
|
*/ |
26
|
|
|
class GeoAnalysisService |
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
|
|
|
* Get all available geographical dispersion analyses. |
42
|
|
|
* |
43
|
|
|
* {@internal The list is generated based on the modules exposing ModuleGeoAnalysisProviderInterface |
44
|
|
|
* |
45
|
|
|
* @param bool $include_disabled |
46
|
|
|
* @return Collection |
47
|
|
|
*/ |
48
|
|
|
public function all(bool $include_disabled = false): Collection |
49
|
|
|
{ |
50
|
|
|
return $this->module_service |
51
|
|
|
->findByInterface(ModuleGeoAnalysisProviderInterface::class, $include_disabled) |
52
|
|
|
->flatMap(fn(ModuleGeoAnalysisProviderInterface $module) => $module->listGeoAnalyses()) |
53
|
|
|
->map(static function (string $analysis_class): ?GeoAnalysisInterface { |
54
|
|
|
try { |
55
|
|
|
$analysis = app($analysis_class); |
56
|
|
|
return $analysis instanceof GeoAnalysisInterface ? $analysis : null; |
57
|
|
|
} catch (BindingResolutionException $ex) { |
58
|
|
|
return null; |
59
|
|
|
} |
60
|
|
|
})->filter(); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|