{"id":15287373,"url":"https://github.com/ntidev/craueconfigbundle","last_synced_at":"2025-10-07T01:31:33.512Z","repository":{"id":57029129,"uuid":"119862691","full_name":"ntidev/CraueConfigBundle","owner":"ntidev","description":"Database-stored settings made available via a service for your Symfony project.","archived":false,"fork":true,"pushed_at":"2018-02-01T16:33:55.000Z","size":249,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-09-30T15:27:52.042Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"craue/CraueConfigBundle","license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ntidev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-01T16:32:34.000Z","updated_at":"2019-03-20T13:50:06.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ntidev/CraueConfigBundle","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ntidev%2FCraueConfigBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ntidev%2FCraueConfigBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ntidev%2FCraueConfigBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ntidev%2FCraueConfigBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ntidev","download_url":"https://codeload.github.com/ntidev/CraueConfigBundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219877415,"owners_count":16554878,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-30T15:27:58.261Z","updated_at":"2025-10-07T01:31:28.225Z","avatar_url":"https://github.com/ntidev.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Information\n\n[![Build Status](https://travis-ci.org/craue/CraueConfigBundle.svg?branch=master)](https://travis-ci.org/craue/CraueConfigBundle)\n[![Coverage Status](https://coveralls.io/repos/github/craue/CraueConfigBundle/badge.svg?branch=master)](https://coveralls.io/github/craue/CraueConfigBundle?branch=master)\n\nCraueConfigBundle manages configuration settings stored in the database and makes them accessible via a service in your\nSymfony project. These settings are similar to those defined in `parameters.yml` but can be modified at runtime, e.g.\nby an admin user.\n\n# Installation\n\n## Get the bundle\n\nLet Composer download and install the bundle by running\n\n```sh\nphp composer.phar require craue/config-bundle:~2.1\n```\n\nin a shell.\n\n## Enable the bundle\n\n```php\n// in app/AppKernel.php\npublic function registerBundles() {\n\t$bundles = array(\n\t\t// ...\n\t\tnew Craue\\ConfigBundle\\CraueConfigBundle(),\n\t);\n\t// ...\n}\n```\n\n## Create the table\n\nPreferably you do this by calling\n\n```sh\n# in a shell (run `bin/console` instead of `app/console` if your project is based on Symfony 3)\nphp app/console doctrine:migrations:diff\nphp app/console doctrine:migrations:migrate\n```\n\nor\n\n```sh\n# in a shell (run `bin/console` instead of `app/console` if your project is based on Symfony 3)\nphp app/console doctrine:schema:update\n```\n\nor however you like.\n\n## Add the route to manage settings (optional)\n\nYou can either import the default routing configuration\n\n```yaml\n# in app/config/routing.yml\ncraue_config_settings:\n  resource: \"@CraueConfigBundle/Resources/config/routing/settings.xml\"\n  prefix: /settings\n```\n\n...or add your own to have full control over the URL pattern.\n\n```yaml\n# in app/config/routing.yml\ncraue_config_settings_modify:\n  path: /settings/modify\n  defaults:\n    _controller: CraueConfigBundle:Settings:modify\n```\n\n# Usage\n\n## Defining settings\n\nThis bundle does _not_ provide functionality to create new settings because this would make no sense at runtime.\nThose settings will be used in your application and thus code needs to be written for that.\nThis means that you have to create new settings in the database table `craue_config_setting` yourself, e.g. using a\nmigration.\n\n## Managing settings' values\n\nIf you added the route described above you can manage the values of all defined settings in a simple form.\nBy default, you can access that form by browsing to `app_dev.php/settings/modify`.\nBut you probably want to limit access to this form in your security configuration.\n\n## Reading settings\n\nThe bundle provides a service called `craue_config`. Inside of a controller you can call\n\n```php\n$this-\u003eget('craue_config')-\u003eget('name-of-a-setting')\n```\n\nto retrieve the value of the setting `name-of-a-setting`. Furthermore, you can call\n\n```php\n$this-\u003eget('craue_config')-\u003eall()\n```\n\nto get an associative array of all defined settings and their values.\n\n```php\n$this-\u003eget('craue_config')-\u003egetBySection('name-of-a-section')\n```\n\nwill fetch only settings with the specified section (or those without a section if explicitly passing `null` for the name).\n\n## Writing settings\n\nWith the same service you can set new values of settings:\n\n```php\n$this-\u003eget('craue_config')-\u003eset('name-of-a-setting', 'new value');\n$this-\u003eget('craue_config')-\u003esetMultiple(array('setting-1' =\u003e 'foo', 'setting-2' =\u003e 'bar'));\n```\n\nKeep in mind that the setting has to be present, or an exception will be thrown.\n\n## Usage in Twig templates\n\nThe Twig extension in this bundle supports reading settings directly in your template.\n\n```twig\n{{ craue_setting('name-of-a-setting') }}\n```\n\n# Enable caching (optional)\n\nTo reduce the number of database queries, you can set up a cache for settings. First, you have to choose which cache\nimplementation you'd like to use. Currently, there are adapters available for:\n- [DoctrineCacheBundle](https://symfony.com/doc/current/bundles/DoctrineCacheBundle/index.html)\n- [Symfony Cache component](https://symfony.com/doc/current/components/cache.html)\n\nRefer to the documentation of each implementation for details and read on in the corresponding section below. When\ndone, `CraueConfigBundle` will automatically cache settings (using the built-in `craue_config_cache_adapter` service).\n\nKeep in mind to clear the cache (if needed) after modifying settings outside of your app (e.g. by Doctrine migrations):\n\n```sh\n# in a shell (run `bin/console` instead of `app/console` if your project is based on Symfony 3)\nphp app/console doctrine:cache:clear craue_config_cache\n```\n\n## Cache implementation: DoctrineCacheBundle\n\nSet the parameter `craue_config.cache_adapter.class` appropriately and configure a so-called cache provider with the\nalias `craue_config_cache_provider`:\n\n```yaml\n# in app/config/config.yml\nparameters:\n  craue_config.cache_adapter.class: Craue\\ConfigBundle\\CacheAdapter\\DoctrineCacheBundleAdapter\n\ndoctrine_cache:\n  providers:\n    craue_config_cache:\n      apc: ~\n      namespace: craue_config\n      aliases:\n        - craue_config_cache_provider\n```\n\n## Cache implementation: Symfony Cache component\n\nSet the parameter `craue_config.cache_adapter.class` appropriately and configure a so-called cache pool with the\nservice id `craue_config_cache_provider`:\n\n```yaml\n# in app/config/config.yml\nparameters:\n  craue_config.cache_adapter.class: Craue\\ConfigBundle\\CacheAdapter\\SymfonyCacheComponentAdapter\n\nservices:\n  craue_config_cache_provider:\n    class: Symfony\\Component\\Cache\\Adapter\\FilesystemAdapter\n    public: false\n    arguments:\n      - 'craue_config'\n      - 0\n      - '%kernel.cache_dir%'\n```\n\n# Customization\n\n## Redirect to a different page after submitting the built-in form\n\nIf you've enabled the build-in form, you can define where to redirect on successfully saving the changes by setting the\ntarget route name:\n\n```yaml\n# in app/config/parameters.yml\nparameters:\n  craue_config.redirectRouteAfterModify: craue_config_settings_modify\n```\n\n## Rendering of settings in sections\n\nIf you want to render settings in a group (called section here), you'll have to assign those settings a common section\nname (in the database). Optionally, you can influence the order of these sections:\n\n```yaml\n# in app/config/parameters.yml\nparameters:\n  craue_config.configTemplate.sectionOrder: [section1, section2, section3]\n```\n\nSettings without a section will be rendered at first. Sections without explicit ordering are rendered at last.\n\n## Translation\n\nYou can add translations for all settings (and sections) to be shown in the form by adding them to translation files\nwith the `CraueConfigBundle` domain, e.g.\n\n```yaml\n# in app/Resources/CraueConfigBundle/translations/CraueConfigBundle.en.yml\nname-of-a-setting: name of the setting\n\n# in app/Resources/CraueConfigBundle/translations/CraueConfigBundle.de.yml\nname-of-a-setting: Name der Einstellung\n```\n\n## Using a custom entity for settings\n\nThe custom entity has to provide a mapping for the field `value`. The class `BaseSetting` defines this field, but no\nmapping for it. This allows easy overriding, including the data type. In the following example, the `value` field will\nbe mapped to a `text` column, which will in turn render the built-in form fields as `textarea`.\n\nSo create the entity and its appropriate mapping:\n\n```php\n// src/MyCompany/MyBundle/Entity/MySetting.php\nuse Craue\\ConfigBundle\\Entity\\BaseSetting;\nuse Doctrine\\ORM\\Mapping as ORM;\n\n/**\n * @ORM\\Entity(repositoryClass=\"Craue\\ConfigBundle\\Repository\\SettingRepository\")\n * @ORM\\Table(name=\"my_setting\")\n */\nclass MySetting extends BaseSetting {\n\n\t/**\n\t * @var string|null\n\t * @ORM\\Column(name=\"value\", type=\"text\", nullable=true)\n\t */\n\tprotected $value;\n\n\t/**\n\t * @var string|null\n\t * @ORM\\Column(name=\"comment\", type=\"string\", nullable=true)\n\t */\n\tprotected $comment;\n\n\tpublic function setComment($comment) {\n\t\t$this-\u003ecomment = $comment;\n\t}\n\n\tpublic function getComment() {\n\t\treturn $this-\u003ecomment;\n\t}\n\n}\n```\n\nAnd make the bundle aware of it:\n\n```yaml\n# in app/config/config.yml\ncraue_config:\n  entity_name: MyCompany\\MyBundle\\Entity\\MySetting\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fntidev%2Fcraueconfigbundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fntidev%2Fcraueconfigbundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fntidev%2Fcraueconfigbundle/lists"}