PHP code example of corex / config

1. Go to this page and download the library: Download corex/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/ */

    

corex / config example snippets


$adapter = new ArrayAdapter([
    'actor' => [
        'name' => 'James Bond',
    ],
]);

$config = new Config([$adapter]);

$actorName = $config->getString('actor.name');

$adapter = new ArrayAdapter([
    'actor' => [
        'name' => 'James Bond',
    ],
]);

$config = new Config([$adapter]);

$actorName = $config->section('actor')->getString('name');

class MyConfigClass implements ConfigClassInterface
{
    public function __construct(array $data)
    {
    }

    public static function getSection(): string
    {
        return 'actor';
    }
}

$adapter = new ArrayAdapter([
    'actor' => [
        'name' => 'James Bond',
    ],
]);

$config = new Config([$adapter]);

/** @var MyConfigClass $actorConfig */
$myConfigClass = $config->getConfigClassObject(MyConfigClass::class);

$config = (new ConfigFactory())
    ->createWithServerAndEnvAndProjectConfigArrayFileAdapter();

$adapter = new ArrayAdapter([
    'actor' => [
        'name' => 'James Bond',
    ],
]);

$adapter = new EnvAdapter();

$adapter = new ServerAdapter();

$adapter = new ArrayFileAdapter(new Filesystem(), '/config-dir-outside-project-root');

$adapter = new ProjectPathArrayFileAdapter(new Filesystem(), 'my-config-dir');

$adapter = new ProjectConfigArrayFileAdapter(new Filesystem());



declare(strict_types=1);

return [
    'actor1' => [
        'firstname' => 'Roger',
        'lastname' => 'Moore'
    ],
    'actor3' => [
        'firstname' => 'Daniel',
        'lastname' => 'Craig'
    ]
];