{"id":15489424,"url":"https://github.com/craue/craueconfigbundle","last_synced_at":"2025-04-13T04:59:09.654Z","repository":{"id":49791034,"uuid":"2011216","full_name":"craue/CraueConfigBundle","owner":"craue","description":"Database-stored settings made available via a service for your Symfony project.","archived":false,"fork":false,"pushed_at":"2023-08-22T09:03:29.000Z","size":456,"stargazers_count":174,"open_issues_count":14,"forks_count":35,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-13T04:59:04.959Z","etag":null,"topics":["bundle","php","symfony","symfony-bundle"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/craue.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2011-07-07T08:39:50.000Z","updated_at":"2024-12-19T23:13:59.000Z","dependencies_parsed_at":"2024-06-18T12:30:22.129Z","dependency_job_id":"40bf5f95-4e78-4084-8020-301b9cbba8c3","html_url":"https://github.com/craue/CraueConfigBundle","commit_stats":{"total_commits":356,"total_committers":7,"mean_commits":"50.857142857142854","dds":"0.047752808988763995","last_synced_commit":"ac08159ac0d0880b46bc29308f720869b4df72e5"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craue%2FCraueConfigBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craue%2FCraueConfigBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craue%2FCraueConfigBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craue%2FCraueConfigBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/craue","download_url":"https://codeload.github.com/craue/CraueConfigBundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248665758,"owners_count":21142123,"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":["bundle","php","symfony","symfony-bundle"],"created_at":"2024-10-02T07:05:37.691Z","updated_at":"2025-04-13T04:59:09.630Z","avatar_url":"https://github.com/craue.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Information\n\n[![Tests](https://github.com/craue/CraueConfigBundle/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/craue/CraueConfigBundle/actions/workflows/tests.yml)\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\ncomposer require craue/config-bundle\n```\n\nin a shell.\n\n## Enable the bundle\n\nIf you don't use Symfony Flex, register the bundle manually:\n\n```php\n// in config/bundles.php\nreturn [\n\t// ...\n\tCraue\\ConfigBundle\\CraueConfigBundle::class =\u003e ['all' =\u003e true],\n];\n```\n\n## Create the table\n\nPreferably you do this by calling\n\n```sh\n# in a shell\nphp bin/console doctrine:migrations:diff\nphp bin/console doctrine:migrations:migrate\n```\n\nor\n\n```sh\n# in a shell\nphp bin/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: Craue\\ConfigBundle\\Controller\\SettingsController::modifyAction\n```\n\nSome CSS is needed to render the form correctly. Install the assets in your project:\n\n```sh\n# in a shell\nphp bin/console assets:install --symlink web\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 `/settings/modify`.\nBut you probably want to limit access to this form in your security configuration.\n\n## Reading and writing settings\n\nFor accessing settings, the bundle provides the service `Craue\\ConfigBundle\\Util\\Config`.\nTo use it directly in a controller, either add an autowired type-hinted argument to the action...\n\n```php\n// in src/Controller/MyController.php\nuse Craue\\ConfigBundle\\Util\\Config;\n\npublic function indexAction(Config $config) {\n\t// use $config\n}\n```\n\n...or let your controller extend `Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController` and make the\nservice alias `craue_config` available by defining `getSubscribedServices`:\n\n```php\n// in src/Controller/MyController.php\nuse Craue\\ConfigBundle\\Util\\Config;\n\npublic function indexAction() {\n\t// use $this-\u003eget('craue_config')\n}\n\npublic static function getSubscribedServices() {\n\treturn array_merge(parent::getSubscribedServices(), [\n\t\t'craue_config' =\u003e Config::class,\n\t]);\n}\n```\n\nThe service defines the following methods:\n\n- `all()` - get an associative array of all defined settings and their values\n- `get($name)` - get the value of the specified setting\n- `getBySection($section)` - like `all()`, but get only settings within the specified section (or those without a section if explicitly passing `null`)\n- `set($name, $value)` - set the value of the specified setting\n- `setMultiple([$name1 =\u003e $value1, $name2 =\u003e $value2])` - set values for multiple settings at once\n\nKeep in mind that each 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://github.com/doctrine/DoctrineCacheBundle)\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\nphp bin/console doctrine:cache:clear craue_config_cache\n```\n\n\u003cdetails\u003e\n  \u003csummary\u003eCache implementation: DoctrineCacheBundle\u003c/summary\u003e\n\n  Set the parameter `craue_config.cache_adapter.class` appropriately and configure a so-called cache provider with the\n  alias `craue_config_cache_provider`:\n\n  ```yaml\n  # in app/config/config.yml\n  parameters:\n    craue_config.cache_adapter.class: Craue\\ConfigBundle\\CacheAdapter\\DoctrineCacheBundleAdapter\n\n  doctrine_cache:\n    providers:\n      craue_config_cache:\n        apc: ~\n        namespace: craue_config\n        aliases:\n          - craue_config_cache_provider\n  ```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003eCache implementation: Symfony Cache component\u003c/summary\u003e\n\n  Set the parameter `craue_config.cache_adapter.class` appropriately and configure a so-called cache pool with the\n  service id `craue_config_cache_provider`:\n\n  ```yaml\n  # in app/config/config.yml\n  parameters:\n    craue_config.cache_adapter.class: Craue\\ConfigBundle\\CacheAdapter\\SymfonyCacheComponentAdapter\n\n  services:\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\u003c/details\u003e\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%2Fcraue%2Fcraueconfigbundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcraue%2Fcraueconfigbundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcraue%2Fcraueconfigbundle/lists"}