{"id":18782394,"url":"https://github.com/atk4/validate","last_synced_at":"2025-09-21T06:47:58.151Z","repository":{"id":33775883,"uuid":"161695320","full_name":"atk4/validate","owner":"atk4","description":"Integration of atk4/data with Valitron for rule-based data validation.","archived":false,"fork":false,"pushed_at":"2025-01-21T15:20:08.000Z","size":73,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":9,"default_branch":"develop","last_synced_at":"2025-08-23T04:51:23.127Z","etag":null,"topics":["agile","atk4","php","validate"],"latest_commit_sha":null,"homepage":"https://agiletoolkit.org/","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/atk4.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,"zenodo":null}},"created_at":"2018-12-13T21:11:29.000Z","updated_at":"2025-01-21T15:20:11.000Z","dependencies_parsed_at":"2024-05-08T11:27:32.675Z","dependency_job_id":"f5391b75-5532-4ec6-822b-64ff30047d8c","html_url":"https://github.com/atk4/validate","commit_stats":{"total_commits":52,"total_committers":4,"mean_commits":13.0,"dds":0.4423076923076923,"last_synced_commit":"501773500af34a4ffd2ace07b0bfe9a06e5954fb"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/atk4/validate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atk4%2Fvalidate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atk4%2Fvalidate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atk4%2Fvalidate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atk4%2Fvalidate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atk4","download_url":"https://codeload.github.com/atk4/validate/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atk4%2Fvalidate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276204834,"owners_count":25602738,"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","status":"online","status_checked_at":"2025-09-21T02:00:07.055Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["agile","atk4","php","validate"],"created_at":"2024-11-07T20:35:51.515Z","updated_at":"2025-09-21T06:47:58.123Z","avatar_url":"https://github.com/atk4.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Validator for Agile Data\n\nThis is validator add-on for Agile Data (https://github.com/atk4/data).\n\nIt uses https://github.com/vlucas/valitron under the hood.\n\n\n[![Code Climate](https://codeclimate.com/github/atk4/validate/badges/gpa.svg)](https://codeclimate.com/github/atk4/validate)\n[![StyleCI](https://styleci.io/repos/161695320/shield)](https://styleci.io/repos/161695320)\n[![CodeCov](https://codecov.io/gh/atk4/validate/branch/develop/graph/badge.svg)](https://codecov.io/gh/atk4/validate)\n[![Test Coverage](https://codeclimate.com/github/atk4/validate/badges/coverage.svg)](https://codeclimate.com/github/atk4/validate/coverage)\n[![Issue Count](https://codeclimate.com/github/atk4/validate/badges/issue_count.svg)](https://codeclimate.com/github/atk4/validate)\n\n[![License](https://poser.pugx.org/atk4/validate/license)](https://packagist.org/packages/atk4/validate)\n[![GitHub release](https://img.shields.io/github/release/atk4/validate.svg?maxAge=2592000)](CHANGELOG.md)\n\n\n# Usage\n\n``` php\n// add model fields\n$model-\u003eaddField('name');\n$model-\u003eaddField('age', ['type' =\u003e 'number']);\n$model-\u003eaddField('type', ['required' =\u003e true, 'enum' =\u003e ['dog', 'ball']]);\n$model-\u003eaddField('tail_length', ['type' =\u003e 'number']);\n\n// add validator to your model\n// also will register itself as $model-\u003evalidator property\n$v = new \\Atk4\\Validate\\Validator($model);\n\n// set simple validation rule for one field\n// -\u003erule($field, $rules)\n$v-\u003erule('name', [ 'required', ['lengthMin', 3] ]);\n\n// set multiple validation rules in one shot\n// -\u003erules($array_of_rules) // [field=\u003erules]\n$v-\u003erules([\n    'name' =\u003e ['required', ['lengthMin',3]],\n    'age' =\u003e ['integer', ['min',0], ['max',99]],\n    'tail_length' =\u003e ['integer', ['min',0]],\n]);\n\n// set validation rules based on value of another field\n// if type=dog, then sets fields age and tail_length as required\n// -\u003eif($condition, $then_array_of_rules, $else_array_of_rules)\n$v-\u003eif(['type'=\u003e'dog'], [\n    'age' =\u003e ['required'],\n    'tail_length' =\u003e ['required'],\n], [\n    'tail_length' =\u003e [ ['equals',''] ], // balls don't have tail\n]);\n\n// you can also pass multiple conditions which will be treated as AND conditions\n$v-\u003eif(['type'=\u003e'dog', 'age'=\u003e50], $rules_if_true, $rules_if_false);\n\n// you can also set custom error message like this:\n$v-\u003erule('age', [ ['min', 3, 'message'=\u003e'Common! {field} to small'] ]);\n// and you will get this \"Common! Age to small\"\n```\n\nYou can also pass callback instead of array of rules.\nCallback receives these parameters $field, $value, $args, $data and should return true/false.\n\nSee `/tests` folder for more examples.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatk4%2Fvalidate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatk4%2Fvalidate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatk4%2Fvalidate/lists"}