Passed
Push — main ( a7f090...08efad )
by Thierry
02:01
created

AbstractLibrary   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 90
rs 10
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getCss() 0 3 1
A helper() 0 3 2
A getJs() 0 3 1
A getUri() 0 3 1
A getScript() 0 3 1
A getJsCode() 0 5 1
1
<?php
2
3
/**
4
 * AbstractDialogLibrary.php
5
 *
6
 * Base class for javascript dialog libraries.
7
 *
8
 * @package jaxon-core
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
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 ?: $this->xHelper = dialog()->getLibraryHelper($this->getName());
59
    }
60
61
    /**
62
     * Get the library base URI
63
     *
64
     * @return string
65
     */
66
    public function getUri(): string
67
    {
68
        return '';
69
    }
70
71
    /**
72
     * Get the CSS header code and file includes
73
     *
74
     * @return string
75
     */
76
    public function getJs(): string
77
    {
78
        return $this->helper()->getJs($this->aJsFiles);
79
    }
80
81
    /**
82
     * Get the javascript header code and file includes
83
     *
84
     * @return string
85
     */
86
    public function getCss(): string
87
    {
88
        return $this->helper()->getCss($this->aCssFiles);
89
    }
90
91
    /**
92
     * Get the javascript code to be printed into the page
93
     *
94
     * @return string
95
     */
96
    public function getScript(): string
97
    {
98
        return '';
99
    }
100
101
    /**
102
     * Get the javascript code to be executed on page load
103
     *
104
     * @return JsCode|null
105
     */
106
    public function getJsCode(): ?JsCode
107
    {
108
        $xJsCode = new JsCode();
109
        $xJsCode->sJs = $this->helper()->getScript();
110
        return $xJsCode;
111
    }
112
}
113