phpmob / settings-bundle
Just a Symfony settings bundle.
Installs: 105 776
Dependents: 3
Suggesters: 0
Security: 0
Stars: 5
Watchers: 3
Forks: 1
Open Issues: 1
Type:symfony-bundle
Requires
- php: ^7.1
- phpmob/settings: ^1.2
- symfony/form: ^3.3|^4.0
- symfony/framework-bundle: ^3.3|^4.0
- symfony/templating: ^3.3|^4.0
- twig/twig: ^2.0
Requires (Dev)
- cache/filesystem-adapter: ^1.0
- phpspec/phpspec: ^4.0
- phpunit/phpunit: ^5.6
- sylius-labs/coding-standard: ^1.0
Suggests
- cache/filesystem-adapter: To use built-in \PhpMob\Settings\Manager\CachedManager.
README
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
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