PHP code example of activecollab / configrepository

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

    

activecollab / configrepository example snippets




use ActiveCollab\ConfigRepository\ConfigRepository;
use ActiveCollab\ConfigRepository\Adapter\PhpConstantsAdapter;

$repository = new ConfigRepository(new PhpConstantsAdapter('/path/to/config.php'));

// Check if option exists in any of the adapters
$repository->exists('CONFIG_NAME');

// Get value from first adapter that has it, or return default value if none of the adapters have it
$repository->get('CONFIG_NAME', 'default if not found');

// Get value from first adapter that has it, or throw an exception if it is not found in any adapter
$repository->mustGet('CONFIG_NAME'); // Throws an exception if option is not fpund

// Set value in all adapters where this option exists. Read-only adapters that have this option will throw an exception
$repository->set('CONFIG_NAME', 'value to set');



use ActiveCollab\ConfigRepository\ConfigRepository;
use ActiveCollab\ConfigRepository\Adapter\PhpConstantsAdapter;

$repository = new ConfigRepository(new PhpConstantsAdapter('/path/to/config.php'));

$repository->getAdapter(PhpConstantsAdapter::class)->exists('CONFIG_NAME');
$repository->getAdapter(PhpConstantsAdapter::class)->get('CONFIG_NAME', 'default if not found');
$repository->getAdapter(PhpConstantsAdapter::class)->mustGet('CONFIG_NAME'); // Throws an exception if option is not fpund
$repository->getAdapter(PhpConstantsAdapter::class)->set('CONFIG_NAME', 'value to set');



use ActiveCollab\ConfigRepository\ConfigRepository;
use ActiveCollab\ConfigRepository\Adapter\DotEnvAdapter;
use ActiveCollab\ConfigRepository\Adapter\PhpConstantsAdapter;

$repository = new ConfigRepository(new PhpConstantsAdapter(__DIR__ . '/Resources/config.simple.php'), new DotEnvAdapter(__DIR__ . '/Resources', '.env'));



use ActiveCollab\ConfigRepository\ConfigRepository;
use ActiveCollab\ConfigRepository\Adapter\DotEnvAdapter;
use ActiveCollab\ConfigRepository\Adapter\PhpConstantsAdapter;

$repository = new ConfigRepository([
    new PhpConstantsAdapter(__DIR__ . '/Resources/config.simple.php'),
    'second' => new PhpConstantsAdapter(__DIR__ . '/Resources/config.simple.php'),
], new DotEnvAdapter(__DIR__ . '/Resources', '.env'));

$repository->getAdapter(PhpConstantsAdapter::class); // Returns PhpConstantsAdapter instance
$repository->getAdapter('second');                   // Returns PhpConstantsAdapter instance
$repository->getAdapter(DotEnvAdapter::class);       // Returns DotEnvAdapter instance



use ActiveCollab\ConfigRepository\ConfigRepository;
use ActiveCollab\ConfigRepository\Adapter\DotEnvAdapter;
use ActiveCollab\ConfigRepository\Adapter\PhpConstantsAdapter;

$repository = new ConfigRepository(new PhpConstantsAdapter(__DIR__ . '/Resources/config.simple.php'));
$repository->addAdapter(new DotEnvAdapter($repository->get('DOT_ENV_DIR_PATH')));