creavo/option-bundle
Symfony bundle to store and retrieve application options/settings via a service, Twig helper, or console commands. Persists values in Doctrine, supports typed options, optional eager loading, and PSR-16 simple cache for faster reads.
please use composer with
composer require creavo/option-bundle
Add the bundle to your app/AppKernel.php with
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
[...],
new Creavo\OptionBundle\CreavoOptionBundle(),
];
return $bundles;
}
[...]
}
Update the doctrine-schema - use
php bin/console doctrine:schema:update
or do a migration:
php bin/console doctrine:migration:diff
php bin/console doctrine:migration:migrate
add the following lines to your app/config/config.yml:
creavo_option:
fetch_all: false
simple_cache_service: null
Psr\SimpleCache\CacheInterface) - when null an ArrayCache for the request is usedset a setting
$container->get('crv.option')->set('option-name', $optionValue, $optionType, $section);
get a setting (cached):
$optionValue=$container->get('crv.option')->get('option-name');
get a setting (uncached - will fetch value freshly from database without the cache)
$optionValue=$container->get('crv.option')->getUnCached('option-name');
to get a value in twig use
{{ crv_ob_setting('option-name') }}
set a setting with php bin/console crv:ob:set name value [type] [section] type and section are optional - if you omit them, the type will be a string and section null.
$ php bin/console crv:ob:set test1 "2017-09-16 12:00:00" dateTime parameters
setting the hash of the last-commit
php bin/console crv:ob:set app_version `git rev-parse --short HEAD`
to get a setting use get:
$ php bin/console crv:ob:get test1
+-----------+---------------------+
| Element | Value |
+-----------+---------------------+
| name | test1 |
| type | dateTime |
| section | parameters |
| updatedAt | 2017-09-16 12:30:17 |
| value | 2017-09-16 12:00:00 |
+-----------+---------------------+
How can I help you explore Laravel packages today?