Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Config Bundle Laravel Package

c975l/config-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require c975l/config-bundle
    

    Add to bundles.php (Symfony 5+):

    return [
        // ...
        c975L\ConfigBundle\c975LConfigBundle::class => ['all' => true],
    ];
    
  2. Define Config Structure Create a YAML file (e.g., config/config.yml) with your key-value pairs:

    app:
        title: "My App"
        debug_mode: true
        api_endpoint: "https://api.example.com"
    
  3. First Use Case Access values in Twig:

    {{ config('app.title') }}  {# Outputs "My App" #}
    

Implementation Patterns

Workflow: Config Management

  1. Define Config Use YAML/JSON files in config/ directory (e.g., config/app.yml). Example:

    features:
        newsletter: true
        analytics: false
    
  2. Build Admin Form Override the default form template (templates/bundles/c975LConfigBundle/views/form.html.twig). Inject your config file path via dependency injection:

    // services.yaml
    c975L\ConfigBundle\ConfigManager:
        arguments:
            $configFiles: ['%kernel.project_dir%/config/app.yml']
    
  3. Access in Controllers Fetch values via the ConfigManager service:

    $title = $this->get('config_manager')->get('app.title');
    
  4. Twig Integration Use the Twig extension globally:

    {% set apiUrl = config('app.api_endpoint') %}
    

Integration Tips

  • Validation: Extend the bundle’s ConfigValidator to add custom rules.
  • Environment-Specific Configs: Load multiple files per environment (e.g., config/dev.yml, config/prod.yml).
  • Caching: Enable Symfony’s cache for config files to reduce I/O:
    # config/packages/c975LConfigBundle.yaml
    c975L_config:
        cache: true
    

Gotchas and Tips

Pitfalls

  1. Template Overrides

    • Forgetting to override form.html.twig may break the admin UI.
    • Fix: Copy the original template from the bundle’s Resources/views/ to your project’s templates/bundles/c975LConfigBundle/views/.
  2. Key-Value System (v2.0+)

    • The bundle no longer uses Symfony’s Configuration class, so custom validation requires manual implementation.
    • Workaround: Extend c975L\ConfigBundle\Validator\ConfigValidator:
      public function validate($value, Constraint $constraint)
      {
          if ($value === 'debug_mode' && $this->isProd()) {
              throw new \InvalidArgumentException('Debug mode disabled in production.');
          }
      }
      
  3. Caching Issues

    • Config changes may not reflect immediately if caching is enabled.
    • Debug: Clear cache after edits:
      php bin/console cache:clear
      
  4. YAML Parsing Quirks

    • Boolean values must use YAML syntax (true/false), not quotes ("true").
    • Example:
      # Correct
      debug: true
      # Incorrect (will be parsed as string)
      debug: "true"
      

Tips

  1. Dynamic Config Loading Load configs dynamically based on user roles:

    $configFiles = [];
    if ($this->isAdmin()) {
        $configFiles[] = '%kernel.project_dir%/config/admin.yml';
    }
    $configManager->setConfigFiles($configFiles);
    
  2. Environment Variables Merge environment variables with YAML configs:

    # .env
    APP_TITLE=Custom Title
    
    $configManager->mergeWithEnv();
    
  3. Event Listeners Listen for config changes to trigger actions (e.g., cache invalidation):

    $eventDispatcher->addListener(
        c975L\ConfigBundle\Event\ConfigUpdatedEvent::class,
        function () {
            $this->container->get('cache')->clear();
        }
    );
    
  4. Testing Mock ConfigManager in tests:

    $configManager = $this->createMock(ConfigManager::class);
    $configManager->method('get')->willReturn('Test Value');
    $this->container->set('config_manager', $configManager);
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui