2017 © Pedro Peláez
 

library key-value-bundle

Zicht KeyValue Bundle

image

zicht/key-value-bundle

Zicht KeyValue Bundle

  • Friday, June 29, 2018
  • by zicht-jenkins
  • Repository
  • 3 Watchers
  • 0 Stars
  • 25 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 16 Versions
  • 0 % Grown

The README.md

zicht/key-value-bundle

A bundle that stores pre-specified key-value pairs., (*1)

Installation

composer require zicht/key-value-bundle
{
    "scripts": {
        "post-install-cmd": [
            "Zicht\\Bundle\\KeyValueBundle\\Composer\\ScriptHandler::createKeyValueStorageDirectory"
        ],
        "post-update-cmd": [
            "Zicht\\Bundle\\KeyValueBundle\\Composer\\ScriptHandler::createKeyValueStorageDirectory"
        ]
    }
}

How to

Define a KeysDefinerInterface or extend AbstractKeyDefiner service in your own bundle and tag this service with zicht_bundle_key_value.keys_definer, (*2)

class FooBundleKeyDefiner extends AbstractKeyDefiner
{
    /** @var SchemaService */
    private $schemaService;

    public function __construct(SchemaService $schemaService)
    {
        $this->schemaService = $schemaService;
    }

    public function getPredefinedKeys()
    {
        return [
            PredefinedKey::createKey(
                name: 'zicht.foo_bundle.my_predefined_key',
                default:  $this->getDefaultValue('zicht.foo_bundle.my_predefined_key', false),
                pretty_name: 'My predefined key',
                form_type: 'checkbox',
                form_options: ['required' => false]
            ),
            PredefinedKey::createKey(
                'zicht.foo_bundle.display_almost_soldout_threshold',
                100,
                'Set the threshold-amount for showing "almost soldout!" on various places in the website',
                'number'
            ),
            PredefinedKey::createKey(
                'zicht.foo_bundle.zipcode_required', // THIS IS LOCALE DEPENDENT
                $this->getDefaultValue('', ['nl' => true, 'en' => false]),
                'Show the zip-code input when creating a user account, this is not required for all visitors',
                'zicht_locale_dependent_type',
                ['type' => 'checkbox']
            ),
            PredefinedJsonSchemaKey::createKey(
                $this->schemaService,
                '/bundles/yourbundle/key-value-storage/foo-config.schema.json', # relative to the public web dir
                $this->getDefaultValue('foo-config.schema.json', [])
            ),
        ];
    }
}

Every defined key has a unique key and a default value. When the user wants to change the associated value, the custom value is stored in the database as a json_data field., (*3)

To distinguish keys between bundles it's recommended to use the following configuration: vendor.bundle_name.purpose_of_this_key, (*4)

Every defined key has a form type and form options, allowing simple input, such as form type 'text', or complicated inputs, such as form type 'file' with options ['data_class' => null'], where the latter will ask for a file upload., (*5)

Make sure the directory web/media/key_value_storage exists and is writable., (*6)

Configuration

zicht_key_value:
    locales:
        -
            locale: nl
            label: Nederlands
        -
            locale: en
            label: Engels
    json_defaults:
        zicht.foo_bundle.homepage_url: '{"nl":"/nl/thuis","en":"/en/home"}'
    defaults:
        zicht.foo_bundle.display_threshold: 200
    cache:
        type: service
        id: cache.app # or another service you have defined

Cache

If enabled, cached items are prefixed with KeyValueStorageManager::CACHE_TAG and tagged with KeyValueStorageManager::CACHE_TAG., (*7)

Service

If you want to use the key value storage at any place in your code. A storage service is available. Registered with the name zicht_bundle_key_value.key_value_storage_manager., (*8)

Twig

There is also a twig extension available. Use the get_from_key_value_storage method with the key parameter to return the value., (*9)

Symfony

Add the new Zicht\Bundle\KeyValueBundle\ZichtKeyValueBundle(), to your AppKernel registerBundles., (*10)

Sonata

To use the admin zicht_bundle_key_value.admin.key_value_admin use this in your sonata_admin config to show the admin for your key's., (*11)

To change a value in one of your keys you have to add. After you have added the value it becomes editable., (*12)

TODO

  • Make a list of questions that should be asked (and have "yes" as an answer) before deciding to define a key. Questions could be: is this value modified often? Do we want to give access to the client to this value and/or modifications? Are there alternatives? Can/will this value be used in a dependecyinjection pattern? This will prevent creating keys that are not suited to be in the KeyValueStorage., (*13)

  • Build a bridge to decouple Symfony and Sonata., (*14)

Maintainer

The Versions

29/06 2018

dev-release/3.x

dev-release/3.x

Zicht KeyValue Bundle

  Sources   Download

The Requires

 

The Development Requires

by Zicht online

29/06 2018

3.0.1

3.0.1.0

Zicht KeyValue Bundle

  Sources   Download

The Requires

 

The Development Requires

by Zicht online

21/06 2018

3.0.0

3.0.0.0

Zicht KeyValue Bundle

  Sources   Download

The Requires

 

The Development Requires

by Zicht online

27/03 2018

dev-release/2.x

dev-release/2.x

Zicht KeyValue Bundle

  Sources   Download

The Requires

 

The Development Requires

by Zicht online

12/03 2018

dev-feature/remove-zicht-admin-dependency

dev-feature/remove-zicht-admin-dependency

Zicht KeyValue Bundle

  Sources   Download

The Requires

 

The Development Requires

by Zicht online

12/03 2018

2.1.1

2.1.1.0

Zicht KeyValue Bundle

  Sources   Download

The Requires

 

The Development Requires

by Zicht online

08/03 2018

2.1.0

2.1.0.0

Zicht KeyValue Bundle

  Sources   Download

The Requires

 

The Development Requires

by Zicht online

19/02 2018

2.0.3

2.0.3.0

Zicht KeyValue Bundle

  Sources   Download

The Requires

 

The Development Requires

by Zicht online

10/01 2018

2.0.2

2.0.2.0

Zicht KeyValue Bundle

  Sources   Download

The Requires

 

The Development Requires

by Zicht online

24/08 2017

2.0.1

2.0.1.0

Zicht KeyValue Bundle

  Sources   Download

The Requires

 

The Development Requires

by Zicht online

10/08 2017

2.0.0

2.0.0.0

Zicht KeyValue Bundle

  Sources   Download

The Requires

 

The Development Requires

by Zicht online

24/07 2017

dev-release/1.0.x

dev-release/1.0.x

Zicht KeyValue Bundle

  Sources   Download

The Requires

 

The Development Requires

by Zicht online

24/07 2017

1.2.0

1.2.0.0

Zicht KeyValue Bundle

  Sources   Download

The Requires

 

The Development Requires

by Zicht online

19/06 2017

1.1.0

1.1.0.0

Zicht KeyValue Bundle

  Sources   Download

The Requires

 

The Development Requires

by Zicht online

10/02 2017

1.0.1

1.0.1.0

Zicht KeyValue Bundle

  Sources   Download

The Requires

 

The Development Requires

by Zicht online

03/02 2017

1.0.0

1.0.0.0

Zicht KeyValue Bundle

  Sources   Download

The Requires

 

The Development Requires

by Zicht online