PHP code example of kislayphp / config
1. Go to this page and download the library: Download kislayphp/config library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kislayphp / config example snippets
$server = new Kislay\Config\Server();
$server->listen('0.0.0.0', 9011);
$server->setGlobal([
'app' => ['name' => 'commerce-platform'],
'db' => ['port' => 3306],
]);
$server->setEnvironment('prod', [
'app' => ['debug' => false],
]);
$server->setProject('commerce', [
'log' => ['level' => 'warn'],
]);
$server->setService('commerce', 'order-service', [
'db' => ['name' => 'orders'],
'gateway' => ['timeout_ms' => 1200],
]);
$server->setNode('commerce', 'order-service', 'order-1', [
'metrics' => ['enabled' => false],
]);
$server->run();
use Kislay\Config\Config;
Config::boot([
'server' => 'http://127.0.0.1:9011',
'environment' => 'prod',
'project' => 'commerce',
'service' => 'order-service',
'node' => 'order-1',
'cache_file' => '/tmp/order-service-config.json',
]);
$dbName = Config::getString('db.name');
$timeout = Config::getInt('gateway.timeout_ms', 1000);
$debug = Config::getBool('app.debug', true);
Config::loadLocal('/etc/kislay/order-service.local.json');
Config::setOverride('gateway.timeout_ms', 1500);
Config::boot(array $options): bool
Config::loadLocal(string $path): bool
Config::refresh(): bool
Config::setOverride(string $key, mixed $value): bool
Config::has(string $key): bool
Config::get(string $key, mixed $default = null): mixed
Config::getString(string $key, ?string $default = null): ?string
Config::getInt(string $key, int $default = 0): int
Config::getBool(string $key, bool $default = false): bool
Config::getArray(string $key, array $default = []): array
Config::all(): array
Config::version(): string
Config::checksum(): string
$server = new Kislay\Config\Server(['host' => '127.0.0.1', 'port' => 9011]);
$server->listen('0.0.0.0', 9011);
$server->setGlobal(array $config): bool;
$server->setEnvironment(string $environment, array $config): bool;
$server->setProject(string $project, array $config): bool;
$server->setService(string $project, string $service, array $config): bool;
$server->setNode(string $project, string $service, string $node, array $config): bool;
$server->resolve(?string $environment = null, ?string $project = null, ?string $service = null, ?string $node = null): array;
$server->version(): string;
$server->save(string $path): bool;
$server->load(string $path): bool;
$server->run(): bool;
$server->stop(): bool;
$client = new Kislay\Config\ConfigClient();
$client->set('db.host', '127.0.0.1');
$client->get('db.host');
$client->all();
bash
export KISLAY_CFG_DB__HOST=127.0.0.1
export KISLAY_CFG_LOG__LEVEL=error