1. Go to this page and download the library: Download majermi4/friendly-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/ */
class MyConfig
{
public function __construct(Connection $connection, Settings $settings) { /* your code */ }
}
class Connection
{
public function __construct(
string $driver,
string $username,
string $password,
string $host = 'localhost',
bool $memory = false,
) { /* your code */ }
}
class Settings
{
public function __construct(string $name = 'value') { /* your code */ }
}
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Majermi4\FriendlyConfig\FriendlyConfiguration;
use Majermi4\FriendlyConfig\InitializeConfigObject;
use Majermi4\FriendlyConfig\RegisterConfigService;
class MyBundleExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function getConfiguration(array $config, ContainerBuilder $container) : ConfigurationInterface
{
return FriendlyConfiguration::fromClass(MyConfig::class, 'my_config');
}
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);
if ($configuration instanceof FriendlyConfiguration) {
// Register config object with processed values as a service
RegisterConfigService::fromProcessedConfig($configuration->getConfigClass(), $config, $container);
// Or ... initialise config object from processed config immediately if needed
$initialisedConfig = InitializeConfigObject::fromProcessedConfig(MyConfig::class, $config);
}
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.