Passed
Push — feature/code-analysis ( e964aa...4fe35d )
by Jonathan
14:33
created

HooksModule   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Importance

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