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

craue/config-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require craue/config-bundle
    

    Enable the bundle in config/bundles.php:

    return [
        Craue\ConfigBundle\CraueConfigBundle::class => ['all' => true],
    ];
    
  2. Database Migration: Generate and run migrations:

    php bin/console doctrine:migrations:diff
    php bin/console doctrine:migrations:migrate
    

    (Alternative: php bin/console doctrine:schema:update --force)

  3. First Use Case: Define a config key via YAML (e.g., config/settings.yml):

    parameters:
        my_app:
            feature_flag: false
            api_endpoint: "https://api.example.com"
    

    Access it in a controller/service:

    $this->container->get('craue_config.manager')->get('my_app.feature_flag');
    

Implementation Patterns

Core Workflows

  1. Configuration Management:

    • Define: Use config/settings.yml to declare keys (e.g., app.max_upload_size).
    • Access: Inject Craue\ConfigBundle\Manager\ConfigManagerInterface (alias: craue_config.manager) to fetch values:
      $value = $configManager->get('app.max_upload_size', 10); // Default: 10
      
    • Update: Use the admin UI (if routed) or manually via ConfigManager::set().
  2. Environment-Specific Configs: Override settings per environment (e.g., config/settings/dev.yml):

    parameters:
        app.debug_mode: true
    
  3. Dependency Injection: Bind configs to services via constructor injection:

    public function __construct(private ConfigManagerInterface $configManager) {}
    
  4. Validation: Use Symfony’s validator constraints in YAML:

    parameters:
        app.timeout:
            value: 30
            type: integer
            min: 1
            max: 60
    

Integration Tips

  • Event Listeners: Subscribe to ConfigUpdatedEvent to react to changes:
    use Craue\ConfigBundle\Event\ConfigUpdatedEvent;
    
    public function onConfigUpdated(ConfigUpdatedEvent $event) {
        $this->logger->info('Config updated:', [$event->getKey() => $event->getValue()]);
    }
    
  • Caching: Enable Redis/Memcached via craue_config.cache config to reduce DB hits.
  • Security: Restrict admin access to the /settings route via firewall rules.

Gotchas and Tips

Pitfalls

  1. Migration Conflicts:

    • If the craue_config table exists but is misconfigured, drop it manually:
      php bin/console doctrine:schema:drop --force
      php bin/console doctrine:migrations:migrate
      
  2. Caching Issues:

    • Clear cache after manual config updates:
      php bin/console cache:clear
      
    • Disable caching during development (craue_config.cache: false in config).
  3. Type Safety:

    • Unvalidated configs return null or defaults. Always provide fallbacks:
      $timeout = $configManager->get('app.timeout', 30); // Default: 30
      
  4. Admin UI Quirks:

    • The default UI may not support nested keys (e.g., app.nested.value). Use the API (ConfigManager) for complex structures.

Debugging

  • Log Configs: Dump all configs to debug:
    $this->logger->debug('All configs:', $configManager->all());
    
  • Check DB: Verify the craue_config table has entries:
    SELECT * FROM craue_config WHERE `key` LIKE 'app.%';
    

Extension Points

  1. Custom Storage: Override the default ConfigStorage to use a custom backend (e.g., Redis):

    # config/packages/craue_config.yaml
    craue_config:
        storage: App\Custom\RedisConfigStorage
    
  2. Event Subscribers: Extend ConfigUpdatedEvent to trigger actions (e.g., restart workers):

    $eventDispatcher->addListener(ConfigUpdatedEvent::class, [$this, 'handleConfigUpdate']);
    
  3. Validation Rules: Add custom validators by implementing Craue\ConfigBundle\Validator\ConstraintValidatorInterface.

  4. API Endpoints: Build custom APIs for config management:

    use Symfony\Component\HttpFoundation\JsonResponse;
    
    public function getConfig(Request $request): JsonResponse {
        return new JsonResponse($this->configManager->all());
    }
    
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.
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
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment