composer require barth/simple-config-bundle
config/bundles.php:
Barth\SimpleConfigBundle\BarthSimpleConfigBundle::class => ['all' => true],
config/routes.yaml:
barth_simpleconfig:
resource: "@BarthSimpleConfigBundle/Controller/"
type: annotation
prefix: /admin/config
/admin/config to see a form for editing bundle configurations. The bundle automatically detects and exposes configuration options from other bundles (e.g., twitter_client_id, twitter_client_secret).Expose Configurations:
The bundle scans for bundle configurations defined in Resources/config/config.yaml (or similar) and generates a form for each. Example:
# AcmeTwitterBundle/Resources/config/config.yaml
parameters:
twitter_client_id: ~
twitter_client_secret: ~
The form will render fields for these parameters.
Admin Interface:
/admin/config to view/edit configurations.config/packages/override.yaml (or a custom path).Integration with Existing Configs:
config/packages/override.yaml:
parameters:
twitter_client_id: 'your_id_here'
twitter_client_secret: 'your_secret_here'
Dynamic Configuration:
Barth\SimpleConfigBundle\Config\ConfigProviderInterface and register it as a service.Accessing Configs in Code:
Use Symfony’s ParameterBag or ContainerInterface to access updated values:
$clientId = $this->getParameter('twitter_client_id');
Configuration Merging:
override.yaml replace default values, not merge them. Use parameters or framework keys carefully to avoid unintended overwrites.twitter_client_id is null in defaults, it will be set to null in overrides unless explicitly defined.Caching:
php bin/console cache:clear) after adding new config files to Resources/config/config.yaml.Security:
# config/routes.yaml
barth_simpleconfig:
resource: "@BarthSimpleConfigBundle/Controller/"
type: annotation
prefix: /admin/config
requirements:
_role: ROLE_ADMIN
Bundle Compatibility:
config.yaml) are exposed. Bundles using Extension classes (e.g., load() methods) may not appear in the UI.config.yaml in your bundle’s Resources/config/ directory.File Permissions:
config/packages/override.yaml is writable by the web server user:
chmod 644 config/packages/override.yaml
Custom Override Path: Change the override file location by configuring the bundle:
# config/packages/barth_simple_config.yaml
barth_simple_config:
override_file: '%kernel.project_dir%/config/custom_overrides.yaml'
Field Customization:
Override form types for specific parameters by creating a service tagged as barth_simple_config.form.type:
services:
app.twitter_client_id_type:
class: App\Form\Type\TwitterClientIdType
tags:
- { name: barth_simple_config.form.type, parameter: twitter_client_id }
Validation:
Add validation rules to override.yaml by extending the bundle’s form builder. Example:
// src/Form/Extension/ConfigExtension.php
namespace App\Form\Extension;
use Barth\SimpleConfigBundle\Form\Type\ConfigType;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormBuilderInterface;
class ConfigExtension extends AbstractTypeExtension
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('twitter_client_id', TextType::class, [
'constraints' => [new NotBlank(), new Length(['max' => 50])],
]);
}
public function getExtendedType()
{
return ConfigType::class;
}
}
Debugging:
// config/packages/dev/barth_simple_config.yaml
barth_simple_config:
debug: true
override.yaml file directly for errors (e.g., YAML syntax).Local Development:
Use environment variables for sensitive data (e.g., twitter_client_secret) and exclude them from the UI by prefixing with _ (e.g., _twitter_client_secret). The bundle ignores parameters starting with _.
How can I help you explore Laravel packages today?