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

Symfony Settings Bundle Laravel Package

dolmitos/symfony-settings-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require dolmitos/symfony-settings-bundle
    

    Register the bundle in config/bundles.php:

    Dolmitos\SettingsBundle\DolmitosSettingsBundle::class => ['all' => true],
    
  2. First Configuration Define settings in config/packages/dolmitos_settings.yaml:

    dolmitos_settings:
        settings:
            app:
                title: "My App"
                debug: "%kernel.debug%"
                features:
                    new_ui: true
    
  3. Accessing Settings Inject the Settings service in a controller or service:

    use Dolmitos\SettingsBundle\Settings\SettingsInterface;
    
    public function __construct(private SettingsInterface $settings) {}
    
    public function index()
    {
        $title = $this->settings->get('app.title');
        // Use $title in your logic
    }
    
  4. Environment Overrides Override settings in .env:

    DOLMITOS_SETTINGS_APP_TITLE="Custom Title"
    DOLMITOS_SETTINGS_APP_DEBUG=false
    

Implementation Patterns

1. Structured Configuration

Use nested YAML for hierarchical settings:

dolmitos_settings:
    settings:
        api:
            endpoints:
                v1: "https://api.example.com/v1"
                v2: "https://api.example.com/v2"
                enabled: true

Access via:

$this->settings->get('api.endpoints.v1'); // Returns "https://api.example.com/v1"

2. Dynamic Settings with Environment Variables

Leverage .env for runtime flexibility:

# config/packages/dolmitos_settings.yaml
dolmitos_settings:
    settings:
        cache:
            driver: "%env(DOLMITOS_SETTINGS_CACHE_DRIVER)%"
            ttl: "%env(int:DOLMITOS_SETTINGS_CACHE_TTL)%"

Override in .env:

DOLMITOS_SETTINGS_CACHE_DRIVER="redis"
DOLMITOS_SETTINGS_CACHE_TTL=3600

3. Validation Rules

Define validation in YAML:

dolmitos_settings:
    settings:
        mail:
            from: "noreply@example.com"
            smtp:
                host: "smtp.example.com"
                port: 587
    validation:
        mail:
            from: "email"
            smtp:
                host: "required|string"
                port: "required|integer|min:1|max:65535"

Trigger validation via:

$this->settings->validate();

4. Caching Strategies

Enable caching for performance:

dolmitos_settings:
    cache: true  # Uses Symfony cache system
    cache_key: "app_settings"  # Optional custom cache key

Clear cache when settings change:

$this->settings->clearCache();

5. Integration with Symfony Forms

Bind settings to forms for admin panels:

use Dolmitos\SettingsBundle\Form\SettingsType;

$form = $this->createForm(SettingsType::class, $this->settings->getAll());

Gotchas and Tips

Pitfalls

  1. Circular Dependencies Avoid injecting SettingsInterface in the bundle’s own services to prevent circular references.

  2. Cache Invalidation Forgetting to clear the cache (php bin/console cache:clear) after modifying settings in YAML/ENV may lead to stale values.

  3. Validation Errors Silent failures occur if validation rules are malformed. Always check logs or use:

    $errors = $this->settings->validate();
    if ($errors) {
        // Handle errors
    }
    

Debugging Tips

  1. Dump All Settings Use a twig template or controller to debug:

    dd($this->settings->getAll());
    
  2. Environment-Specific Overrides Use %kernel.environment% in YAML to conditionally load settings:

    dolmitos_settings:
        settings:
            debug_bar: "%kernel.debug%"
    
  3. Parameter Precedence Order of precedence (highest to lowest): .env.local > .env > config/packages/dolmitos_settings.yaml.


Extension Points

  1. Custom Validators Implement Dolmitos\SettingsBundle\Validator\ConstraintValidatorInterface for bespoke validation.

  2. Event Listeners Subscribe to SettingsLoadedEvent to react to setting changes:

    use Dolmitos\SettingsBundle\Event\SettingsLoadedEvent;
    use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    
    class MySubscriber implements EventSubscriberInterface
    {
        public static function getSubscribedEvents()
        {
            return [
                SettingsLoadedEvent::NAME => 'onSettingsLoaded',
            ];
        }
    
        public function onSettingsLoaded(SettingsLoadedEvent $event)
        {
            // Logic here
        }
    }
    
  3. Database Backend While not natively supported, extend the bundle by implementing a custom SettingsProvider to fetch settings from a database.

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.
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon
itsemon245/lamet
baks-dev/dashboard
amoifr/pickle-panther-bundle
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle