Passed
Push — main ( 3310d4...08974e )
by Thierry
02:20
created

DbAuditPackage::getJsCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Lagdo\DbAdmin\Db;
4
5
use Jaxon\Plugin\AbstractPackage;
6
use Jaxon\Plugin\CssCode;
7
use Jaxon\Plugin\CssCodeGeneratorInterface;
8
use Jaxon\Plugin\JsCode;
9
use Jaxon\Plugin\JsCodeGeneratorInterface;
10
use Lagdo\DbAdmin\Ajax\Audit\Commands;
11
use Lagdo\DbAdmin\Ajax\Audit\Wrapper;
12
13
use function realpath;
14
use function Jaxon\cl;
15
use function Jaxon\rq;
16
17
/**
18
 * Jaxon DbAdmin audit package
19
 */
20
class DbAuditPackage extends AbstractPackage implements CssCodeGeneratorInterface, JsCodeGeneratorInterface
21
{
22
    /**
23
     * Get the path to the config file
24
     *
25
     * @return string|array
26
     */
27
    public static function config(): string
28
    {
29
        return realpath(__DIR__ . '/../config/dbaudit.php');
30
    }
31
32
    /**
33
     * Get a given server options
34
     *
35
     * @return array
36
     */
37
    public function getServerOptions(): array
38
    {
39
        return $this->getOption('database', []);
40
    }
41
42
    /**
43
     * Get the driver of a given server
44
     *
45
     * @return string
46
     */
47
    public function getServerDriver(): string
48
    {
49
        return $this->getOption('database.driver', '');
50
    }
51
52
    /**
53
     * @inheritDoc
54
     */
55
    public function getCssCode(): CssCode
56
    {
57
        $code = "/* Spinner CSS code. */\n" .
58
            $this->view()->render('dbadmin::codes::spin.css') .
59
            "\n/* DbAdmin CSS code. */\n" .
60
            $this->view()->render('dbadmin::codes::styles.css');
61
62
        return new CssCode($code);
63
    }
64
65
    /**
66
     * @inheritDoc
67
     */
68
    public function getJsCode(): JsCode
69
    {
70
        $html = $this->view()->render('dbadmin::codes::js.html');
71
        $code = "// Spinner javascript code.\n\n" .
72
            $this->view()->render('dbadmin::codes::spin.js') . "\n\n" .
73
            $this->view()->render('dbadmin::codes::script.js');
74
75
        return new JsCode(sCode: $code, sHtml: $html);
76
    }
77
78
    /**
79
     * Get the javascript code to include into the page
80
     *
81
     * The code must NOT be enclosed in HTML tags.
82
     *
83
     * @return string
84
     */
85
    public function getReadyScript(): string
86
    {
87
        return rq(Commands::class)->page();
88
    }
89
90
    /**
91
     * Get the HTML code of the package home page
92
     *
93
     * @return string
94
     */
95
    public function getHtml(): string
96
    {
97
        return cl(Wrapper::class)->html();
98
    }
99
}
100