2017 © Pedro Peláez
 

symfony-bundle settings-bundle

Settings user interface and API for ONGR platform projects

image

ongr/settings-bundle

Settings user interface and API for ONGR platform projects

  • Wednesday, March 22, 2017
  • by saimaz
  • Repository
  • 16 Watchers
  • 5 Stars
  • 13,916 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 12 Forks
  • 5 Open issues
  • 11 Versions
  • 0 % Grown

The README.md

ONGR Settings Bundle

Settings Bundle provides settings API and simple user interface for setting management., (*1)

What's inside:, (*2)

  • Settings features toggle (for features on/off).
  • Personal settings for every user, that only he can change (cookie based).
  • API for every setting control.
  • Simple and minimal web interface.
  • Multi type settings: yaml, boolean, text.
  • Cache layer for global settings.

This bundle is independent from ONGR platform and can be used in your project on its own with few dependencies., (*3)

If you need any help, stack overflow is the preferred and recommended way to ask questions about ONGR bundles and libraries., (*4)

Build Status Coverage Status Latest Stable Version Scrutinizer Code Quality, (*5)

Documentation

The online documentation of the bundle can be found in http://docs.ongr.io. Docs source is stored within the repo under Resources/doc/, so if you see a typo or problem, please submit a PR to fix it!, (*6)

For contribution to the documentation you can find it in the contribute topic., (*7)

Installation

Step 1: Install Settings bundle

FilterManager bundle is installed using Composer., (*8)

$ composer require ongr/settings-bundle "~1.0"

Please note that settings bundle requires Elasticsearch bundle, guide on how to install and configure it can be found here., (*9)

Step 2: Enable ONGR bundles

Register Settings bundle and all required dependencies in your AppKernel:, (*10)

// app/AppKernel.php
<?php

public function registerBundles()
{
    $bundles = array(
        // ...
        new FOS\JsRoutingBundle\FOSJsRoutingBundle(),
        new JMS\SerializerBundle\JMSSerializerBundle(),
        new ONGR\CookiesBundle\ONGRCookiesBundle(),
        new ONGR\ElasticsearchBundle\ONGRElasticsearchBundle(),
        new ONGR\FilterManagerBundle\ONGRFilterManagerBundle(),
        new ONGR\SettingsBundle\ONGRSettingsBundle(),
        // ...
    );

    // ...
}

Step 3: Add configuration

Add minimal configuration for Elasticsearch bundle. With these configs all settings will be saved to separate Elasticsearch index named settings., (*11)

# app/config/config.yml

ongr_elasticsearch:
    managers:
        settings:
            index:
                index_name: settings
                settings:
                    number_of_shards: 2
                    number_of_replicas: 0
            mappings:
                - ONGRSettingsBundle

If you already using ONGR Elasticsearch bundle, merge your current configuration with this one: add settings connection to your current list of connections and add settings manager to current list of managers. Read more about ElasticsearchBundle configuration., (*12)

Also add routing configuration for settings API and web interface., (*13)

#app/config/routing.yml

# FOS JS bundle route map, if you have it already skip this one.
fos_js_routing:
    resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.xml"

# ONGR settings management route map. You might want to secure it under some firewall.
ongr_settings_private_routing:
    resource: "@ONGRSettingsBundle/Resources/config/routing/management.yml"
    prefix: /settings

# Public routes for ONGR settings. Do not add them to the firewall unless you know what you are doing.
ongr_settings_public_routing:
    resource: "@ONGRSettingsBundle/Resources/config/routing/public.yml"
    prefix: /s

Under /settings there will be all the parts of urls for settings management. For example general settings panel will be at /settings/general_settings_list and personal settings panel at /settings/settings. You can change map prefix as you like., (*14)

Under /s/ in public route map there will be a route for settings profile enabling by link. This is a landing page to enable or disable profile for the user. It's up to you to secure this prefix or not. You can map both resources under the same prefix, there will never be the same routes in both of them., (*15)

Step 4: Create index and install assets

Create an Elasticsearch index by running this command in your terminal:, (*16)


bin/console ongr:es:index:create -m settings

More info about all commands can be found in the Elasticsearch bundle commands chapter., (*17)

We strongly recommend to have a separate index for your settings (as in example above) so your business data won't mix up with settings., (*18)

Web interface won't work without assets. Install them by using this command in your terminal:, (*19)


bin/console assets:install --symlink

Step 5: Check how it works

Yes, you can check how it works, but it is NOT ready for production yet. At this moment all settings management is public. Don't forget to setup firewall and protect your_settings_prefix endpoint., (*20)

Visit /{your_settings_prefix}/settings. You should see admin panel of general settings., (*21)

Usage

Global settings.

Visit /{your_management_settings_prefix}/settings and create settings you want to use in your application. There is a selection of profiles when you create a setting. After you create a setting and want to use it in website you have to activate a profile (see profile section)., (*22)

There is a Twig extension to use settings in the templates., (*23)

{{ ongr_setting('setting_name', 'default value') }}, (*24)

e.g. if you want to have features toggle you can create bool setting and use extension in if statement:, (*25)

``` {% if ongr_setting('setting_name') %}, (*26)

show something cool

{% endif %} ```, (*27)

Profiles

Profiles are like grouped settings where you can enable or disable all of them at once. The setting can be assigned for multiple profiles. You can find profiles management page at /your_management_settings_prefix/profiles., (*28)

To create a profile simply create your first setting with a new profile and it will appear in the profiles page., (*29)

License

This bundle is covered by the MIT license. Please see the complete license in the bundle LICENSE file., (*30)

The Versions