Skip to content

Commit c9628e6

Browse files
4.13.2
1 parent 0b5b175 commit c9628e6

File tree

3 files changed

+45
-36
lines changed

3 files changed

+45
-36
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1877,7 +1877,9 @@ In a nutshell:
18771877
>
18781878
> Every decimal version means that it patches/fixes/refactoring a previous functionality i.e. 1.5.0 -> 1.5.1 (fix)
18791879
1880-
* 4.13 2025-02-02
1880+
* 4.13.2 2025-02-20
1881+
* Later fix in the constructor.
1882+
* 4.13 2025-02-20
18811883
* Added prefix and postfix to the referential columns.
18821884
* 4.12 2024-12-30
18831885
* Compatibility with PHP 8.4

lib/PdoOne.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -306,15 +306,18 @@ public static function endsWith($haystack, $needle): bool
306306
public static function factoryFromArray(array $array): PdoOne
307307
{
308308
if (isset($array['databaseType'])) {
309-
return new self($array['databaseType'] ?? '',
310-
$array['server'] ?? '',
311-
$array['user'] ?? '',
312-
$array['pwd'] ?? '',
313-
$array['database'] ?? '',
314-
$array['logFile'] ?? false,
315-
$array['charset'] ?? null,
316-
$array['nodeId'] ?? 1,
317-
$array['tableKV'] ?? ""
309+
return new self($array['databaseType'] ?? '', //0
310+
$array['server'] ?? '', //1
311+
$array['user'] ?? '', //2
312+
$array['pwd'] ?? '', //3
313+
$array['database'] ?? '', //4
314+
$array['logFile'] ?? false, //5
315+
$array['charset'] ?? null, //6
316+
$array['nodeId'] ?? 1, //7
317+
$array['tableKV'] ?? "", //8
318+
$array['instanceName'] ?? "0", //9
319+
$array['prefix'] ?? self::$prefixBase, //10
320+
$array['postfix'] ?? self::$postfixBase, //11
318321
);
319322
}
320323
return new self($array[0] ?? '',
@@ -325,7 +328,10 @@ public static function factoryFromArray(array $array): PdoOne
325328
$array[5] ?? false,
326329
$array[6] ?? null,
327330
$array[7] ?? 1,
328-
$array[8] ?? ""
331+
$array[8] ?? "",
332+
$array[9] ?? "0",
333+
$array[10] ?? self::$prefixBase,
334+
$array[11] ?? self::$postfixBase,
329335
);
330336
}
331337

lib/PdoOneCli.php

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
2323
* @package eftec
2424
* @author Jorge Castro Castillo
2525
* @copyright (c) Jorge Castro C. Dual Licence: MIT and Commercial License https://github.com/EFTEC/PdoOne
26-
* @version 2.5
26+
* @version 2.6
2727
*/
2828
class PdoOneCli
2929
{
30-
public const VERSION = '2.5';
30+
public const VERSION = '2.6';
3131
/** @var CliOne|null */
32-
public ?CliOne $cli=null;
32+
public ?CliOne $cli = null;
3333
//protected $help;
3434
/** @var ?PdoOneCli the current instance */
35-
public static ?PdoOneCli $instance=null;
35+
public static ?PdoOneCli $instance = null;
3636

3737
public static function instance(bool $run = true): PdoOneCli
3838
{
@@ -41,9 +41,10 @@ public static function instance(bool $run = true): PdoOneCli
4141
}
4242
return self::$instance;
4343
}
44+
4445
public function __construct(bool $run = true)
4546
{
46-
self::$instance=$this;
47+
self::$instance = $this;
4748
$this->cli = CliOne::instance();
4849
$this->cli->setErrorType();
4950
$this->cli->addMenu('mainmenu',
@@ -87,8 +88,7 @@ function($cli) {
8788
}
8889
try {
8990
$this->cli->evalMenu('mainmenu', $this);
90-
} catch(Exception $e) {
91-
91+
} catch (Exception $e) {
9292
}
9393
}
9494
}
@@ -170,7 +170,7 @@ public function menuConnectSave(): void
170170
if ($sg->value === 'yes') {
171171
$saveconfig = $this->cli->getParameter('fileconnect')->setInput()->evalParam(true);
172172
if ($saveconfig->value) {
173-
$arr=$this->pdoGetConfigArray();
173+
$arr = $this->pdoGetConfigArray();
174174
$r = $this->cli->saveDataPHPFormat($this->cli->getValue('fileconnect'), $arr);
175175
if ($r === '') {
176176
$this->cli->showCheck('OK', 'green', 'file saved correctly');
@@ -180,8 +180,6 @@ public function menuConnectSave(): void
180180
$this->cli->downLevel();
181181
}
182182

183-
184-
185183
public function menuConnectQuery(): void
186184
{
187185
$this->cli->upLevel('query');
@@ -268,7 +266,7 @@ public function menuConnectConfigure(): void
268266
->setDefault('no')
269267
->setDescription('Do you want to log into a file?', '', ['Example: <dim>yes</dim>'])
270268
->setCurrentAsDefault()
271-
->setInput(true, 'optionshort',['yes','no'])
269+
->setInput(true, 'optionshort', ['yes', 'no'])
272270
->evalParam(true);
273271
$this->cli->createOrReplaceParam('charset', [], 'longflag')
274272
->setRequired(false)
@@ -283,7 +281,7 @@ public function menuConnectConfigure(): void
283281
->setDefault(1)
284282
->setDescription('Select the node id used by snowflake, (or empty for default)', '', ['Example: <dim>1</dim>'])
285283
->setCurrentAsDefault()
286-
->setInput(true,'number')
284+
->setInput(true, 'number')
287285
->evalParam(true);
288286
$this->cli->createOrReplaceParam('tableKV', [], 'longflag')
289287
->setRequired(false)
@@ -296,6 +294,7 @@ public function menuConnectConfigure(): void
296294
$this->cli->createOrReplaceParam('prefix', [], 'longflag')
297295
->setRequired(false)
298296
->setDefault('_')
297+
->setAllowEmpty()
299298
->setDescription('The prefix', '', ['Example: <dim>_</dim>'])
300299
->setCurrentAsDefault()
301300
->setInput()
@@ -328,20 +327,22 @@ public function menuConnectConfigure(): void
328327
}
329328
}
330329
}
331-
public function pdoGetConfigArray():array
330+
331+
public function pdoGetConfigArray(): array
332332
{
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';
336336
return $r;
337337
}
338+
338339
public function pdoSetConfigArray(array $array): void
339340
{
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
345346
}
346347

347348
public function doReadConfig(): void
@@ -351,7 +352,8 @@ public function doReadConfig(): void
351352
$this->cli->showCheck('OK', 'green', 'file read correctly');
352353
$this->cli->setVariable('connect', '<green>ok</green>');
353354
$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') ?? '';
355357
} else {
356358
$this->cli->showCheck('ERROR', 'red', 'unable to read file ' . $this->cli->getValue('fileconnect') . ", cause " . $r[1]);
357359
}
@@ -372,8 +374,8 @@ public function createPdoInstance()
372374
) {
373375
throw new RuntimeException('No configuration');
374376
}
375-
$r=$this->pdoGetConfigArray();
376-
$r=array_values($r);
377+
$r = $this->pdoGetConfigArray();
378+
$r = array_values($r);
377379
$pdo = new PdoOne(...$r);
378380
$pdo->logLevel = 1;
379381
$pdo->connect();
@@ -474,7 +476,6 @@ protected function showLogo(): void
474476
try {
475477
$this->cli->showParamSyntax2();
476478
} catch (Exception $ex) {
477-
478479
}
479480
}
480481

0 commit comments

Comments
 (0)