AbstractLibrary::getJs()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * AbstractDialogLibrary.php
5
 *
6
 * Base class for javascript dialog libraries.
7
 *
8
 * @package jaxon-dialogs
9
 * @author Thierry Feuzeu <[email protected]>
10
 * @copyright 2016 Thierry Feuzeu <[email protected]>
11
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
12
 * @link https://github.com/jaxon-php/jaxon-dialogs
13
 */
14
15
namespace Jaxon\Dialogs\Dialog;
16
17
use Jaxon\Plugin\Code\JsCode;
18
19
use function Jaxon\Dialogs\dialog;
20
21
abstract class AbstractLibrary
22
{
23
    /**
24
     * The dialog library helper
25
     *
26
     * @var LibraryHelper|null
27
     */
28
    private $xHelper = null;
29
30
    /**
31
     * The css files
32
     *
33
     * @var array
34
     */
35
    protected $aCssFiles = [];
36
37
    /**
38
     * The js files
39
     *
40
     * @var array
41
     */
42
    protected $aJsFiles = [];
43
44
    /**
45
     * Get the library name
46
     *
47
     * @return string
48
     */
49
    abstract public function getName(): string;
50
51
    /**
52
     * Get the helper
53
     *
54
     * @return LibraryHelper
55
     */
56
    public function helper(): LibraryHelper
57
    {
58
        return $this->xHelper ?:
59
            $this->xHelper = dialog()->getLibraryHelper($this->getName());
60
    }
61
62
    /**
63
     * Get the library base URI
64
     *
65
     * @return string
66
     */
67
    public function getUri(): string
68
    {
69
        return '';
70
    }
71
72
    /**
73
     * Get the CSS header code and file includes
74
     *
75
     * @return string
76
     */
77
    public function getJs(): string
78
    {
79
        return $this->helper()->getJs($this->aJsFiles);
80
    }
81
82
    /**
83
     * Get the javascript header code and file includes
84
     *
85
     * @return string
86
     */
87
    public function getCss(): string
88
    {
89
        return $this->helper()->getCss($this->aCssFiles);
90
    }
91
92
    /**
93
     * Get the javascript code to be printed into the page
94
     *
95
     * @return string
96
     */
97
    public function getScript(): string
98
    {
99
        return '';
100
    }
101
102
    /**
103
     * Get the javascript code to be executed on page load
104
     *
105
     * @return JsCode|null
106
     */
107
    public function getJsCode(): ?JsCode
108
    {
109
        $xJsCode = new JsCode();
110
        $xJsCode->sJs = $this->helper()->getScript();
111
        return $xJsCode;
112
    }
113
}
114