Passed
Push — main ( 4ddaea...7c5fe7 )
by Thierry
04:58
created

AbstractPackage   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfig() 0 3 1
A init() 0 2 1
A getHtml() 0 3 1
A html() 0 3 1
A getHash() 0 4 1
A getOption() 0 3 1
A view() 0 3 1
A getReadyScript() 0 3 1
1
<?php
2
3
/**
4
 * AbstractPackage.php
5
 *
6
 * Base class for the Jaxon packages.
7
 *
8
 * @package jaxon-core
9
 * @author Thierry Feuzeu <[email protected]>
10
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
11
 * @link https://github.com/jaxon-php/jaxon-core
12
 */
13
14
namespace Jaxon\Plugin;
15
16
use Jaxon\App\View\ViewRenderer;
17
use Jaxon\Config\Config;
18
use Stringable;
19
20
abstract class AbstractPackage extends AbstractCodeGenerator
21
{
22
    /**
23
     * The configuration options of the package
24
     *
25
     * @var Config
26
     */
27
    protected $xPkgConfig;
28
29
    /**
30
     * The view renderer
31
     *
32
     * @var ViewRenderer
33
     */
34
    protected $xRenderer;
35
36
    /**
37
     * Get the path to the config file, or the config options in an array.
38
     *
39
     * @return string|array
40
     */
41
    abstract public static function config(): string|array;
42
43
    /**
44
     * Get the package config object
45
     *
46
     * @return Config
47
     */
48
    final public function getConfig(): Config
49
    {
50
        return $this->xPkgConfig;
51
    }
52
53
    /**
54
     * This method is automatically called after the package instance is created and configured.
55
     *
56
     * @return void
57
     */
58
    protected function init(): void
59
    {}
60
61
    /**
62
     * Get the value of a given package option
63
     *
64
     * @param string $sOption    The option name
65
     * @param mixed $xDefault    The default value
66
     *
67
     * @return mixed
68
     */
69
    final public function getOption(string $sOption, $xDefault = null): mixed
70
    {
71
        return $this->xPkgConfig->getOption($sOption, $xDefault);
72
    }
73
74
    /**
75
     * Get the view renderer
76
     *
77
     * @return ViewRenderer
78
     */
79
    final public function view(): ViewRenderer
80
    {
81
        return $this->xRenderer;
82
    }
83
84
    /**
85
     * @inheritDoc
86
     */
87
    final public function getHash(): string
88
    {
89
        // Packages do not generate hash on their own. So we make this method final.
90
        return '';
91
    }
92
93
    /**
94
     * Get the HTML code of the package home page
95
     *
96
     * @return string|Stringable
97
     */
98
    public function getHtml(): string|Stringable
99
    {
100
        return '';
101
    }
102
103
    /**
104
     * Get the HTML code of the package home page
105
     *
106
     * This method is an alias for getHtml().
107
     *
108
     * @return string|Stringable
109
     */
110
    public function html(): string|Stringable
111
    {
112
        return $this->getHtml();
113
    }
114
115
    /**
116
     * Get the Js code of the ready() callback
117
     *
118
     * @return string|Stringable
119
     */
120
    public function getReadyScript(): string|Stringable
121
    {
122
        return '';
123
    }
124
}
125