37 lines
948 B
PHP
37 lines
948 B
PHP
<?php
|
|
namespace nur\sery\db\sqlite;
|
|
|
|
use nur\sery\php\func;
|
|
|
|
class _config {
|
|
static function with($configs): self {
|
|
if ($configs instanceof static) return $configs;
|
|
return new static($configs);
|
|
}
|
|
|
|
const CONFIG = null;
|
|
|
|
function __construct($configs) {
|
|
if ($configs === null) $configs = static::CONFIG;
|
|
if ($configs === null) $configs = [];
|
|
elseif (is_string($configs)) $configs = [$configs];
|
|
elseif (is_callable($configs)) $configs = [$configs];
|
|
elseif (!is_array($configs)) $configs = [strval($configs)];
|
|
$this->configs = $configs;
|
|
}
|
|
|
|
/** @var array */
|
|
protected $configs;
|
|
|
|
function configure(Sqlite $sqlite): void {
|
|
foreach ($this->configs as $key => $config) {
|
|
if (is_string($config) && !func::is_method($config)) {
|
|
$sqlite->exec($config);
|
|
} else {
|
|
func::ensure_func($config, $this, $args);
|
|
func::call($config, $sqlite, $key, ...$args);
|
|
}
|
|
}
|
|
}
|
|
}
|