1. Go to this page and download the library: Download ghostwriter/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/ */
// from an array
$configFactory = ConfigFactory::new(); // or new ConfigFactory()
$config = $configFactory->create($options);
$config->toArray(); // ['settings' => ['enable'=>true]]
$config->has('settings'); // true
$config->has('settings.enable'); // true
$config->get('settings.enable'); // true
// from a directory
$configFactory = ConfigFactory::new(); // or new ConfigFactory()
$config = $configFactory->createFromDirectory($options);
$config->toArray(); // output below
// [
// 'app' => ['name'=>'App','version'=>'1.0.0'],
// 'database' => ['host'=>'localhost','port'=>3306]
// 'file' => ['path'=>'/path/to/file']
// ]
// from a file
$configFactory = ConfigFactory::new(); // or new ConfigFactory()
$config = $configFactory->createFromFile($file);
$config->toArray(); // ['path'=>'/path/to/file']
interface ConfigInterface
{
public function get(string $key, mixed $default = null): mixed;
public function has(string $key): bool;
/**
* @param array<string,mixed> $config
*/
public function merge(array $config): self;
public function remove(string $key): void;
public function set(string $key, mixed $value): void;
/**
* @return array<string,mixed>
*/
public function toArray(): array;
}
interface ConfigFactoryInterface
{
/**
* @param array<string,mixed> $config
*/
public function create(array $config = []): ConfigInterface;
public function createFromDirectory(string $directory): ConfigInterface;
public function createFromFile(string $file): ConfigInterface;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.