PHP code example of vigihdev / symfony-bridge-config
1. Go to this page and download the library: Download vigihdev/symfony-bridge-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/ */
vigihdev / symfony-bridge-config example snippets
use VigihDev\SymfonyBridge\Config\ConfigBridge;
use VigihDev\SymfonyBridge\Config\Service\ServiceLocator;
>container();
// Access parameters
echo $config->container()->getParameter('app.env');
echo ServiceLocator::getParameter('app.env');
use VigihDev\SymfonyBridge\Config\ConfigBridge;
use App\Config\AppConfig;
$config = new ConfigBridge(__DIR__);
$config->loadEnv(); // Load .env file
$config->loadConfig(__DIR__ . '/config'); // Load YAML configs
$config->addConfiguration(new AppConfig()); // Add custom config
$config->compile(); // Compile container
// Use the container
$appConfig = $config->get(AppConfig::class);
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class AppConfig implements ConfigurationInterface
{
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('app');
$rootNode = $treeBuilder->getRootNode();
$rootNode
->children()
->scalarNode('env')->defaultValue('dev')->end()
->scalarNode('debug')->defaultTrue()->end()
->arrayNode('database')
->children()
->scalarNode('host')->defaultValue('localhost')->end()
->scalarNode('port')->defaultValue('3306')->end()
->end()
->end()
->end();
return $treeBuilder;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.