{"id":21467404,"url":"https://github.com/elusivecodes/fyrevalidation","last_synced_at":"2025-07-29T06:04:16.085Z","repository":{"id":62508451,"uuid":"448243591","full_name":"elusivecodes/FyreValidation","owner":"elusivecodes","description":"FyreValidation is a free, open-source validation library for PHP.","archived":false,"fork":false,"pushed_at":"2025-07-03T10:30:28.000Z","size":123,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-03T11:42:07.975Z","etag":null,"topics":["php","ruleset","validation"],"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/elusivecodes.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":"2022-01-15T10:16:04.000Z","updated_at":"2025-07-03T10:30:21.000Z","dependencies_parsed_at":"2024-02-25T11:33:10.276Z","dependency_job_id":"90b80db0-07bf-49ac-8559-405c6a1d3f52","html_url":"https://github.com/elusivecodes/FyreValidation","commit_stats":null,"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"purl":"pkg:github/elusivecodes/FyreValidation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreValidation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreValidation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreValidation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreValidation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elusivecodes","download_url":"https://codeload.github.com/elusivecodes/FyreValidation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreValidation/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267638634,"owners_count":24119764,"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-07-29T02:00:12.549Z","response_time":2574,"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":["php","ruleset","validation"],"created_at":"2024-11-23T08:17:53.812Z","updated_at":"2025-07-29T06:04:16.049Z","avatar_url":"https://github.com/elusivecodes.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FyreValidation\r\n\r\n**FyreValidation** is a free, open-source validation library for *PHP*.\r\n\r\n\r\n## Table Of Contents\r\n- [Installation](#installation)\r\n- [Basic Usage](#basic-usage)\r\n- [Methods](#methods)\r\n- [Rules](#rules)\r\n- [Error Messages](#error-messages)\r\n\r\n\r\n\r\n## Installation\r\n\r\n**Using Composer**\r\n\r\n```\r\ncomposer require fyre/validation\r\n```\r\n\r\nIn PHP:\r\n\r\n```php\r\nuse Fyre\\Validation\\Validator;\r\n```\r\n\r\n\r\n## Basic Usage\r\n\r\n- `$container` is a [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n- `$typeParser` is a  [*TypeParser*](https://github.com/elusivecodes/FyreTypeParser).\r\n- `$lang` is a [*Lang*](https://github.com/elusivecodes/FyreLang).\r\n\r\n```php\r\n$validator = new Validator($container, $typeParser, $lang);\r\n```\r\n\r\n**Autoloading**\r\n\r\nAny dependencies will be injected automatically when loading from the [*Container*](https://github.com/elusivecodes/FyreContainer).\r\n\r\n```php\r\n$validator = $container-\u003euse(Validator::class);\r\n```\r\n\r\n\r\n## Methods\r\n\r\n**Add**\r\n\r\nAdd a validation rule.\r\n\r\n- `$field` is a string representing the field name.\r\n- `$rule` is a *Closure* or a [*Rule*](#rules) representing the validation rule.\r\n- `$options` is an array containing options for the validation rule.\r\n    - `on` is a string representing the type of validation the rule applies to, and will default to *null*.\r\n    - `message` is a string representing the [error message](#error-messages) for the rule, and will default to *null*.\r\n    - `name` is a string representing the name of the validation rule, and will default to *null*.\r\n\r\n```php\r\n$validator-\u003eadd($field, $rule, $options);\r\n```\r\n\r\nIf using a *Closure* rule, the `$rule` should be expressing in the following format:\r\n\r\n```php\r\n$rule = function(mixed $value, array $data, string $field): string|bool {\r\n    // validation logic\r\n\r\n    return true;\r\n};\r\n```\r\n\r\n**Clear**\r\n\r\nClear all rules from the *Validator*.\r\n\r\n```php\r\n$validator-\u003eclear();\r\n```\r\n\r\n**Get Field Rules**\r\n\r\nGet the rules for a field.\r\n\r\n- `$field` is a string representing the field name.\r\n\r\n```php\r\n$rules = $validator-\u003egetFieldRules($field);\r\n``` \r\n\r\n**Remove**\r\n\r\nRemove a validation rule.\r\n\r\n- `$field` is a string representing the field name.\r\n- `$name` is a string representing the rule name.\r\n\r\n```php\r\n$removed = $validator-\u003eremove($field, $name);\r\n```\r\n\r\nIf the `$name` argument is omitted, all rules will be removed instead.\r\n\r\n```php\r\n$validator-\u003eremove($field);\r\n```\r\n\r\n**Validate**\r\n\r\nPerform validation and return any errors.\r\n\r\n- `$data` is an array containing the data to validate.\r\n- `$type` is a string representing the type of validation, and will default to *null*.\r\n\r\n```php\r\n$errors = $validator-\u003evalidate($data, $type);\r\n```\r\n\r\n\r\n## Rules\r\n\r\n```php\r\nuse Fyre\\Validation\\Rule;\r\n```\r\n\r\n**Alpha**\r\n\r\nCreate an \"alpha\" *Rule*.\r\n\r\n```php\r\nRule::alpha();\r\n```\r\n\r\n**Alpha Numeric**\r\n\r\nCreate an \"alpha-numeric\" *Rule*.\r\n\r\n```php\r\nRule::alphaNumeric();\r\n```\r\n\r\n**Ascii**\r\n\r\nCreate an \"ASCII\" *Rule*.\r\n\r\n```php\r\nRule::ascii();\r\n```\r\n\r\n**Between**\r\n\r\nCreate a \"between\" *Rule*.\r\n\r\n- `$min` is a number representing the minimum value (inclusive).\r\n- `$max` is a number representing the maximum value (inclusive).\r\n\r\n```php\r\nRule::between($min, $max);\r\n```\r\n\r\n**Boolean**\r\n\r\nCreate a \"boolean\" *Rule*.\r\n\r\n```php\r\nRule::boolean();\r\n```\r\n\r\n**Decimal**\r\n\r\nCreate a \"decimal\" *Rule*.\r\n\r\n```php\r\nRule::decimal();\r\n```\r\n\r\n**Date**\r\n\r\nCreate a \"date\" *Rule*.\r\n\r\n```php\r\nRule::date();\r\n```\r\n\r\n**DateTime**\r\n\r\nCreate a \"date/time\" *Rule*.\r\n\r\n```php\r\nRule::dateTime();\r\n```\r\n\r\n**Differs**\r\n\r\nCreate a \"differs\" *Rule*.\r\n\r\n- `$field` is a string representing the other field to compare against.\r\n\r\n```php\r\nRule::differs($field);\r\n```\r\n\r\n**Email**\r\n\r\nCreate an \"email\" *Rule*.\r\n\r\n```php\r\nRule::email();\r\n```\r\n\r\n**Empty**\r\n\r\nCreate an \"empty\" *Rule*.\r\n\r\n```php\r\nRule::empty();\r\n```\r\n\r\n**Equals**\r\n\r\nCreate an \"equals\" *Rule*.\r\n\r\n- `$value` is the value to compare against.\r\n\r\n```php\r\nRule::equals($value);\r\n```\r\n\r\n**Exact Length**\r\n\r\nCreate an \"exact length\" *Rule*.\r\n\r\n- `$length` is a number representing the length.\r\n\r\n```php\r\nRule::exactLength($length);\r\n```\r\n\r\n**Greater Than**\r\n\r\nCreate a \"greater than\" *Rule*.\r\n\r\n- `$min` is the minimum value.\r\n\r\n```php\r\nRule::greaterThan($min);\r\n```\r\n\r\n**Greater Than Or Equals**\r\n\r\nCreate a \"greater than or equals\" *Rule*.\r\n\r\n- `$min` is the minimum value.\r\n\r\n```php\r\nRule::greaterThanOrEquals($min);\r\n```\r\n\r\n**In**\r\n\r\nCreate an \"in\" *Rule*.\r\n\r\n- `$values` is an array containing the values to compare against.\r\n\r\n```php\r\nRule::in($values);\r\n```\r\n\r\n**Integer**\r\n\r\nCreate an \"integer\" *Rule*.\r\n\r\n```php\r\nRule::integer();\r\n```\r\n\r\n**Ip**\r\n\r\nCreate an \"IP\" *Rule*.\r\n\r\n```php\r\nRule::ip();\r\n```\r\n\r\n**Ipv4**\r\n\r\nCreate an \"IPv4\" *Rule*.\r\n\r\n```php\r\nRule::ipv4();\r\n```\r\n\r\n**Ipv6**\r\n\r\nCreate an \"IPv6\" *Rule*.\r\n\r\n```php\r\nRule::ipv6();\r\n```\r\n\r\n**Less Than**\r\n\r\nCreate a \"less than\" *Rule*.\r\n\r\n- `$max` is the maximum value.\r\n\r\n```php\r\nRule::lessThan($max);\r\n```\r\n\r\n**Less Than Or Equals**\r\n\r\nCreate a \"less than or equals\" *Rule*.\r\n\r\n- `$max` is the maximum value.\r\n\r\n```php\r\nRule::lessThanOrEquals($max);\r\n```\r\n\r\n**Matches**\r\n\r\nCreate a \"matches\" *Rule*.\r\n\r\n- `$field` is a string representing the other field to compare against.\r\n\r\n```php\r\nRule::matches($field);\r\n```\r\n\r\n**Max Length**\r\n\r\nCreate a \"maximum length\" *Rule*.\r\n\r\n- `$length` is a number representing the maximum length.\r\n\r\n```php\r\nRule::maxLength($length);\r\n```\r\n\r\n**Min Length**\r\n\r\nCreate a \"minimum length\" *Rule*.\r\n\r\n- `$length` is a number representing the minimum length.\r\n\r\n```php\r\nRule::minLength($length);\r\n```\r\n\r\n**Natural Number**\r\n\r\nCreate a \"natural number\" *Rule*.\r\n\r\n```php\r\nRule::naturalNumber();\r\n```\r\n\r\n**Not Empty**\r\n\r\nCreate an \"not empty\" *Rule*.\r\n\r\n```php\r\nRule::notEmpty();\r\n```\r\n\r\n**Regex**\r\n\r\nCreate a \"regular expression\" *Rule*.\r\n\r\n- `$regex` is a string representing the regular expression.\r\n\r\n```php\r\nRule::regex($regex);\r\n```\r\n\r\n**Required**\r\n\r\nCreate a \"required\" *Rule*.\r\n\r\n```php\r\nRule::required();\r\n```\r\n\r\n**Require Presence**\r\n\r\nCreate a \"require presence\" *Rule*.\r\n\r\n```php\r\nRule::requirePresence();\r\n```\r\n\r\n**Time**\r\n\r\nCreate a \"time\" *Rule*.\r\n\r\n```php\r\nRule::time();\r\n```\r\n\r\n**Url**\r\n\r\nCreate a \"URL\" *Rule*.\r\n\r\n```php\r\nRule::url();\r\n```\r\n\r\n\r\n## Error Messages\r\n\r\nCustom error messages can be used by supplying the `message` property of the `$options` array to the *Validator* `add` method.\r\n\r\n```php\r\n$validator-\u003eadd('field', Rule::required(), [\r\n    'message' =\u003e 'The field is required.'\r\n]);\r\n```\r\n\r\nAlternatively, for custom validation callbacks, a string can be returned and that will be used as the error messages.\r\n\r\n```php\r\n$validator-\u003eadd('field', function(mixed $value): bool|string {\r\n    if ($value) {\r\n        return true;\r\n    }\r\n\r\n    return 'The field is required.';\r\n});\r\n```\r\n\r\nIf a custom error message is not supplied, the rule name will be used to retrieve a [*Lang*](https://github.com/elusivecodes/FyreLang) value. The field placeholder can be used for the field name, and any arguments supplied to the rule will be available as numeric placeholders.\r\n\r\n```php\r\n// language/en/Validation.php\r\n\r\nreturn [\r\n    'required' =\u003e 'The {field} is required.'\r\n];\r\n```\r\n\r\nIf no error message is available, the error message will simply be set to \"*invalid*\".","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felusivecodes%2Ffyrevalidation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felusivecodes%2Ffyrevalidation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felusivecodes%2Ffyrevalidation/lists"}