Package Data | |
---|---|
Maintainer Username: | patkruk |
Maintainer Contact: | patkruk@gmail.com (Patryk Kruk) |
Package Create Date: | 2014-01-24 |
Package Last Update: | 2014-10-01 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-23 03:17:02 |
Package Statistics | |
---|---|
Total Downloads: | 683 |
Monthly Downloads: | 2 |
Daily Downloads: | 0 |
Total Stars: | 24 |
Total Watchers: | 2 |
Total Forks: | 5 |
Total Open Issues: | 0 |
Provides a basic container for your configuration parameters and settings.
Key-value pairs are stored in your database and, if cache is enabled in the package configuration file, also in your caching system. When you try to retrieve a value from the container, the caching system is always checked first and if the value exists, the database layer is never touched. In case the value is not in your cache, it's retrieved from the persistent storage and also automatically added to the caching layer.
The package uses the current environment name to oraganize settings in order to allow you have different values based on the environment the application is running in. Therefore, a value added while in "local", won't be available in "production" or "testing".
One of the artisan commands the package offers, allows you to import a json file into the persistant storage system. See below for more info.
Add the package to your composer.json file:
"require": {
"patkruk/laravel-cached-settings": "dev-master"
}
Use composer to install the package:
$ composer update
Pusblish a configuration file using artisan:
$ php artisan config:publish patkruk/laravel-cached-settings
Add an alias to the bottom of app/config/app.php
'CachedSettings' => 'Patkruk\LaravelCachedSettings\Facades\CachedSettings',
and register this service provider at the bottom of the $providers
array:
'Patkruk\LaravelCachedSettings\LaravelCachedSettingsServiceProvider',
$ php artisan migrate --package=patkruk/laravel-cached-settings
You can specify the table name in the published package config file.
CachedSettings::set('datetime_format', 'Y-m-d H-i-s');
You can use "dot" notation to imitate a multi-dimensional array:
CachedSettings::set('email.admin', 'admin@example.com');
CachedSettings::set('email.editor', 'editor@example.com');
CachedSettings::get('datetime_format');
CachedSettings::get('email.editor');
CachedSettings::get('email.host', 'default_value');
CachedSettings::has('email.admin');
It checks the persistent storage and returns a boolean.
CachedSettings::set('email.admin', 'administrator@example.com');
CachedSettings::delete('email.admin');
This command removes a setting from the caching and persistent storages!
CachedSettings::deleteAll();
This command removes all settings from the caching and persistent storages!
If you have changed a value directly in the database or just want to make sure that your cache is up-to-date, you can refresh individual settings.
CachedSettings::refresh('email.admin');
The value in your cache is updated with the one from the database.
You can update your cache with the values from the database with just one command.
CachedSettings::refreshAll();
CachedSettings::getKeys();
This command returns an array of all keys currently stored in the database.
CachedSettings::getKeysAndValues();
This command returns an associative array of all settings.
CachedSettings::getAll();
This command returns a dump of the entire table.
The packages provides 5 different artisan commands for your convenience:
$ php artisan cached-settings:set email.admin admin@example.com
Or simply run the command below and provide the needed info when asked:
$ php artisan cached-settings:set
You can always specify the environment by using the "env" option:
$ php artisan cached-settings:set email.admin admin@example.com --env=production
$ php artisan cached-settings:get email.admin
Or simply:
$ php artisan cached-settings:get
$ php artisan cached-settings:refresh-all
$ php artisan cached-settings:delete-all
$ php artisan cached-settings:import-file /home/vagrant/import_data.json
This command allows you to import a file with a JSON object which has string or number fields only. Example:
{
"email.admin": "admin@example.com",
"email.editor": "editor@example.com",
"email.send": "false",
"security.min_password_length": 15
}
As always, you can specify the environment by using the "env" option:
$ php artisan cached-settings:import-file /home/vagrant/import_data.json --env=production
Laravel Cached Settings is open-sourced software licensed under the MIT license