23
23
* @package eftec
24
24
* @author Jorge Castro Castillo
25
25
* @copyright (c) Jorge Castro C. Dual Licence: MIT and Commercial License https://github.com/EFTEC/PdoOne
26
- * @version 2.5
26
+ * @version 2.6
27
27
*/
28
28
class PdoOneCli
29
29
{
30
- public const VERSION = '2.5 ' ;
30
+ public const VERSION = '2.6 ' ;
31
31
/** @var CliOne|null */
32
- public ?CliOne $ cli= null ;
32
+ public ?CliOne $ cli = null ;
33
33
//protected $help;
34
34
/** @var ?PdoOneCli the current instance */
35
- public static ?PdoOneCli $ instance= null ;
35
+ public static ?PdoOneCli $ instance = null ;
36
36
37
37
public static function instance (bool $ run = true ): PdoOneCli
38
38
{
@@ -41,9 +41,10 @@ public static function instance(bool $run = true): PdoOneCli
41
41
}
42
42
return self ::$ instance ;
43
43
}
44
+
44
45
public function __construct (bool $ run = true )
45
46
{
46
- self ::$ instance= $ this ;
47
+ self ::$ instance = $ this ;
47
48
$ this ->cli = CliOne::instance ();
48
49
$ this ->cli ->setErrorType ();
49
50
$ this ->cli ->addMenu ('mainmenu ' ,
@@ -87,8 +88,7 @@ function($cli) {
87
88
}
88
89
try {
89
90
$ this ->cli ->evalMenu ('mainmenu ' , $ this );
90
- } catch (Exception $ e ) {
91
-
91
+ } catch (Exception $ e ) {
92
92
}
93
93
}
94
94
}
@@ -170,7 +170,7 @@ public function menuConnectSave(): void
170
170
if ($ sg ->value === 'yes ' ) {
171
171
$ saveconfig = $ this ->cli ->getParameter ('fileconnect ' )->setInput ()->evalParam (true );
172
172
if ($ saveconfig ->value ) {
173
- $ arr= $ this ->pdoGetConfigArray ();
173
+ $ arr = $ this ->pdoGetConfigArray ();
174
174
$ r = $ this ->cli ->saveDataPHPFormat ($ this ->cli ->getValue ('fileconnect ' ), $ arr );
175
175
if ($ r === '' ) {
176
176
$ this ->cli ->showCheck ('OK ' , 'green ' , 'file saved correctly ' );
@@ -180,8 +180,6 @@ public function menuConnectSave(): void
180
180
$ this ->cli ->downLevel ();
181
181
}
182
182
183
-
184
-
185
183
public function menuConnectQuery (): void
186
184
{
187
185
$ this ->cli ->upLevel ('query ' );
@@ -268,7 +266,7 @@ public function menuConnectConfigure(): void
268
266
->setDefault ('no ' )
269
267
->setDescription ('Do you want to log into a file? ' , '' , ['Example: <dim>yes</dim> ' ])
270
268
->setCurrentAsDefault ()
271
- ->setInput (true , 'optionshort ' ,['yes ' ,'no ' ])
269
+ ->setInput (true , 'optionshort ' , ['yes ' , 'no ' ])
272
270
->evalParam (true );
273
271
$ this ->cli ->createOrReplaceParam ('charset ' , [], 'longflag ' )
274
272
->setRequired (false )
@@ -283,7 +281,7 @@ public function menuConnectConfigure(): void
283
281
->setDefault (1 )
284
282
->setDescription ('Select the node id used by snowflake, (or empty for default) ' , '' , ['Example: <dim>1</dim> ' ])
285
283
->setCurrentAsDefault ()
286
- ->setInput (true ,'number ' )
284
+ ->setInput (true , 'number ' )
287
285
->evalParam (true );
288
286
$ this ->cli ->createOrReplaceParam ('tableKV ' , [], 'longflag ' )
289
287
->setRequired (false )
@@ -296,6 +294,7 @@ public function menuConnectConfigure(): void
296
294
$ this ->cli ->createOrReplaceParam ('prefix ' , [], 'longflag ' )
297
295
->setRequired (false )
298
296
->setDefault ('_ ' )
297
+ ->setAllowEmpty ()
299
298
->setDescription ('The prefix ' , '' , ['Example: <dim>_</dim> ' ])
300
299
->setCurrentAsDefault ()
301
300
->setInput ()
@@ -328,20 +327,22 @@ public function menuConnectConfigure(): void
328
327
}
329
328
}
330
329
}
331
- public function pdoGetConfigArray ():array
330
+
331
+ public function pdoGetConfigArray (): array
332
332
{
333
- $ r = $ this ->cli ->getValueAsArray (
334
- ['databaseType ' ,'server ' ,'user ' ,'pwd ' ,'database ' ,'logFile ' ,'charset ' ,'nodeId ' ,'tableKV ' ,'prefix ' ,'postfix ' ]);
335
- $ r ['logFile ' ]= $ r ['logFile ' ]==='yes ' ;
333
+ $ r = $ this ->cli ->getValueAsArray (
334
+ ['databaseType ' , 'server ' , 'user ' , 'pwd ' , 'database ' , 'logFile ' , 'charset ' , 'nodeId ' , 'tableKV ' , 'prefix ' , 'postfix ' ]);
335
+ $ r ['logFile ' ] = $ r ['logFile ' ] === 'yes ' ;
336
336
return $ r ;
337
337
}
338
+
338
339
public function pdoSetConfigArray (array $ array ): void
339
340
{
340
- $ lf= $ array ['logFile ' ]?? 'false ' ;
341
- $ backup= $ this ->cli ->getValue ('logFile ' ); //yes|no
342
- $ this ->cli ->setParam ('logFile ' ,$ lf? 'yes ' : 'no ' ,false ,true ); //true|false
343
- $ this ->cli ->setParamUsingArray ($ array ,['databaseType ' ,'server ' ,'user ' ,'pwd ' ,'database ' ,'logFile ' ,'charset ' ,'nodeId ' ,'tableKV ' ,'prefix ' ,'postfix ' ]);
344
- $ this ->cli ->setParam ('logFile ' ,$ backup );//yes|no
341
+ $ lf = $ array ['logFile ' ] ?? 'false ' ;
342
+ $ backup = $ this ->cli ->getValue ('logFile ' ); //yes|no
343
+ $ this ->cli ->setParam ('logFile ' , $ lf ? 'yes ' : 'no ' , false , true ); //true|false
344
+ $ this ->cli ->setParamUsingArray ($ array , ['databaseType ' , 'server ' , 'user ' , 'pwd ' , 'database ' , 'logFile ' , 'charset ' , 'nodeId ' , 'tableKV ' , 'prefix ' , 'postfix ' ]);
345
+ $ this ->cli ->setParam ('logFile ' , $ backup );//yes|no
345
346
}
346
347
347
348
public function doReadConfig (): void
@@ -351,7 +352,8 @@ public function doReadConfig(): void
351
352
$ this ->cli ->showCheck ('OK ' , 'green ' , 'file read correctly ' );
352
353
$ this ->cli ->setVariable ('connect ' , '<green>ok</green> ' );
353
354
$ this ->pdoSetConfigArray ($ r [1 ]);
354
- PdoOne::$ prefixBase =$ this ->cli ->getValue ('prefix ' );
355
+ PdoOne::$ prefixBase = $ this ->cli ->getValue ('prefix ' ) ?? '_ ' ;
356
+ PdoOne::$ postfixBase = $ this ->cli ->getValue ('postfix ' ) ?? '' ;
355
357
} else {
356
358
$ this ->cli ->showCheck ('ERROR ' , 'red ' , 'unable to read file ' . $ this ->cli ->getValue ('fileconnect ' ) . ", cause " . $ r [1 ]);
357
359
}
@@ -372,8 +374,8 @@ public function createPdoInstance()
372
374
) {
373
375
throw new RuntimeException ('No configuration ' );
374
376
}
375
- $ r= $ this ->pdoGetConfigArray ();
376
- $ r= array_values ($ r );
377
+ $ r = $ this ->pdoGetConfigArray ();
378
+ $ r = array_values ($ r );
377
379
$ pdo = new PdoOne (...$ r );
378
380
$ pdo ->logLevel = 1 ;
379
381
$ pdo ->connect ();
@@ -474,7 +476,6 @@ protected function showLogo(): void
474
476
try {
475
477
$ this ->cli ->showParamSyntax2 ();
476
478
} catch (Exception $ ex ) {
477
-
478
479
}
479
480
}
480
481
0 commit comments