{"id":16463514,"url":"https://github.com/mr-luke/configuration","last_synced_at":"2025-02-27T08:43:15.600Z","repository":{"id":57020704,"uuid":"159022034","full_name":"mr-luke/configuration","owner":"mr-luke","description":"Dot notation array host configuration package.","archived":false,"fork":false,"pushed_at":"2023-05-12T11:54:17.000Z","size":31,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-11T00:54:57.342Z","etag":null,"topics":["array","configuration","php7","schema-validation","wrapper"],"latest_commit_sha":null,"homepage":null,"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/mr-luke.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2018-11-25T10:53:44.000Z","updated_at":"2023-05-11T09:36:23.000Z","dependencies_parsed_at":"2025-01-10T08:33:09.480Z","dependency_job_id":"f90fdd19-37eb-4604-ace3-8ffbe5c6f8e8","html_url":"https://github.com/mr-luke/configuration","commit_stats":{"total_commits":14,"total_committers":1,"mean_commits":14.0,"dds":0.0,"last_synced_commit":"9c6dbd3273dcfdc7db500dbe05e942fdd959e7d5"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mr-luke%2Fconfiguration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mr-luke%2Fconfiguration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mr-luke%2Fconfiguration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mr-luke%2Fconfiguration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mr-luke","download_url":"https://codeload.github.com/mr-luke/configuration/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240996127,"owners_count":19890900,"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":["array","configuration","php7","schema-validation","wrapper"],"created_at":"2024-10-11T11:14:38.457Z","updated_at":"2025-02-27T08:43:15.552Z","avatar_url":"https://github.com/mr-luke.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Configuration Host\n\n[![Latest Stable Version](https://poser.pugx.org/mr-luke/configuration/v/stable)](https://packagist.org/packages/mr-luke/configuration)\n[![Total Downloads](https://poser.pugx.org/mr-luke/configuration/downloads)](https://packagist.org/packages/mr-luke/configuration)\n[![License](https://poser.pugx.org/mr-luke/configuration/license)](https://packagist.org/packages/mr-luke/configuration)\n\n![Tests Workflow](https://github.com/mr-luke/configuration/actions/workflows/run-testsuit.yaml/badge.svg)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=mr-luke_configuration\u0026metric=alert_status)](https://sonarcloud.io/summary/new_code?id=mr-luke_configuration)\n[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=mr-luke_configuration\u0026metric=security_rating)](https://sonarcloud.io/summary/new_code?id=mr-luke_configuration)\n[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=mr-luke_configuration\u0026metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=mr-luke_configuration)\n\nThis package provides array host (wrapper) package that supports dot notation access and schema validation.\n\n* [Getting Started](#getting-started)\n* [Installation](#installation)\n* [Usage](#usage)\n* [Plans](#plans)\n\n## Getting Started\n\nGood software development follows many patterns and architectures. We design things that depends on many other parts. Some of them are well structured Objects but many times we need to have some configurations. Often we use array as our config host but it can produce mass of unexpected side-effects becasue of one reason - array is not an Object so it can't follow any schema. But what if it can...\n\nDuring my work I developed a simple wrapper tool that helped me with schema sensitive arrays and I decided to make it a package. I hope you enjoy it!\n\n## Installation\n\nTo install through composer, simply put the following in your composer.json file and run `composer update`\n\n```json\n{\n    \"require\": {\n        \"mr-luke/configuration\": \"~1.0\"\n    }\n}\n```\nOr use the following command\n\n```bash\ncomposer require \"mr-luke/configuration\"\n```\n\n## Usage\n\nLet's move to a `Schema` class. It's a validation tool with one interface method:\n\n```php\npublic function check(array $insert, bool $throw = true): bool\n```\n\n* `$insert` - This is your array that is a subject of validation\n* `$throw`  - This option change behavior of validation\n\nBy default `check` method throws an `InvalidArgumentException` when `$insert` doesn't follow schema.\n\n### Step One\n\nCreate your Schema array:\n```php\n$instruction = [\n  'first_key'  =\u003e 'required|string',\n  'second_key' =\u003e 'nullable|integer',\n  'third_key'  =\u003e 'required|float',\n];\n```\n\nAvailable rules:\n* `required` - given key must not be empty\n* `nullable` - given key can be null\n* `boolean`  - given key must be boolean type\n* `float`    - given key must be float type\n* `integer`  - given key must be integer type\n* `string`   - given key must be string and can't be other types\n\n### Step Two\n\nCreate new instance of `Mrluke\\Configuration\\Schema`:\n\n```php\n$schema = new Schema(array $instruction);\n```\n\nNote! From v1.2.0 you can create `Schema` by static method `createFromFile(string $path, bool $json = false)`.\n\n### Step Three\n\nCreate new instance of `Mrluke\\Configuration\\Host` with `Schema` as a dependency and your `$configArray` is automatically validated.\n\n```php\n$host = new Host($configArray, $schema);\n```\n\nIf your `$configArray` doesn't follow given `Schema`, you will get `InvalidArgumentException`. You can also use `Host` without any `Schema` due to it's optional parameter of `Mrluke\\Configuration\\Host`.\n\n### Your configuration is Wrapped!\n\nNow you have an access to `Host` methods:\n\n```php\n/**\n * Return given key from array.\n *\n * @param  string $key\n * @param  mixed  $default\n * @return mixed\n */\npublic function get(string $key, $default = null)\n```\n\nYour `key` can follow **dot notation** to access nested `keys`:\n```php\n$host-\u003eget('mysql.database', 'my_db');\n```\n\nBy default if `key` is not present, `Host` returns `null`. You can also use magic getter to acces config:\n```php\n$host-\u003emysql;\n```\n\nYou can check if given hey is present:\n```php\n/**\n * Determine if given key is present.\n *\n * @param  string $key\n * @return bool\n */\npublic function has(string $key): bool\n```\n\n## Plans\n\nFeel free to contribute because I am aware that there are some things to improve. For now:\n* Nested Schema support\n* New validation rules support\n* New Schema's file format\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmr-luke%2Fconfiguration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmr-luke%2Fconfiguration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmr-luke%2Fconfiguration/lists"}