AbstractPackage::readyInlined()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
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\Utils\Config\Config;
18
19
abstract class AbstractPackage implements CodeGeneratorInterface
20
{
21
    /**
22
     * The configuration options of the package
23
     *
24
     * @var Config
25
     */
26
    protected $xPkgConfig;
27
28
    /**
29
     * The view renderer
30
     *
31
     * @var ViewRenderer
32
     */
33
    protected $xRenderer;
34
35
    /**
36
     * Whether to include the getReadyScript() in the generated code.
37
     *
38
     * @var bool
39
     */
40
    protected $bReadyEnabled = false;
41
42
    /**
43
     * Get the path to the config file, or the config options in an array.
44
     *
45
     * @return string|array
46
     */
47
    abstract public static function config();
48
49
    /**
50
     * Get the package config object
51
     *
52
     * @return Config
53
     */
54
    public function getConfig()
55
    {
56
        return $this->xPkgConfig;
57
    }
58
59
    /**
60
     * This method is automatically called after the package instance is created and configured.
61
     *
62
     * @return void
63
     */
64
    protected function init()
65
    {}
66
67
    /**
68
     * Get the value of a given package option
69
     *
70
     * @param string $sOption    The option name
71
     * @param mixed $xDefault    The default value
72
     *
73
     * @return mixed
74
     */
75
    public function getOption(string $sOption, $xDefault = null)
76
    {
77
        return $this->xPkgConfig->getOption($sOption, $xDefault);
78
    }
79
80
    /**
81
     * Get the view renderer
82
     *
83
     * @return ViewRenderer
84
     */
85
    public function view(): ViewRenderer
86
    {
87
        return $this->xRenderer;
88
    }
89
90
    /**
91
     * Include the getReadyScript() in the generated code.
92
     *
93
     * @return void
94
     */
95
    public function ready()
96
    {
97
        $this->bReadyEnabled = true;
98
    }
99
100
    /**
101
     * @inheritDoc
102
     */
103
    public function readyEnabled(): bool
104
    {
105
        return $this->bReadyEnabled;
106
    }
107
108
    /**
109
     * @inheritDoc
110
     */
111
    public final function readyInlined(): bool
112
    {
113
        // For packages, the getReadyScript() is never exported to external files.
114
        return true;
115
    }
116
117
    /**
118
     * @inheritDoc
119
     */
120
    public final function getHash(): string
121
    {
122
        // Packages do not generate hash on their own. So we make this method final.
123
        return '';
124
    }
125
126
    /**
127
     * @inheritDoc
128
     */
129
    public function getCss(): string
130
    {
131
        return '';
132
    }
133
134
    /**
135
     * @inheritDoc
136
     */
137
    public function getJs(): string
138
    {
139
        return '';
140
    }
141
142
    /**
143
     * @inheritDoc
144
     */
145
    public function getScript(): string
146
    {
147
        return '';
148
    }
149
150
    /**
151
     * @inheritDoc
152
     */
153
    public function getReadyScript(): string
154
    {
155
        return '';
156
    }
157
158
    /**
159
     * Get the HTML code of the package home page
160
     *
161
     * @return string
162
     */
163
    abstract public function getHtml(): string;
164
165
    /**
166
     * Get the HTML code of the package home page
167
     *
168
     * This method is an alias for getHtml().
169
     *
170
     * @return string
171
     */
172
    public function html(): string
173
    {
174
        return $this->getHtml();
175
    }
176
}
177