Passed
Branch feature/2.0 (ef99fd)
by Jonathan
11:25
created

AbstractModuleMaj   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 83
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A resourcesFolder() 0 3 1
A moduleCssUrl() 0 11 2
A customModuleSupportUrl() 0 3 1
A boot() 0 5 1
A customTranslations() 0 10 2
A customModuleAuthorName() 0 3 1
1
<?php
2
/**
3
 * webtrees-lib: MyArtJaub library for webtrees
4
 *
5
 * @package MyArtJaub\Webtrees
6
 * @author Jonathan Jaubart <[email protected]>
7
 * @copyright Copyright (c) 2020, Jonathan Jaubart
8
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3
9
 */
10
declare(strict_types=1);
11
12
namespace MyArtJaub\Webtrees\Module;
13
14
use Aura\Router\Map;
15
use Aura\Router\RouterContainer;
16
use Fisharebest\Localization\Translation;
17
use Fisharebest\Webtrees\View;
18
use Fisharebest\Webtrees\Webtrees;
19
use Fisharebest\Webtrees\Module\AbstractModule;
20
use Fisharebest\Webtrees\Module\ModuleCustomInterface;
21
use Fisharebest\Webtrees\Module\ModuleCustomTrait;
22
use Fisharebest\Webtrees\Module\ModuleThemeInterface;
23
24
/**
25
 * MyArtJaub Module
26
 */
27
abstract class AbstractModuleMaj extends AbstractModule implements ModuleCustomInterface
28
{    
29
    use ModuleCustomTrait;
30
    
31
    /**
32
     * {@inheritDoc}
33
     * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
34
     */
35
    public function boot() : void
36
    {
37
        View::registerNamespace($this->name(), $this->resourcesFolder() . 'views/');
38
        
39
        $this->loadRoutes(app(RouterContainer::class)->getMap());
40
    }
41
    
42
    /**
43
     * {@inheritDoc}
44
     * @see \Fisharebest\Webtrees\Module\AbstractModule::resourcesFolder()
45
     */
46
    public function resourcesFolder(): string
47
    {
48
        return Webtrees::MODULES_DIR . trim($this->name(), '_') . '/resources/';
49
    }
50
    
51
    /**
52
     * {@inheritDoc}
53
     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleAuthorName()
54
     */
55
    public function customModuleAuthorName() : string
56
    {
57
        return 'Jonathan Jaubart';
58
    }
59
    
60
    /**
61
     * {@inheritDoc}
62
     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleSupportUrl()
63
     */
64
    public function customModuleSupportUrl() : string
65
    {
66
        return 'https://github.com/jon48/webtrees-lib';
67
    }
68
    
69
    /**
70
     * {@inheritDoc}
71
     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customTranslations()
72
     */
73
    public function customTranslations(string $language) : array
74
    {
75
        $translation_file = $this->resourcesFolder() . 'lang/' . $language . '/messages.php';
76
        
77
        try {
78
            $translation  = new Translation($translation_file);
79
            return $translation->asArray();
80
        } catch (\Exception $e) { }
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
81
        
82
        return array();
83
    }
84
    
85
    /**
86
     * Add module routes to webtrees route loader
87
     * 
88
     * @param Map $router
89
     */
90
    public abstract function loadRoutes(Map $router) : void;
91
    
92
    /**
93
     * Returns the URL of the module specific stylesheets.
94
     * It will look for a CSS file matching the theme name (e.g. xenea.min.css),
95
     * and fallback to default.min.css if none are found
96
     * 
97
     * @return string
98
     */
99
    public function moduleCssUrl() : string
100
    {
101
        /** @var ModuleThemeInterface $theme */
102
        $theme = app(ModuleThemeInterface::class);
103
        $css_file = $this->resourcesFolder() . 'css/' . $theme->name() . '.min.css';
104
        
105
        if(file_exists($css_file)) {
106
            return $this->assetUrl('css/' . $theme->name() . '.min.css');
107
        }
108
        else {
109
            return $this->assetUrl('css/default.min.css');
110
        }
111
    }
112
    
113
}
114