marcin_jozwikowski/settings_in_db_bundle

A Symfony2 bundle that allows an easy key-value storage in DB

0.1.4 2016-09-09 21:13 UTC

This package is auto-updated.

Last update: 2024-05-29 03:27:48 UTC


README

A Symfony2 bundle that allows an easy key-value storage in DB

Installation

  1. Add as composer dependency:
composer require marcin_jozwikowski/settings_in_db_bundle
  1. Add in application kernel:
class AppKernel extends Kernel
{
    public function registerBundles()
    {
    //...
    $bundles[] = new \MarcinJozwikowski\SettingsInDBBundle\SettingsInDBBundle();
    return $bundles;
    }
}
  1. Update database schema:
php app/console doctrine:schema:update --force

##Usage

  1. Access DB stored values through service:
  //in controller
  $val = $this->get('settings_in_db_service')->read('key', 'defaultValue');

##Configuration

Default configuration:

   settings_in_db:
      allow_inserts: true
      return_null_on_not_found: false 
      read_all_entries_at_first_use: true
  • allow_inserts - if set to true, persists a new key-value pair if none is found
  • return_null_on_not_found - if nothing found and allow_inserts = false, returns null instead of throwing an exception
  • read_all_entries_at_first_use - if set to true loads all records at first use and searches in internal array insted of querying