{"id":20903513,"url":"https://github.com/phly/phly-rule-validation","last_synced_at":"2025-07-08T19:38:08.432Z","repository":{"id":206459013,"uuid":"716788663","full_name":"phly/phly-rule-validation","owner":"phly","description":"Simple rule-based validation framework","archived":false,"fork":false,"pushed_at":"2024-11-25T20:46:18.000Z","size":219,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"0.2.x","last_synced_at":"2025-04-30T13:39:04.923Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phly.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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":"2023-11-09T21:56:05.000Z","updated_at":"2024-11-25T20:45:00.000Z","dependencies_parsed_at":"2023-11-14T19:29:30.332Z","dependency_job_id":"3dd9035b-68b9-4309-b7c7-c2fa950189dd","html_url":"https://github.com/phly/phly-rule-validation","commit_stats":null,"previous_names":["phly/phly-rule-validation"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phly%2Fphly-rule-validation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phly%2Fphly-rule-validation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phly%2Fphly-rule-validation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phly%2Fphly-rule-validation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phly","download_url":"https://codeload.github.com/phly/phly-rule-validation/tar.gz/refs/heads/0.2.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253877265,"owners_count":21977632,"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-11-18T13:13:52.181Z","updated_at":"2025-05-13T04:33:17.782Z","avatar_url":"https://github.com/phly.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# phly/phly-rule-validation\n\n[![Build Status](https://github.com/phly/phly-rule-validation/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/phly/phly-rule-validation/actions/workflows/continuous-integration.yml)\n\nThis library provides a barebones validation framework.\n\n## Goals of this library\n\nThe explicit goals of this library are:\n\n- Provide an idempotent way to validate individual items and/or data sets.\n- Provide an extensible framework for developing validation rules.\n- Allow handling optional data, with default values.\n- Allow reporting validation error messages.\n- Ensure missing required values are reported as validation failures.\n- Use as few dependencies as possible.\n\nNon-goals:\n\n- Creating an extensive set of validation rule classes.\n- Providing extensive mechanisms for validating and returning nested data sets.\n- Providing a configuration-driven mechanism for creating rule sets.\n- Providing HTML form input representations or all metadata required to create HTML form input representations.\n\n## Installation\n\n```bash\ncomposer require phly/phly-rule-validation\n```\n\n## Basic Usage\n\n```php\nuse Phly\\RuleValidation\\Result\\Result;\nuse Phly\\RuleValidation\\RuleSet\\RuleSet;\nuse Phly\\RuleValidation\\Rule\\CallbackRule;\n\n$rules = new RuleSet();\n$rules-\u003eadd(new CallbackRule('flag', function (mixed $value, array $data): Result {\n    if (! is_bool($value)) {\n        return Result::forInvalidValue('flag', $value, 'Not a boolean value');\n    }\n    return Result::forValidValue('flag', $value);\n}, default: false));\n$rules-\u003eadd(new MyCustomRule());\n// and so on\n\n$resultSet = $rules-\u003evalidate($someFormData);\n\nif ($resultSet-\u003eisValid()) {\n    $values = $resultSet-\u003egetValues();\n    // do something with values\n} else {\n    $messages = $resultSet-\u003egetMessages();\n    // do something with error messages\n}\n\n// Get a result for a single key:\n$flagResult = $resultSet-\u003eflag; // or $resultSet-\u003egetResult('flag')\n\n// Get the value from a single result\n$flag = $flagResult-\u003evalue();\n\n// Get the validation status from a single result\nif ($flagResult-\u003eisValid()) {\n    // ...\n}\n\n// Get an error message for a single result\nif (! $flagResult-\u003eisValid()) {\n    echo $flagResult-\u003emessage();\n}\n```\n\n## Documentation\n\nPlease see the [documentation tree (docs/)](./docs/README.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphly%2Fphly-rule-validation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphly%2Fphly-rule-validation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphly%2Fphly-rule-validation/lists"}