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

Millwright Configuration Bundle Laravel Package

zerkalica/millwright-configuration-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the bundle to your composer.json:

    composer require zerkalica/millwright-configuration-bundle
    

    Register the bundle in config/app.php under providers:

    Zerkalica\MillwrightConfigurationBundle\MillwrightConfigurationBundle::class,
    
  2. Configuration File Create a config file (e.g., config/millwright.php) with your service container settings:

    return [
        'services' => [
            'database' => [
                'host' => env('DB_HOST'),
                'port' => env('DB_PORT'),
            ],
            'cache' => [
                'driver' => env('CACHE_DRIVER'),
                'prefix' => 'laravel_',
            ],
        ],
    ];
    
  3. First Use Case Access configurations in a service provider or controller:

    $config = $this->container->get('millwright.configuration');
    $dbHost = $config['services']['database']['host'];
    

Implementation Patterns

Service Configuration Management

  • Centralized Configuration Use the bundle to consolidate all service-specific configurations (e.g., database, cache, queues) into a single, structured file. Avoid hardcoding values in multiple places.

  • Environment Overrides Combine with Laravel’s .env to dynamically override configurations:

    // config/millwright.php
    return [
        'services' => [
            'database' => [
                'host' => env('DB_HOST', 'localhost'), // Default fallback
            ],
        ],
    ];
    
  • Dependency Injection Bind configurations to interfaces or abstract classes for better testability:

    $this->app->bind('config.services.database', function ($app) {
        return $app['millwright.configuration']['services']['database'];
    });
    

Workflows

  1. Configuration Validation Validate configurations during bootstrapping (e.g., in a service provider):

    $config = $this->container->get('millwright.configuration');
    if (!in_array($config['services']['cache']['driver'], ['file', 'redis'])) {
        throw new \RuntimeException('Invalid cache driver');
    }
    
  2. Dynamic Configuration Loading Load configurations from external sources (e.g., API, database) and merge them with the bundle’s config:

    $externalConfig = Cache::get('dynamic_config');
    $mergedConfig = array_merge(
        $this->container->get('millwright.configuration'),
        $externalConfig
    );
    
  3. Configuration Caching Cache the resolved configurations to avoid repeated file reads:

    $config = Cache::remember('millwright_config', 60, function () {
        return $this->container->get('millwright.configuration');
    });
    

Gotchas and Tips

Pitfalls

  • Outdated Package The last release is from 2015, so expect potential compatibility issues with modern Laravel versions (8+). Test thoroughly or fork the package for updates.

  • No Built-in Validation The bundle does not validate configuration structure or values by default. Implement custom validation logic (e.g., using Laravel’s Validator or array_key_exists).

  • Namespace Conflicts The bundle uses Zerkalica\MillwrightConfigurationBundle, which may conflict with other packages. Prefix your service bindings to avoid collisions:

    $this->app->bind('millwright.database.config', ...);
    

Debugging

  • Configuration Not Loading? Ensure the bundle is registered in config/app.php after Laravel’s core providers. Check for typos in the config file path (config/millwright.php).

  • Circular Dependencies If configurations depend on other services (e.g., cache), resolve them in the correct order:

    // Resolve cache config first
    $cacheConfig = $this->container->get('millwright.configuration')['services']['cache'];
    Cache::set($cacheConfig['prefix'] . 'key', 'value');
    

Extension Points

  • Custom Configuration Sources Extend the bundle by creating a custom loader (e.g., for YAML or JSON files):

    $this->app->extend('millwright.configuration', function ($config) {
        $customConfig = json_decode(file_get_contents('config/custom.json'), true);
        return array_merge($config, $customConfig);
    });
    
  • Configuration Events Dispatch events when configurations are loaded or modified:

    event(new ConfigLoaded($this->container->get('millwright.configuration')));
    
  • Testing Mock configurations in tests:

    $this->app->instance('millwright.configuration', [
        'services' => ['database' => ['host' => 'test_host']],
    ]);
    
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