Weave 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

Core Config Bundle Laravel Package

c33s-toolkit/core-config-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require c33s-toolkit/core-config-bundle
    

    Enable the bundle in config/bundles.php:

    return [
        // ...
        C33S\Toolkit\CoreConfigBundle\C33SToolkitCoreConfigBundle::class => ['all' => true],
    ];
    
  2. Basic Configuration Define your project-wide constants in config/packages/c33s_toolkit_core_config.yaml:

    c33s_toolkit_core_config:
        app:
            name: "MyApp"
            version: "1.0.0"
            debug: "%kernel.debug%"
        features:
            experimental_ui: false
    
  3. First Use Case Access config values in a controller or service:

    use C33S\Toolkit\CoreConfigBundle\Config\ConfigManager;
    
    class MyController extends AbstractController
    {
        public function index(ConfigManager $configManager)
        {
            $appName = $configManager->get('app.name');
            $debugMode = $configManager->get('app.debug');
    
            return $this->render('index.html.twig', [
                'app_name' => $appName,
                'debug' => $debugMode,
            ]);
        }
    }
    

Implementation Patterns

1. Centralized Configuration

  • Use Case: Replace hardcoded values (e.g., API endpoints, feature flags) with centralized config.
  • Pattern:
    # config/packages/c33s_toolkit_core_config.yaml
    services:
        api:
            base_url: "https://api.example.com/v1"
            timeout: 30
    
    Access via:
    $apiUrl = $configManager->get('services.api.base_url');
    

2. Environment-Specific Overrides

  • Use Case: Override config per environment (e.g., dev, prod).
  • Pattern: Create config/packages/dev/c33s_toolkit_core_config.yaml:
    c33s_toolkit_core_config:
        app:
            debug: true
        features:
            experimental_ui: true
    
    Use config/packages/prod/c33s_toolkit_core_config.yaml for production overrides.

3. Dynamic Feature Flags

  • Use Case: Toggle features without redeploying.
  • Pattern:
    features:
        new_dashboard: true
        legacy_support: false
    
    Check in middleware or controllers:
    if ($configManager->get('features.new_dashboard')) {
        // Enable new dashboard logic
    }
    

4. Integration with Symfony Parameters

  • Use Case: Merge with Symfony’s built-in %parameter% system.
  • Pattern:
    c33s_toolkit_core_config:
        app:
            database: "%env(DATABASE_URL)%"
    
    Access via:
    $dbUrl = $configManager->get('app.database');
    

5. Validation and Defaults

  • Use Case: Enforce config structure and provide defaults.
  • Pattern: Define defaults in config/packages/c33s_toolkit_core_config.yaml:
    c33s_toolkit_core_config:
        app:
            name: "DefaultApp"  # Fallback if not overridden
            timeout: 60         # Default timeout
    

Gotchas and Tips

Pitfalls

  1. Caching Issues

    • Config changes may not reflect immediately if Symfony’s cache is enabled.
    • Fix: Clear cache after config updates:
      php bin/console cache:clear
      
  2. Namespace Collisions

    • Avoid duplicate keys (e.g., app.name vs. application.name).
    • Tip: Use a consistent prefix (e.g., project.app.name).
  3. Type Safety

    • The bundle returns values as strings by default. Cast manually:
      $timeout = (int) $configManager->get('app.timeout');
      
  4. Dependency Injection

    • Ensure ConfigManager is properly autowired in services/controllers.
    • Error: ServiceNotFoundException if the bundle isn’t enabled.

Debugging Tips

  • Dump Config:
    dump($configManager->getAll());
    
  • Check Loaded Config:
    php bin/console debug:config c33s_toolkit_core_config
    

Extension Points

  1. Custom Config Loaders

    • Extend ConfigManager to load from external sources (e.g., database):
      $configManager->extendLoader(function ($key) {
          return DB::table('config')->where('key', $key)->value('value');
      });
      
  2. Event Listeners

    • Listen for config changes (e.g., reload on kernel.request):
      // src/EventListener/ConfigListener.php
      public function onKernelRequest(GetResponseEvent $event)
      {
          $configManager->reload();
      }
      
  3. Validation Rules

    • Add validation via Symfony’s Validator:
      # config/validator/constraints.yaml
      C33S\Toolkit\CoreConfigBundle\Validator\Constraints\ValidConfig:
          groups: [config_validation]
      

Performance

  • Avoid Over-Fetching: Cache getAll() results if used frequently.
  • Lazy Loading: Prefer get('key') over getAll() for specific values.
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.
mehedimi/laravel-amp-mail
happones/laravel-vue-i18n-generator
jwerd/inertia-table
siberfx/flysystem-wasabi
hollyit/token-replace
ippanelcom/laravel-sdk
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel