diff --git a/.github/workflows/coverage_report.yml b/.github/workflows/coverage_report.yml index 837397d..de60e02 100644 --- a/.github/workflows/coverage_report.yml +++ b/.github/workflows/coverage_report.yml @@ -1,6 +1,6 @@ # Run coverage report and upload it to CodeClimate name: Coverage -on: +on: push: branches: [master] jobs: @@ -19,9 +19,10 @@ jobs: uses: ramsey/composer-install@v3 with: composer-options: "--prefer-dist --optimize-autoloader" - - name: Test & publish code coverage - uses: paambaati/codeclimate-action@v8.0.0 - env: - CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} + - name: Build the code coverage report + run: composer coverage:clover + - name: Upload code coverage report + uses: qltysh/qlty-action/coverage@v1 with: - coverageCommand: "composer coverage:clover" + token: ${{ secrets.QLTY_COVERAGE_TOKEN }} + files: clover.xml diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 7342612..36cf720 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -11,8 +11,8 @@ jobs: - name: Setup Python uses: actions/setup-python@v4 with: - python-version: '3.x' - architecture: 'x64' + python-version: "3.x" + architecture: "x64" - name: Install dependencies run: python -m pip install --upgrade pip mkdocs mkdocs-material - name: Upload artifacts @@ -29,7 +29,7 @@ jobs: - name: Setup PHP, with composer and extensions uses: shivammathur/setup-php@v2 with: - php-version: '8.3' + php-version: "8.3" coverage: none - name: Install composer dependencies uses: ramsey/composer-install@v3 @@ -45,7 +45,7 @@ jobs: name: api-artifact path: _site/api/ deploy_documentation: - needs: [build_documentation,build_api] + needs: [build_documentation, build_api] runs-on: ubuntu-latest steps: - name: Download artifacts diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7c7a4ee..17f783d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,8 +8,8 @@ jobs: fail-fast: false matrix: operating-system: [ubuntu-latest, windows-latest, macOS-latest] - php-versions: ['8.3', '8.4'] - symfony-version: ['6.4', '7.1'] + php-versions: ["8.3", "8.4"] + symfony-version: ["6.4", "7.1"] runs-on: ${{ matrix.operating-system }} steps: - name: Set autocrlf on windows diff --git a/.qlty/qlty.toml b/.qlty/qlty.toml new file mode 100644 index 0000000..b4fe1c7 --- /dev/null +++ b/.qlty/qlty.toml @@ -0,0 +1,96 @@ +# This file was automatically generated by `qlty init`. +# You can modify it to suit your needs. +# We recommend you to commit this file to your repository. +# +# This configuration is used by both Qlty CLI and Qlty Cloud. +# +# Qlty CLI -- Code quality toolkit for developers +# Qlty Cloud -- Fully automated Code Health Platform +# +# Try Qlty Cloud: https://qlty.sh +# +# For a guide to configuration, visit https://qlty.sh/d/config +# Or for a full reference, visit https://qlty.sh/d/qlty-toml +config_version = "0" + +exclude_patterns = [ + "*_min.*", + "*-min.*", + "*.min.*", + "**/*.d.ts", + "**/.yarn/**", + "**/bower_components/**", + "**/build/**", + "**/cache/**", + "**/config/**", + "**/db/**", + "**/deps/**", + "**/dist/**", + "**/extern/**", + "**/external/**", + "**/generated/**", + "**/Godeps/**", + "**/gradlew/**", + "**/mvnw/**", + "**/node_modules/**", + "**/protos/**", + "**/seed/**", + "**/target/**", + "**/testdata/**", + "**/vendor/**", + "**/assets/**", +] + +test_patterns = [ + "**/test/**", + "**/tests/**", + "**/spec/**", + "**/*.test.*", + "**/*.spec.*", + "**/*_test.*", + "**/*_spec.*", + "**/test_*.*", + "**/spec_*.*", +] + +[smells] +mode = "comment" + +[[source]] +name = "default" +default = true + +[[plugin]] +name = "golangci-lint" +mode = "comment" + +[[plugin]] +name = "markdownlint" +mode = "comment" + +[[plugin]] +name = "php-codesniffer" +mode = "comment" + +[[plugin]] +name = "php-cs-fixer" + +[[plugin]] +name = "prettier" + +[[plugin]] +name = "radarlint-php" + +[[plugin]] +name = "ripgrep" +mode = "comment" + +[[plugin]] +name = "trivy" +drivers = [ + "config", + "fs-vuln", +] + +[[plugin]] +name = "trufflehog" diff --git a/CHANGELOG.md b/CHANGELOG.md index 0eac6d3..1e806f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,47 +1,71 @@ # Changelog + All notable changes to `susina/config-builder` project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -### [1.1] - 2025-05-22 +### [1.1] - 2025-05-28 + ### Added + - Add `replaces` option to inject an external parameter to resolve. Useful, i.e. to pass -`kernel_dir` or other parameters. + `kernel_dir` or other parameters. - Add [phpdocumentor](https://phpdoc.org/) to generate the documentation api + ### Changed + - Update the documentation ## [1.0.1] - 2024-11-30 + ### Fixed + - Remove PHP 8.4 deprecations ## [1.0] - 2024-09-16 + ### Added + - Introduce `susina/param-resolver` library - Introduce `susina/xml-to-array` library + ### Changed + - Bump dependencies - Update Github Actions - Update documentation + ### Removed + - Remove `.ini` support since it's not suited for complex nested configurations ## [0.4] - 2023-02-16 + ### Added -- `ConfigBuilder::keepFirstXmlTag` method, to include into the configuration array also the first xml tag + +- `ConfigBuilder::keepFirstXmlTag` method, to include into the configuration array also the first xml tag + ### Changed -- Introduce [Pest](https://www.pest.com) testing tool. Since Pest is built on top of Phpunit, this change doesn't break backward compatibility + +- Introduce [Pest](https://www.pest.com) testing tool. Since Pest is built on top of Phpunit, this change doesn't break backward compatibility + ### Fixed -- Fixed Github Actions warning by update our workflows dependencies + +- Fixed Github Actions warning by update our workflows dependencies ## [0.3] - 2023-01-07 + ### Added + - `ConfigBuilder::populateContainer` method, to populate a dependency injection container with the loaded parameters. ## [0.2] - 2021-12-29 + ### Added -- Support for Symfony 6 libraries + +- Support for Symfony 6 libraries ## [0.1] - 2021-12-16 + First release: fully functional library. diff --git a/README.md b/README.md index 641a7b2..e82d626 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,21 @@ # Configuration Builder ![Tests](https://github.com/susina/config-builder/actions/workflows/test.yml/badge.svg) -[![Maintainability](https://api.codeclimate.com/v1/badges/df031168e25a1206df64/maintainability)](https://codeclimate.com/github/susina/config-builder/maintainability) -[![Test Coverage](https://api.codeclimate.com/v1/badges/df031168e25a1206df64/test_coverage)](https://codeclimate.com/github/susina/config-builder/test_coverage) +[![Maintainability](https://qlty.sh/badges/689d9c9a-29ce-4e10-93ea-21ccba522cf3/maintainability.svg)](https://qlty.sh/gh/susina/projects/config-builder) +[![Maintainability](https://qlty.sh/badges/689d9c9a-29ce-4e10-93ea-21ccba522cf3/maintainability.svg)](https://qlty.sh/gh/susina/projects/config-builder) ![GitHub](https://img.shields.io/github/license/susina/config-builder) Susina Configuration Builder is a library to load parameters, from configuration files, and build configuration objects -or arrays. It's based on [Symfony Config](https://symfony.com/doc/current/components/config.html) and +or arrays. It's based on [Symfony Config](https://symfony.com/doc/current/components/config.html) and [Propel configuration sub-system](https://github.com/propelorm/Propel2/tree/master/src/Propel/Common/Config). Supported configuration file formats are: -- __.json__ via PHP json extension -- __.neon__ via [Nette Neon](https://github.com/nette/neon) library -- __.php__ -- __.xml__ via PHP SimpleXml, Xml and Dom extensions -- __.yml__ via [Symfony Yaml](https://symfony.com/doc/current/components/yaml.html) component - +- **.json** via PHP json extension +- **.neon** via [Nette Neon](https://github.com/nette/neon) library +- **.php** +- **.xml** via PHP SimpleXml, Xml and Dom extensions +- **.yml** via [Symfony Yaml](https://symfony.com/doc/current/components/yaml.html) component ## Installation @@ -25,6 +24,7 @@ You can install the library via [composer](http://getcomposer.org): ```bash composer require susina/config-builder ``` + then you should install the library you need to load your preferred configuration file format: ```bash @@ -36,7 +36,6 @@ composer require symfony/yaml See the [documentation site](https://susina.github.io/config-builder). - ## Issues Please, open an issue on [Github repository](https://github.com/susina/config-builder/issues). @@ -47,4 +46,4 @@ Fork the repository and submit a pull request. For further information see the [ ## Licensing -This library is released under [Apache 2.0 license](LICENSE) \ No newline at end of file +This library is released under [Apache 2.0 license](LICENSE) diff --git a/composer.json b/composer.json index a22aa1f..67ba1c2 100644 --- a/composer.json +++ b/composer.json @@ -1,73 +1,73 @@ { - "name": "susina/config-builder", - "type": "library", - "description": "Load and build configuration classes", - "license": "Apache-2.0", - "authors": [ - { - "name": "Cristiano Cinotti", - "email": "cristianocinotti@gmail.com" - } + "name": "susina/config-builder", + "type": "library", + "description": "Load and build configuration classes", + "license": "Apache-2.0", + "authors": [ + { + "name": "Cristiano Cinotti", + "email": "cristianocinotti@gmail.com" + } + ], + "require": { + "php": ">=8.2", + "symfony/config": "^6.4|^7.1", + "susina/param-resolver": "^0.5.0", + "susina/xml-to-array": "^1.0" + }, + "autoload": { + "psr-4": { + "Susina\\ConfigBuilder\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Susina\\ConfigBuilder\\Tests\\": "tests/" + } + }, + "require-dev": { + "mikey179/vfsstream": "^1.6", + "susina/coding-standard": "^2", + "symfony/yaml": "^6.4|^7.0", + "pestphp/pest": "^2", + "psalm/phar": "^5.25", + "nette/neon": "^3.4" + }, + "scripts": { + "analytics": "vendor/bin/psalm.phar", + "check": [ + "@test", + "@analytics", + "@cs:fix" ], - "require": { - "php": ">=8.2", - "symfony/config": "^6.4|^7.1", - "susina/param-resolver": "^0.5.0", - "susina/xml-to-array": "^1.0" - }, - "autoload": { - "psr-4": { - "Susina\\ConfigBuilder\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "Susina\\ConfigBuilder\\Tests\\": "tests/" - } - }, - "require-dev": { - "mikey179/vfsstream": "^1.6", - "susina/coding-standard": "^2", - "symfony/yaml": "^6.4|^7.0", - "pestphp/pest": "^2", - "psalm/phar": "^5.25", - "nette/neon": "^3.4" - }, - "scripts": { - "analytics": "vendor/bin/psalm.phar", - "check": [ - "@test", - "@analytics", - "@cs:fix" - ], - "coverage": "@test --coverage", - "coverage:html": "@test --coverage-html coverage/", - "coverage:clover": "@test --coverage-clover clover.xml", - "cs:check": "php-cs-fixer fix -v --diff --dry-run", - "cs:fix": "php-cs-fixer fix -v --diff", - "test": "pest" - }, - "scripts-descriptions": { - "analytics": "Run static analysis tool", - "check": "Perform all tests and analysis, required before submitting a pull request", - "cs:check": "Run code style analysis, without fixing errors", - "cs:fix": "Run code style analysis and fix errors", - "coverage": "Show the coverage report", - "coverage:html": "Create a code coverage report in html format, into the `coverage/` directory", - "coverage:clover": "Create a code coverage report in xml format, into the `clover.xml` file", - "test": "Run the test suite" - }, - "suggest": { - "symfony/yaml": "Needed to load YAML configuration files", - "nette/neon": "Needed to load NEON configuration files", - "ext-json": "Needed to load JSON configuration files", - "ext-simplexml": "Needed to load XML configuration files", - "ext-dom": "Allows to include XML files into your XML configuration", - "ext-libxml": "Needed to manipulate XML configuration files" - }, - "config": { - "allow-plugins": { - "pestphp/pest-plugin": true - } + "coverage": "@test --coverage", + "coverage:html": "@test --coverage-html coverage/", + "coverage:clover": "@test --coverage-clover clover.xml", + "cs:check": "php-cs-fixer fix -v --diff --dry-run", + "cs:fix": "php-cs-fixer fix -v --diff", + "test": "pest" + }, + "scripts-descriptions": { + "analytics": "Run static analysis tool", + "check": "Perform all tests and analysis, required before submitting a pull request", + "cs:check": "Run code style analysis, without fixing errors", + "cs:fix": "Run code style analysis and fix errors", + "coverage": "Show the coverage report", + "coverage:html": "Create a code coverage report in html format, into the `coverage/` directory", + "coverage:clover": "Create a code coverage report in xml format, into the `clover.xml` file", + "test": "Run the test suite" + }, + "suggest": { + "symfony/yaml": "Needed to load YAML configuration files", + "nette/neon": "Needed to load NEON configuration files", + "ext-json": "Needed to load JSON configuration files", + "ext-simplexml": "Needed to load XML configuration files", + "ext-dom": "Allows to include XML files into your XML configuration", + "ext-libxml": "Needed to manipulate XML configuration files" + }, + "config": { + "allow-plugins": { + "pestphp/pest-plugin": true } + } } diff --git a/docs/contributing.md b/docs/contributing.md index e762a7b..c86c269 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -6,7 +6,7 @@ 4. Fix the coding standard by running `composer cs:fix`. !!! note "Tip" - We provide a __check__ command for the tests, analytics and code style fixing, required for a pull request: run `composer check` +We provide a **check** command for the tests, analytics and code style fixing, required for a pull request: run `composer check` ## Running the Test Suite @@ -17,6 +17,7 @@ Our test tool is [Pest](https://pestphp.com/) and we provide a script to launch ```bash composer test ``` + Since our command runs pest binary under the hood, you can pass all options to it via the `--` operator, i.e.: ```bash @@ -33,10 +34,9 @@ vendor/bin/pest We provides three commands to generate a code coverage report in _html_ or _xml_ format: -- `composer coverage` command to print a coverage report summary to the console -- `composer coverage:html` command generates a code coverage report in _html_ format, into the directory `coverage/` -- `composer coverage:clover` generates the report in _xml_ format, into `clover.xml` file. - +- `composer coverage` command to print a coverage report summary to the console +- `composer coverage:html` command generates a code coverage report in _html_ format, into the directory `coverage/` +- `composer coverage:clover` generates the report in _xml_ format, into `clover.xml` file. ## Static Analysis Tool @@ -49,7 +49,6 @@ composer analytics After its analysis, Psalm outputs errors and issues with its suggestions on how to fix them. - ## Coding Standard We ship our script to easily fix coding standard errors, via [php-cs-fixer](https://cs.symfony.com/) tool. @@ -67,19 +66,16 @@ composer cs:check If you want to learn more about our code style, see [https://github.com/susina/coding-standard](https://github.com/susina/coding-standard). - ## Documentation Contributing `susina/config-builder` documentation resides into the directory `docs/`. It's written in [markdown](https://daringfireball.net/projects/markdown/) and it's generated by [MkDocs](https://www.mkdocs.org). - ### Install the Tools If you want to contribute to the documentation, you should install the following tools, to generate it locally: 1. [Install MkDocs](https://www.mkdocs.org/#installation) 2. Install [Material theme](https://squidfunk.github.io/mkdocs-material/) by running: `pip install mkdocs-material` - ### Markdown flavour @@ -87,7 +83,6 @@ MkDocs uses [Python-Markdown](https://python-markdown.github.io/) with some exte Additionally, you could get a look at [Material theme](https://squidfunk.github.io/mkdocs-material/) documentation for further information. - ### Admonition [admonition](https://python-markdown.github.io/extensions/admonition/) extension helps to write beautiful notes or warnings or other (see the official documentation) with a syntax like the following: @@ -100,4 +95,4 @@ Additionally, you could get a look at [Material theme](https://squidfunk.github. which translates into the following: !!! Danger - Very dangerous operation! +Very dangerous operation! diff --git a/docs/example.md b/docs/example.md index e08aad8..ab30fca 100644 --- a/docs/example.md +++ b/docs/example.md @@ -24,22 +24,21 @@ example └───tests ``` -- `app/config/example-config.yml` is our configuration file -- `var/cache` is our cache directory -- `src/Configuration/ExampleConfiguration.php` is our definition class +- `app/config/example-config.yml` is our configuration file +- `var/cache` is our cache directory +- `src/Configuration/ExampleConfiguration.php` is our definition class The application namespace is `App` and it points to `src` directory. We want to manage our configuration via [Dot Access Data](https://github.com/dflydev/dflydev-dot-access-data) library. - ## Installation We need to install: -- `susina/config-builder` (of course!) -- `symfony/yaml` since we decide to use _yaml_ format for our file -- `dflydev/dot-access-data` we love to access the configuration properties via dot syntax +- `susina/config-builder` (of course!) +- `symfony/yaml` since we decide to use _yaml_ format for our file +- `dflydev/dot-access-data` we love to access the configuration properties via dot syntax ```bash composer require susina/config-builder symfony/yaml dflydev/dot-access-data @@ -51,25 +50,25 @@ The configuration file, we'll load and process, is `app/config/example-config.ya ```yaml title="app/config/example-config.yaml" app: - database: - auto_connect: true - default_connection: pgsql - connections: - pgsql: - host: localhost - driver: postgresql - username: user - password: pass - sqlite: - host: localhost - driver: sqlite - memory: true - username: user - password: pass - - paths: - template: app/resources - logger: var/log + database: + auto_connect: true + default_connection: pgsql + connections: + pgsql: + host: localhost + driver: postgresql + username: user + password: pass + sqlite: + host: localhost + driver: sqlite + memory: true + username: user + password: pass + + paths: + template: app/resources + logger: var/log ``` ## The definition class @@ -140,7 +139,7 @@ class ExampleConfiguration implements ConfigurationInterface ``` -## Let's go! +## Let's go Let's use the `ConfigurationBuilder` to load and process our file and to instantiate the class, to manage the configuration: diff --git a/docs/index.md b/docs/index.md index 3788aa2..fb2baf2 100644 --- a/docs/index.md +++ b/docs/index.md @@ -4,7 +4,7 @@ Susina Configuration Builder is a library to load and build configuration object It's based on [Symfony Config](https://symfony.com/doc/current/components/config.html) and it's heavily inspired on [Propel configuration sub-system](https://github.com/propelorm/Propel2/tree/master/src/Propel/Common/Config). ---------------------------------- +--- Building a configuration is a three-step process: @@ -12,14 +12,12 @@ Building a configuration is a three-step process: 2. process the loaded parameters to normalize and validate them 3. return an array of cleaned parameters or a configuration object - We ship loaders for the following file formats: -- __.json__ via PHP json extension -- __.neon__ via [Nette Neon](https://github.com/nette/neon) library -- __.php__ -- __.xml__ via [Susina xml to array](https://github.com/susina/xml-to-array) library -- __.yml__ via [Symfony Yaml](https://symfony.com/doc/current/components/yaml.html) component - +- **.json** via PHP json extension +- **.neon** via [Nette Neon](https://github.com/nette/neon) library +- **.php** +- **.xml** via [Susina xml to array](https://github.com/susina/xml-to-array) library +- **.yml** via [Symfony Yaml](https://symfony.com/doc/current/components/yaml.html) component -The Configuration Builder can populate any object whose constructor, or any other initialize method, takes an array as a parameter. \ No newline at end of file +The Configuration Builder can populate any object whose constructor, or any other initialize method, takes an array as a parameter. diff --git a/docs/installation.md b/docs/installation.md index 25bc8ce..3a58c3c 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -5,7 +5,7 @@ composer require susina/config-builder ``` Additionally, you should install the library you could need to load your configuration file format. In example, if -you have to load some __yaml__ files: +you have to load some **yaml** files: ``` composer require symfony/yaml @@ -20,10 +20,11 @@ on which format you prefer. Here are the list of supported file formats and the libraries to load: -|Format|Supported file extension|Library to load|Installation| -|------|------------------------|---------------|-------| -|_json_|.json, .json.dist|Bundled with PHP by default|enabled by default| -|_neon_|.neon, .neon.dist|[Nette Neon](https://ne-on.org/)|`composer require nette/neon`| -|_php_|.php, .php.dist|PHP itself|none| -|_xml_|.xml, .xml.dist|[Susina Xml To Array](https://github.com/susina/xml-to-array)|Automatically installed by composer| -|_yaml_|.yaml, .yml, .yaml.dist, .yml.dist|[Symfony Yaml](https://symfony.com/doc/current/components/yaml.html)|`composer require symfony/yaml`| \ No newline at end of file +| Format | Supported file extension | Library to load | Installation | +| ------ | ---------------------------------- | -------------------------------------------------------------------- | ----------------------------------- | +| _json_ | .json, .json.dist | Bundled with PHP by default | enabled by default | +| _neon_ | .neon, .neon.dist | [Nette Neon](https://ne-on.org/) | `composer require nette/neon` | +| _php_ | .php, .php.dist | PHP itself | none | +| _xml_ | .xml, .xml.dist | [Susina Xml To Array](https://github.com/susina/xml-to-array) | Automatically installed by composer | +| _yaml_ | .yaml, .yml, .yaml.dist, .yml.dist | [Symfony Yaml](https://symfony.com/doc/current/components/yaml.html) | `composer require symfony | +| /yaml` | diff --git a/docs/license.md b/docs/license.md index f49a4e1..c319da3 100644 --- a/docs/license.md +++ b/docs/license.md @@ -2,180 +2,180 @@ Version 2.0, January 2004 http://www.apache.org/licenses/ - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" @@ -186,16 +186,16 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] +Copyright [yyyy] [name of copyright owner] - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/docs/parameters.md b/docs/parameters.md index f18cab8..9a281ba 100644 --- a/docs/parameters.md +++ b/docs/parameters.md @@ -4,32 +4,32 @@ A parameter is a previously defined property, put between `%` special character. ```yaml general: - project: MyProject + project: MyProject paths: - projectDir: /home/%project% + projectDir: /home/%project% ``` It becomes: ```yaml general: - project: MyProject + project: MyProject paths: - projectDir: /home/MyProject + projectDir: /home/MyProject ``` You can escape the special character `%` by doubling it: ```yaml general: - project: 100%% + project: 100%% ``` `project` property now contains the string `'100%'`. -### Special parameters: environment variables ### +### Special parameters: environment variables The parameter `env` is used to specify an environment variable. Many hosts give services or credentials via environment variables and you can use them in your configuration file via `env.variable` syntax. In example, let's suppose to have the following environment variables: @@ -46,9 +46,9 @@ In your configuration file you can write: ```yaml project: database: - default: - adapter: mysql - dsn: mysql:host=%env.host%;dbname=%env.dbName% + default: + adapter: mysql + dsn: mysql:host=%env.host%;dbname=%env.dbName% ``` and it becomes: @@ -56,7 +56,7 @@ and it becomes: ```yaml project: database: - default: - adapter: mysql - dsn: mysql:host=192.168.0.54;dbname=myDB -``` \ No newline at end of file + default: + adapter: mysql + dsn: mysql:host=192.168.0.54;dbname=myDB +``` diff --git a/docs/usage.md b/docs/usage.md index 7e29b51..a0d8d21 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -1,6 +1,6 @@ ## Create Your Configuration Definition -The first step to take is writing a `Symfony\Component\Config\Definition\ConfigurationInterface` class, +The first step to take is writing a `Symfony\Component\Config\Definition\ConfigurationInterface` class, to define the structure of your configuration. Please, read the [official Symfony documentation](https://symfony.com/doc/current/components/config/definition.html) @@ -29,7 +29,7 @@ You can set up the `ConfigurationBuilder` via all the methods explained into [Ap Once you have your builder set up, you can get an array of loaded and processed parameters, by calling [getConfigurationArray](https://github.com/susina/config-builder/blob/master/src/ConfigurationBuilder.php#L286) method: -```php +```php getConfigurationArray(); or you can do it in one-line, thanks to the fluent api: -```php +```php addDirectory('app/config') ->setDefinition(MyProjectConfiguration::class) ->setConfigurationClass(Data::class) ; - + $config = $builder->getConfiguration(); //Now, you can use your configuration class @@ -97,7 +97,7 @@ Now, suppose you have a configuration class, like the following: namespace MyApp\MyNamespace; class ConfigManager { - + public function init(array $params): void { //some operations with $params @@ -135,9 +135,9 @@ If you set your cache directory, via `setCacheDirectory` method, after the first The cache is invalidated when one of the following events occurs: -1. one of the configuration files is changed -2. the `ConfigurationBuilder` set up is changed -3. one of the cache files is deleted +1. one of the configuration files is changed +2. the `ConfigurationBuilder` set up is changed +3. one of the cache files is deleted In example, let's suppose you have an application and your bootstrap file looks something like this: diff --git a/mkdocs.yml b/mkdocs.yml index 7f44dd3..2515fa4 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -4,9 +4,9 @@ site_description: "Load and build configuration" site_url: https://susina.github.io/config-builder #Repository -repo_name: 'susina/config-builder' -repo_url: 'https://github.com/susina/config-builder' -edit_uri: '' +repo_name: "susina/config-builder" +repo_url: "https://github.com/susina/config-builder" +edit_uri: "" #Copyright copyright: 'Susina Configuration Builder is licensed under Apache 2.0 license' @@ -28,9 +28,9 @@ nav: - Documentation: - Installation: installation.md - Usage: usage.md - - Reference: - - Api: api/index.html - - Parameters reference: parameters.md + - Reference: + - Api: api/index.html + - Parameters reference: parameters.md - Complete Example: example.md - About: - Contributing: contributing.md diff --git a/tests/Fixtures/database_config.yml b/tests/Fixtures/database_config.yml index d424032..d70f061 100644 --- a/tests/Fixtures/database_config.yml +++ b/tests/Fixtures/database_config.yml @@ -2,12 +2,12 @@ auto_connect: true default_connection: mysql connections: mysql: - host: localhost - driver: mysql + host: localhost + driver: mysql username: user password: pass sqlite: - host: localhost - driver: sqlite + host: localhost + driver: sqlite username: user - password: pass \ No newline at end of file + password: pass