37 lines
928 B
PHP
37 lines
928 B
PHP
<?php
|
|
namespace nulib\db\_private;
|
|
|
|
use nulib\db\IDatabase;
|
|
use nulib\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(IDatabase $db): void {
|
|
foreach ($this->configs as $key => $config) {
|
|
if (is_string($config) && !func::is_method($config)) {
|
|
$db->exec($config);
|
|
} else {
|
|
func::with($config)->bind($this, true)->invoke([$db, $key]);
|
|
}
|
|
}
|
|
}
|
|
}
|