{"id":33997503,"url":"https://github.com/zxc7563598/php-schema-validator","last_synced_at":"2025-12-13T08:58:34.736Z","repository":{"id":308645696,"uuid":"1033562852","full_name":"zxc7563598/php-schema-validator","owner":"zxc7563598","description":"一个简单且可扩展的 PHP 参数验证库，支持规则式定义与自定义扩展，适用于任何结构化数据校验场景 | A simple and extensible PHP parameter validation library, supporting rule-based definitions and custom extensions, suitable for any structured data verification scenarios","archived":false,"fork":false,"pushed_at":"2025-08-07T05:53:56.000Z","size":18,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-10T04:53:38.680Z","etag":null,"topics":["custom-rules","data-validation","input-validation","php","php-library","schema-validation","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/zxc7563598.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":"2025-08-07T02:39:50.000Z","updated_at":"2025-08-21T00:03:44.000Z","dependencies_parsed_at":"2025-08-07T04:27:29.280Z","dependency_job_id":"0537f18e-75f5-47dc-9c8f-25f8fef9a337","html_url":"https://github.com/zxc7563598/php-schema-validator","commit_stats":null,"previous_names":["zxc7563598/php-schema-validator"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/zxc7563598/php-schema-validator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zxc7563598%2Fphp-schema-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zxc7563598%2Fphp-schema-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zxc7563598%2Fphp-schema-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zxc7563598%2Fphp-schema-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zxc7563598","download_url":"https://codeload.github.com/zxc7563598/php-schema-validator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zxc7563598%2Fphp-schema-validator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27702869,"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-12-13T02:00:09.769Z","response_time":147,"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":["custom-rules","data-validation","input-validation","php","php-library","schema-validation","validation"],"created_at":"2025-12-13T08:58:34.256Z","updated_at":"2025-12-13T08:58:34.727Z","avatar_url":"https://github.com/zxc7563598.png","language":"PHP","readme":"# hejunjie/schema-validator\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"./README.md\"\u003eEnglish\u003c/a\u003e｜\u003ca href=\"./README.zh-CN.md\"\u003e简体中文\u003c/a\u003e\n  \u003chr width=\"50%\"/\u003e\n\u003c/div\u003e\n\nA simple and extensible PHP parameter validation library, supporting rule-based definitions and custom extensions, suitable for any structured data verification scenarios\n\n**This project has been parsed by Zread. If you need a quick overview of the project, you can click here to view it：[Understand this project](https://zread.ai/zxc7563598/php-schema-validator)**\n\n---\n\n## 📦 Installation method\n\nInstall using Composer：\n\n```bash\ncomposer require hejunjie/schema-validator\n```\n\n---\n\n## 🚀 Usage\n\nSupport multiple rule definitions + throw exceptions + custom extensions：\n\n```php\nuse Hejunjie\\SchemaValidator\\Validator;\nuse Hejunjie\\SchemaValidator\\Exceptions\\ValidationException;\n\n$data = [\n    'name'   =\u003e '张三',\n    'age'    =\u003e 28,\n    'email'  =\u003e 'invalid-email',\n];\n\n// Custom extension. If true is returned, the rule passes; otherwise, it is considered as failing\nValidator::extend('is_zh', function ($field, $value, $params = null) {\n    if (preg_match('/^[\\x{4e00}-\\x{9fa5}]+$/u', $value)) {\n        return true;\n    }\n});\n\ntry {\n    Validator::validate($data, [\n        'name'  =\u003e ['is_zh', 'string', 'minLength:2'],\n        'age'   =\u003e ['integer', 'between:18,60'],\n        'email' =\u003e ['required', 'email'],\n    ]);\n    echo \"Verified by ✅\";\n} catch (ValidationException $e) {\n    echo \"Validation failed ❌\" . PHP_EOL;\n    print_r($e-\u003egetErrors());\n}\n\n// Return the fields and rules indicating whether it is passed or failed:\n// Validation failed ❌\n// Array\n// (\n//     [email] =\u003e Array\n//         (\n//             [0] =\u003e email\n//         )\n\n// )\n```\n\n---\n\n## ✅ Default support rule\n\nThe following rules are already supported in a built-in manner and are implemented as independent classes, allowing for free extension or replacement：\n\n### Type class\n\n| Rule Name     | Function Description                                                           | Parameter Format | Example Usage              |\n| ------------- | ------------------------------------------------------------------------------ | ---------------- | -------------------------- |\n| `StringRule`  | Verify whether it is a string                                                  | `string`         | `['param' =\u003e ['string']]`  |\n| `IntegerRule` | Verify whether it is an integer                                                | `integer`        | `['param' =\u003e ['integer']]` |\n| `BooleanRule` | Verify whether it is a boolean value (true/false or 0/1)                       | `boolean`        | `['param' =\u003e ['boolean']]` |\n| `ArrayRule`   | Verify whether it is an array                                                  | `array`          | `['param' =\u003e ['array']]`   |\n| `ObjectRule`  | Verify whether it is an object                                                 | `object`         | `['param' =\u003e ['object']]`  |\n| `FloatRule`   | Verify whether it is a floating-point number                                   | `float`          | `['param' =\u003e ['float']]`   |\n| `NumericRule` | Verify whether it is a number (including integer, floating-point string, etc.) | `numeric`        | `['param' =\u003e ['numeric']]` |\n\n---\n\n### Compare class\n\n| Rule Name       | Function Description                                                                                     | Parameter Format | Example Usage                    |\n| --------------- | -------------------------------------------------------------------------------------------------------- | ---------------- | -------------------------------- |\n| `MinRule`       | The numerical value or string length cannot be less than the specified value                             | `min`            | `['param' =\u003e ['min:2']]`         |\n| `MaxRule`       | The size of numbers or the length of strings are not allowed to exceed the specified value               | `max`            | `['param' =\u003e ['max:2']]`         |\n| `BetweenRule`   | The size of a number or the length of a string must fall within the specified minimum and maximum values | `between`        | `['param' =\u003e ['between:18,60']]` |\n| `LengthRule`    | The length of the string must be equal to the specified value                                            | `length`         | `['param' =\u003e ['length:10']]`     |\n| `MinLengthRule` | The length of the string is not allowed to exceed the specified value                                    | `min_length`     | `['param' =\u003e ['min_length:2']]`  |\n| `MaxLengthRule` | The length of the string cannot be less than the specified value                                         | `max_length`     | `['param' =\u003e ['max_length:20']]` |\n| `GtRule`        | The number must be greater than the specified value                                                      | `gt`             | `['param' =\u003e ['gt:2']]`          |\n| `LtRule`        | The number must be less than the specified value                                                         | `lt`             | `['param' =\u003e ['lt:2']]`          |\n| `GteRule`       | The number must be greater than or equal to the specified value                                          | `gte`            | `['param' =\u003e ['gte:2']]`         |\n| `LteRule`       | The number must be less than or equal to the specified value                                             | `lte`            | `['param' =\u003e ['lte:2']]`         |\n\n---\n\n### Format class\n\n| Rule Name       | Function Description                                                      | Parameter Format | Example Usage                 |\n| --------------- | ------------------------------------------------------------------------- | ---------------- | ----------------------------- |\n| `EmailRule`     | The content must be in email format                                       | `email`          | `['param' =\u003e ['email']]`      |\n| `MobileRule`    | The content must be in the format of a mainland China mobile phone number | `mobile`         | `['param' =\u003e ['mobile']]`     |\n| `UrlRule`       | The content must be a URL                                                 | `url`            | `['param' =\u003e ['url']]`        |\n| `IpRule`        | The content must be a valid IP address (IPv4 or IPv6)                     | `ip`             | `['param' =\u003e ['ip']]`         |\n| `JsonRule`      | The content must be a valid JSON string                                   | `json`           | `['param' =\u003e ['json']]`       |\n| `AlphaRule`     | The content can only contain letters                                      | `alpha`          | `['param' =\u003e ['alpha']]`      |\n| `AlphaNumRule`  | The content can only contain letters and numbers                          | `alpha_num`      | `['param' =\u003e ['alpha_num']]`  |\n| `AlphaDashRule` | The content can only contain letters, numbers, dashes, and underscores    | `alpha_dash`     | `['param' =\u003e ['alpha_dash']]` |\n\n---\n\n### Boolean class\n\n| Rule Name      | Function Description                                 | Parameter Format | Example Usage               |\n| -------------- | ---------------------------------------------------- | ---------------- | --------------------------- |\n| `RequiredRule` | The content must exist and not be empty              | `required`       | `['param' =\u003e ['required']]` |\n| `AcceptedRule` | The content can only be \"yes\", \"on\", \"1\", or \"true\"  | `accepted`       | `['param' =\u003e ['accepted']]` |\n| `DeclinedRule` | The content can only be \"no\", \"off\", \"0\", or \"false\" | `declined`       | `['param' =\u003e ['declined']]` |\n\n---\n\n### Custom class\n\n| Rule Name        | Function Description                             | Parameter Format | Example Usage                  |\n| ---------------- | ------------------------------------------------ | ---------------- | ------------------------------ |\n| `StartsWithRule` | The content must start with the specified string | `starts_with`    | `['param' =\u003e ['starts_with']]` |\n| `EndsWithRule`   | The content must end with the specified string   | `ends_with`      | `['param' =\u003e ['ends_with']]`   |\n| `ContainsRule`   | The content must contain the specified string    | `contains`       | `['param' =\u003e ['contains']]`    |\n\n\u003e The error message is returned as an array of rule names, and the prompt text can be customized\n\n---\n\n## 🧩 Purpose \u0026 Original Intent\n\nIn daily development, we often need to perform structured validation on incoming data, but many existing libraries are either bulky, rely on frameworks, or are not flexible in terms of extension (such as Laravel Validator).\n\nThe goal of this library is to:\n\n- ✅ Zero dependencies, suitable for any PHP project\n- ✅ Validation for structured arrays\n- ✅ Each rule is encapsulated independently, facilitating customization and expansion\n- ✅ More suitable for field prompts and error handling in the Chinese context\n\nIf you need a simple, clear, and rule-controlled data verification tool, it may be just right for you.\n\n---\n\n## 🙌 Welcome to contribute\n\nWelcome to raise issues, submit pull requests, or directly fork for use!\n\nIf you have other commonly used validation rules, feel free to add them, even if it's just a line of regular expression.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzxc7563598%2Fphp-schema-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzxc7563598%2Fphp-schema-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzxc7563598%2Fphp-schema-validator/lists"}