Passed
Push — main ( 148bfb...4ebd52 )
by Thierry
01:32
created

ConfigEntity::onActions()   A

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
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Lagdo\DbAdmin\Driver\Entity;
4
5
use Lagdo\DbAdmin\Driver\TranslatorInterface;
6
7
class ConfigEntity
8
{
9
    /**
10
     * @var string
11
     */
12
    public $jush = '';
13
14
    /**
15
     * @var string
16
     */
17
    public $version = '4.8.1-dev';
18
19
    /**
20
     * @var array
21
     */
22
    public $drivers = [];
23
24
    /**
25
     * @var array
26
     */
27
    public $types = [];
28
29
    /**
30
     * @var array
31
     */
32
    public $structuredTypes = [];
33
34
    /**
35
     * @var array
36
     */
37
    public $unsigned = [];
38
39
    /**
40
     * @var array
41
     */
42
    public $operators = [];
43
44
    /**
45
     * @var array
46
     */
47
    public $functions = [];
48
49
    /**
50
     * @var array
51
     */
52
    public $grouping = [];
53
54
    /**
55
     * @var array
56
     */
57
    public $editFunctions = [];
58
59
    /**
60
     * @var array
61
     */
62
    public $options;
63
64
    /**
65
     * From bootstrap.inc.php
66
     * @var string
67
     */
68
    public $onActions = 'RESTRICT|NO ACTION|CASCADE|SET NULL|SET DEFAULT'; ///< @var string used in foreignKeys()
69
70
    /**
71
     * @var string
72
     */
73
    public $numberRegex = '((?<!o)int(?!er)|numeric|real|float|double|decimal|money)'; // not point, not interval
74
75
    /**
76
     * From index.php
77
     * @var string
78
     */
79
    public $inout = 'IN|OUT|INOUT';
80
81
    /**
82
     * From index.php
83
     * @var string
84
     */
85
    public $enumLength = "'(?:''|[^'\\\\]|\\\\.)*'";
86
87
    /**
88
     * The current database name
89
     *
90
     * @var string
91
     */
92
    public $database = '';
93
94
    /**
95
     * The current schema name
96
     *
97
     * @var string
98
     */
99
    public $schema = '';
100
101
    /**
102
     * Set the supported types
103
     *
104
     * @param array $types
105
     * @param TranslatorInterface $trans
106
     *
107
     * @return void
108
     */
109
    public function setTypes(array $types, TranslatorInterface $trans)
110
    {
111
        foreach ($types as $group => $_types) {
112
            $this->structuredTypes[$trans->lang($group)] = array_keys($_types);
113
            $this->types = array_merge($this->types, $_types);
114
        }
115
    }
116
117
    /**
118
     * The constructor
119
     *
120
     * @param array $options
121
     */
122
    public function __construct(array $options)
123
    {
124
        $this->options = $options;
125
    }
126
127
    /**
128
     * Get the driver options
129
     *
130
     * @param string $name The option name
131
     *
132
     * @return mixed
133
     */
134
    public function options(string $name = '')
135
    {
136
        if (!($name = trim($name))) {
137
            return $this->options;
138
        }
139
        if (\array_key_exists($name, $this->options)) {
140
            return $this->options[$name];
141
        }
142
        if ($name === 'server') {
143
            $server = $this->options['host'] ?? '';
144
            $port = $this->options['port'] ?? ''; // Optional
145
            // Append the port to the host if it is defined.
146
            if (($port)) {
147
                $server .= ":$port";
148
            }
149
            return $server;
150
        }
151
        // if ($name === 'ssl') {
152
        //     return false; // No SSL options yet
153
        // }
154
        // Option not found
155
        return '';
156
    }
157
158
    /**
159
     * @return array
160
     */
161
    public function onActions()
162
    {
163
        return \explode('|', $this->onActions);
164
    }
165
}
166