phpmob/settings-bundle

Just a Symfony settings bundle.

Installs: 101 055

Dependents: 3

Suggesters: 0

Security: 0

Stars: 5

Watchers: 3

Forks: 1

Open Issues: 1

Type:symfony-bundle

1.2.2 2018-06-09 18:11 UTC

This package is auto-updated.

Last update: 2024-04-18 21:51:34 UTC


README

Scrutinizer Code Quality Code Coverage Build Status Latest Stable Version Latest Unstable Version

Just a Settings Library.

Installation

Install via composer.

$ composer require phpmob/settings-bundle

Using with cache

$ composer require cache/filesystem-adapter

Now you can use built-in \PhpMob\Settings\Manager\CachedManager.

Alternative using built-int symfony framework cache see - framework/cache

Sample config

# use with doctrine orm
doctrine:
    orm:
        mappings:
            PhpMobSettings:
                type: xml
                is_bundle: false
                prefix: PhpMob\Settings\Model
                dir: '%kernel.project_dir%/vendor/phpmob/settings-bundle/src/Resources/config/doctrine/model'


phpmob_settings:
    cache:
        service: cache.flysystem
    schemas:
        section1:
            label: Section1
            settings:
                key1: ~
        section2:
            label: Section2
            settings:
                key1:
                    value: key1Value
                key2:
                    label: SectionKey2
                    value: key2value
                    blueprint:
                        options:
                            label: SectionKey2Label
                        constraints:
                            NotBlank: ~
                gender:
                    label: Gender
                    value: f
                    blueprint:
                        type: Symfony\Component\Form\Extension\Core\Type\ChoiceType
                        options:
                            required: true
                            choices:
                                Man: m
                                Feman: f
                birthday:
                    type: date
                    label: Birthday
                    value: "1988-02-10"
                    blueprint:
                        type: Symfony\Component\Form\Extension\Core\Type\BirthdayType
                datetime:
                    type: datetime
                    label: DateTime
                    value: ~
                    blueprint:
                        type: Symfony\Component\Form\Extension\Core\Type\DateTimeType

Ownered settings

Configuration for owner (user) aware settings. Controller used PhpMobSettingsBundle:Update:userUpdate.

phpmob_settings:
    schemas:
        section1:
            owner_aware: true
            label: Section1
            settings:
                key1: ~

Updater Routing

See example routing in src/Resources/config/routing.xml or you can customize with:

your_route_name:
    path: /settings/{section}
    defaults:
        _controller: PhpMobSettingsBundle:Update:globalUpdate
        _template: @yourtemplate # default @PhpMobSetting/default.html.twig
        _flash: ~ # flash message after update
        _redirect: ~ # redirect after update

Custom form type to display description setting in form view.

<?php

namespace YourBundle\Form\Type;

use PhpMob\SettingsBundle\Form\Type\AbstractBlueprintType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;

class YourSettingType extends AbstractBlueprintType
{
    /**
     * {@inheritdoc}
     */
    public function getParentType(): string
    {
        return CheckboxType::class;
    }
}

And in setting configuration.

phpmob_settings:
    schemas:
        section1:
            owner_aware: true
            label: Section1
            settings:
                key1:
                    type: boolean
                    label: 'Key 1'
                    value: true
                    blueprint:
                        type: YourBundle\Form\Type\YourSettingType

using in twig

Getter setting

{{ settings_get('section.key') }}

{# owner aware setting #}
{{ settings_get('section.key', app.user) }}

Setter setting

{{ settings_set('section.key', 'value') }}

{# owner aware setting #}
{{ settings_set('section.key', 'value', app.user) }}

Sample Admin Screen

screen

Contributing

Would like to help us and build the developer-friendly php code? Just follow our Coding Standards and test your code — see tests, spec.

Let Fork and PR now!

Coding Standards

When contributing code to PhpMob, you must follow its coding standards.

PhpMob follows the standards defined in the PSR-0, PSR-1 and PSR-2 documents.

$ ./bin/ecs check src --fix

Tests

$ ./bin/phpunit

LICENSE

MIT