Download the PHP package harmony/settings-manager-bundle without Composer
On this page you can find all versions of the php package harmony/settings-manager-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download harmony/settings-manager-bundle
More information about harmony/settings-manager-bundle
Files in harmony/settings-manager-bundle
Package settings-manager-bundle
Short Description Provides a nice way to define variables and inject them into application parts
License MIT
Informations about the package settings-manager-bundle
SettingsManagerBundle
Provides a nice way to define variables and inject them into application parts.
- Supporting
bool
,string
,int
,float
,array
as setting values. - Multiple providers.
- User interface.
Jump to
- Quick start
- Usage
- Models
- Setting providers
- Configuration reference
- User interface
- Twig
- Controller
Quick start
-
composer require harmony/settings-manager-bundle
-
Register bundle to
AppKernel.php
(Symfony3) orconfig/bundles.php
(Symfony4) -
Add an example configuration to
app/config/config.yml
(Symfony3) orconfig/packages/settings_manager.yaml
(Symfony4) - Now, the easiest way to get settings in your services is by using
SettingsRouterAwareTrait
. The service will be automatically injected by autowire. Then just ask for setting:
Usage
To get settings into your services, you have a few choices:
- SettingsRouter
- Service Tag
SettingsRouter
SettingsRouter is pretty straight-forward. It has one main method, called $settingsRouter->get($settingName, $default = null)
, which returns a setting of any type. If the setting is missing, default value will be returned. Other getters are aliases for get
but with declared return types and appropriate default values.
Method name | Default value | Declared return type |
---|---|---|
getString |
'' |
string |
getBool |
false |
bool |
getInt |
0 |
int |
getFloat |
0.0 |
float |
getArray |
[] |
array |
Service Tag
If you dont want to inject SettingsRouter
or wish for a cleaner service, service tags are here to help. First of all, the service must have a setter, which can be used to inject a setting value. For bool values, the bundle provides the SwitchableTrait
, which adds setEnabled
and isEnabled
methods. Then add a tag on your service with attributes setting
for setting name and method
for method name. Example:
Models
Harmony\Bundle\SettingsManagerBundle\Model\SettingModel
Base setting model.
Property | Type | Description |
---|---|---|
$name | string | Setting name |
$description | string | Setting descrption |
$domain | DomainModel | Domain model |
$tags | Collection[Tag] | Collection of tags |
$type | Enum[Type] | Determines setting value type |
$data | array | Holds actual value for setting |
$providerName | string | Internal field to know from which provider this setting is |
Harmony\Bundle\SettingsManagerBundle\Model\DomainModel
Domain is like a group for settings. Setting cannot exist without domain. The default is named default
, which is also always enabled. Domain can hold only one setting with the same name. Settings with the same names must be in different domains. When a setting is requested, the one from a higher priority domain will be returned.
Property | Type | Description |
---|---|---|
$name | string | Domain name |
$priority | int (default: 0) | Domain priority |
$enabled | bool (default: false) | Is domain enabled indication |
$readOnly | bool (default: false) | is domain only readable indication |
Harmony\Bundle\SettingsManagerBundle\Model\Type
Enum which holds supported types for setting. Values:
- STRING
- BOOL
- INT
- FLOAT
- YAML
- CHOICE
Setting providers
Settings can be pulled from multiple sources. Currently, the bundle comes with 4 settings providers. They can be configured and prioritized. If a setting with the same name will come from >1 providers, setting from provider with higher priority will override settings from lower priority providers.
Settings can be easily mutated in providers using user interface.
Settings providers:
- Simple
- DoctrineORM
- Cookie
- AWS SSM
And additional 2 decorating providers:
- Phpredis
- Predis
Simple settings provider
Harmony\Bundle\SettingsManagerBundle\Provider\SimpleSettingsProvider
This is a provider, which only holds settings collections. Currently, it's being used to hold settings from configuration, but many more can be configured.
To configure additional simple providers, factory is provided because provider can only accept already denormalized objects.
Configuration example:
DoctrineORM settings provider
Harmony\Bundle\SettingsManagerBundle\Provider\DoctrineOrmSettingsProvider
This is a provider which reads and saves settings using EntityManagerInterface
.
Required libraries:
- doctrine/orm
-
I am guessing you already have it :open_mouth:
composer require doctrine/orm acelaya/doctrine-enum-type
Configuration example:
-
Doctrine configuration
-
Create setting entity
-
Update your doctrine schema.
- Register settings provider:
Cookie settings provider
Harmony\Bundle\SettingsManagerBundle\Provider\CookieSettingsProvider
This is a provider, which only enables existing settings by using a cookie. Cookies are encoded, so that they could not be randomly enabled by users.
Required libraries:
-
composer require paragonie/paseto
Paseto
is used to encrypt cookies.Configuration example:
Asymmetric Cookie settings provider
Harmony\Bundle\SettingsManagerBundle\Provider\AsymmetricCookieSettingsProvider
This is a provider, which only enables existing settings by using a cookie. Cookies are encoded with asymmetric private and public keys, so that they could not be randomly enabled by users.
Required libraries:
-
composer require paragonie/paseto
Paseto
is used to encrypt cookies.Configuration example:
AWS SSM settings provider
Harmony\Bundle\SettingsManagerBundle\Provider\AwsSsmSettingsProvider
This is a provider, which is used only for reading and updating existing ssm parameters as settings.
Required libraries:
-
composer require aws/aws-sdk-php
Configuration example:
Phpredis decorating settings provider
Harmony\Bundle\SettingsManagerBundle\Provider\DecoratingRedisSettingsProvider
This provider is used to cache other settings providers like symfony/cache adapters because we want to take advantage of redis data structures for simplier invalidation process.
Required extensions:
-
pecl install redis-3.1.6
Configuration example:
Predis decorating settings provider
Harmony\Bundle\SettingsManagerBundle\Provider\DecoratingPredisSettingsProvider
Same as predis.
Required libraries:
-
composer require predis/predis
Configuration reference
User interface
User interface can be used to change setting values, enable or disable domains.
-
Bundled user interface requires knp-menu-bundle, jsrouting-bundle.
composer require knplabs/knp-menu-bundle friendsofsymfony/jsrouting-bundle
- Include routing file.
That's it. Now go to the /settings
path and you will see the settings user interface.
Twig
The Twig extension is also added to get settings in your twig templates. Just like in SettingsRouter
, first argument is the setting name and the second sets default value.
Controller
Harmony\Bundle\SettingsManagerBundle\Controller\Traits\SettingsControllerTrait
Adds a method to deny access, unless a setting is enabled. It's using SettingsRouter
, which, again, will be injected by autowire.
Contribution
New feature branches should be created from the master branch.
All versions of settings-manager-bundle with dependencies
ext-json Version *
doctrine/collections Version ^1.5
myclabs/php-enum Version ^1.5
ocramius/proxy-manager Version ^2.1
symfony/config Version ^3.4|^4.0
symfony/console Version ^3.4|^4.0
symfony/dependency-injection Version ^3.4|^4.0
symfony/form Version ^3.4|^4.0
symfony/http-foundation Version ^3.4|^4.0
symfony/http-kernel Version ^3.4|^4.0
symfony/options-resolver Version ^3.4|^4.0
symfony/proxy-manager-bridge Version ^3.4|^4.0
symfony/serializer Version ^3.4|^4.0
symfony/validator Version ^3.4|^4.0
symfony/yaml Version ^3.4|^4.0