PHP code example of survos / settings-bundle

1. Go to this page and download the library: Download survos/settings-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

survos / settings-bundle example snippets


use Survos\SettingsBundle\Service\SettingsManagerInterface;

final readonly class BrandingController
{
    public function __construct(private SettingsManagerInterface $settings) {}

    public function updateTenantBranding(): void
    {
        $this->settings->set('logo', '/uploads/tenant/acme.svg', scope: 'tenant:acme');
        $this->settings->set('tagline', 'Archives for everyone', scope: 'tenant:acme');
        $this->settings->set('displayed_locales', ['en', 'es'], scope: 'tenant:acme');
    }
}

$logo = $settings->get('logo', '/default-logo.svg', scope: 'tenant:acme');
$locales = $settings->get('displayed_locales', ['en'], scope: 'tenant:acme');

use Survos\SettingsBundle\Service\ScopeResolverInterface;

final readonly class TenantScopeResolver implements ScopeResolverInterface
{
    public function __construct(private TenantContext $tenantContext) {}

    public function currentScope(): ?string
    {
        return $this->tenantContext->tenant()?->code
            ? 'tenant:'.$this->tenantContext->tenant()->code
            : null;
    }
}
yaml
# config/packages/survos_settings.yaml
survos_settings:
    # `global` stores global settings with an explicit scope. Use 'global' if your app prefers an explicit row key.
    global_scope: global
    fallback_to_global: true
    settings:
        logo:
            type: Symfony\Component\Form\Extension\Core\Type\UrlType
            options: { label: Logo URL }
            default: /default-logo.svg
        tagline:
            options: { label: Tagline }
            default: Welcome
        displayed_locales:
            type: Symfony\Component\Form\Extension\Core\Type\ChoiceType
            options:
                label: Displayed locales
                multiple: true
                choices: { English: en, Spanish: es, French: fr }
            default: [en]