Passed
Branch main (f9aaf7)
by Jonathan
14:43
created

HooksModule   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 102
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A loadRoutes() 0 11 1
A description() 0 3 1
A getConfigLink() 0 3 1
A title() 0 3 1
A boot() 0 8 1
A customModuleVersion() 0 3 1
A listSubscribedHooks() 0 12 1
1
<?php
2
3
/**
4
 * webtrees-lib: MyArtJaub library for webtrees
5
 *
6
 * @package MyArtJaub\Webtrees
7
 * @subpackage Hooks
8
 * @author Jonathan Jaubart <[email protected]>
9
 * @copyright Copyright (c) 2009-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\Hooks;
16
17
use Aura\Router\Map;
18
use Fisharebest\Webtrees\I18N;
19
use Fisharebest\Webtrees\Module\AbstractModule;
20
use Fisharebest\Webtrees\Module\ModuleConfigInterface;
21
use Fisharebest\Webtrees\Module\ModuleConfigTrait;
22
use Fisharebest\Webtrees\Services\MigrationService;
23
use MyArtJaub\Webtrees\Contracts\Hooks\HookServiceInterface;
24
use MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface;
25
use MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface;
26
use MyArtJaub\Webtrees\Module\ModuleMyArtJaubTrait;
27
use MyArtJaub\Webtrees\Module\Hooks\Hooks\CustomSimpleTagEditorCollector;
28
use MyArtJaub\Webtrees\Module\Hooks\Hooks\FactSourceTextExtenderCollector;
29
use MyArtJaub\Webtrees\Module\Hooks\Hooks\FamilyDatatablesExtenderCollector;
30
use MyArtJaub\Webtrees\Module\Hooks\Hooks\IndividualDatatablesExtenderCollector;
31
use MyArtJaub\Webtrees\Module\Hooks\Hooks\NameAccordionExtenderCollector;
32
use MyArtJaub\Webtrees\Module\Hooks\Hooks\RecordNameTextExtenderCollector;
33
use MyArtJaub\Webtrees\Module\Hooks\Hooks\SosaFamilyDatatablesExtenderCollector;
34
use MyArtJaub\Webtrees\Module\Hooks\Hooks\SosaIndividualDatatablesExtenderCollector;
35
use MyArtJaub\Webtrees\Module\Hooks\Hooks\SosaMissingDatatablesExtenderCollector;
36
use MyArtJaub\Webtrees\Module\Hooks\Http\RequestHandlers\AdminConfigPage;
37
use MyArtJaub\Webtrees\Module\Hooks\Http\RequestHandlers\ModulesHooksAction;
38
use MyArtJaub\Webtrees\Module\Hooks\Http\RequestHandlers\ModulesHooksPage;
39
use MyArtJaub\Webtrees\Module\Hooks\Services\HookService;
40
41
/**
42
 * MyArtJaub Hooks Module
43
 * Provide entry points to extend core webtrees code.
44
 */
45
class HooksModule extends AbstractModule implements
46
    ModuleMyArtJaubInterface,
47
    ModuleConfigInterface,
48
    ModuleHookSubscriberInterface
49
{
50
    use ModuleMyArtJaubTrait {
51
        boot as traitBoot;
52
    }
53
    use ModuleConfigTrait;
54
55
    // How to update the database schema for this module
56
    private const SCHEMA_TARGET_VERSION   = 2;
57
    private const SCHEMA_SETTING_NAME     = 'MAJ_HOOKS_SCHEMA_VERSION';
58
    private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema';
59
60
    /**
61
     * {@inheritDoc}
62
     * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
63
     */
64
    public function title(): string
65
    {
66
        return /* I18N: Name of the “Hooks” module */ I18N::translate('Hooks');
67
    }
68
69
    /**
70
     * {@inheritDoc}
71
     * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
72
     */
73
    public function description(): string
74
    {
75
        return /* I18N: Description of the “Hooks” module */ I18N::translate('Implements hooks management.');
76
    }
77
78
    /**
79
     * {@inheritDoc}
80
     * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
81
     */
82
    public function boot(): void
83
    {
84
        $this->traitBoot();
85
        app()->bind(HookServiceInterface::class, HookService::class);
86
        app(MigrationService::class)->updateSchema(
87
            self::SCHEMA_MIGRATION_PREFIX,
88
            self::SCHEMA_SETTING_NAME,
89
            self::SCHEMA_TARGET_VERSION
90
        );
91
    }
92
93
    /**
94
     * {@inheritDoc}
95
     * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
96
     */
97
    public function loadRoutes(Map $router): void
98
    {
99
        $router->attach('', '', static function (Map $router): void {
100
101
            $router->attach('', '/module-maj/hooks', static function (Map $router): void {
102
103
                $router->attach('', '/config/admin', static function (Map $router): void {
104
105
                    $router->get(AdminConfigPage::class, '', AdminConfigPage::class);
106
                    $router->get(ModulesHooksPage::class, '/{hook_name}', ModulesHooksPage::class);
107
                    $router->post(ModulesHooksAction::class, '/{hook_name}', ModulesHooksAction::class);
108
                });
109
            });
110
        });
111
    }
112
113
    /**
114
     * {@inheritDoc}
115
     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
116
     */
117
    public function customModuleVersion(): string
118
    {
119
        return '2.1.0-v.1';
120
    }
121
122
    /**
123
     * {@inheritDoc}
124
     * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink()
125
     */
126
    public function getConfigLink(): string
127
    {
128
        return route(AdminConfigPage::class);
129
    }
130
131
    /**
132
     * {@inheritDoc}
133
     * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks()
134
     */
135
    public function listSubscribedHooks(): array
136
    {
137
        return [
138
            app()->makeWith(CustomSimpleTagEditorCollector::class, ['module' => $this]),
139
            app()->makeWith(FactSourceTextExtenderCollector::class, ['module' => $this]),
140
            app()->makeWith(FamilyDatatablesExtenderCollector::class, ['module' => $this]),
141
            app()->makeWith(IndividualDatatablesExtenderCollector::class, ['module' => $this]),
142
            app()->makeWith(NameAccordionExtenderCollector::class, ['module' => $this]),
143
            app()->makeWith(RecordNameTextExtenderCollector::class, ['module' => $this]),
144
            app()->makeWith(SosaFamilyDatatablesExtenderCollector::class, ['module' => $this]),
145
            app()->makeWith(SosaIndividualDatatablesExtenderCollector::class, ['module' => $this]),
146
            app()->makeWith(SosaMissingDatatablesExtenderCollector::class, ['module' => $this])
147
        ];
148
    }
149
}
150