{"id":24361984,"url":"https://github.com/webdevcave/schema-validator-php","last_synced_at":"2025-03-12T09:13:40.053Z","repository":{"id":271283236,"uuid":"911763600","full_name":"WebdevCave/schema-validator-php","owner":"WebdevCave","description":null,"archived":false,"fork":false,"pushed_at":"2025-01-13T19:28:42.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-13T20:28:08.548Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WebdevCave.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":"2025-01-03T19:41:02.000Z","updated_at":"2025-01-13T19:28:46.000Z","dependencies_parsed_at":"2025-01-06T19:32:04.827Z","dependency_job_id":"93cf4a13-1903-4380-811c-43fb6da6a188","html_url":"https://github.com/WebdevCave/schema-validator-php","commit_stats":null,"previous_names":["webdevcave/schema-validator-php"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebdevCave%2Fschema-validator-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebdevCave%2Fschema-validator-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebdevCave%2Fschema-validator-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebdevCave%2Fschema-validator-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WebdevCave","download_url":"https://codeload.github.com/WebdevCave/schema-validator-php/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243188237,"owners_count":20250457,"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":"2025-01-18T22:27:12.315Z","updated_at":"2025-03-12T09:13:40.016Z","avatar_url":"https://github.com/WebdevCave.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Schema Validator\n\n[![codecov](https://codecov.io/gh/WebdevCave/schema-validator-php/graph/badge.svg?token=lC2scjv7Co)](https://codecov.io/gh/WebdevCave/schema-validator-php)\n![StyleCI](https://github.styleci.io/repos/911763600/shield?branch=main)\n\nA simple schema validation library for PHP. This package allows you to define rules for your data and validate it easily.\n\n## Table of Contents\n- [Installation](#installation)\n- [Usage](#usage)\n    - [Basic Usage](#basic-usage)\n    - [Dataset Schema Example](#dataset-validation-example)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Installation\n\nTo install the Schema Validator PHP library, you can use Composer. Run the following command:\n\n```bash\ncomposer require webdevcave/schema-validator-php\n```\n\n## Usage\n\n### Basic Usage\n\n```php\nuse Webdevcave\\SchemaValidator\\Validator;\n\n$validator = Validator::string()\n    -\u003emin(3)\n    -\u003emax(50);\n\n// Validate the data\n$isValid = $validator-\u003evalidate('Carlos');\n\nif ($isValid) {\n    echo \"Data is valid!\";\n} else {\n    echo \"Data is invalid!\";\n}\n```\n\n### Dataset Validation Example\n\nThe library also allows you to define more complex validation rules for nested structures or arrays. For example:\n\n```php\nuse Webdevcave\\SchemaValidator\\Validator;\n\n$validator = Validator::array([\n    'name' =\u003e Validator::string()\n        -\u003emin(3)\n        -\u003emax(50),\n    'email' =\u003e Validator::string()\n        -\u003epattern('/^\\w+@(\\w+|\\.)+$/'),\n    'address' =\u003e Validator::array([\n        'street' =\u003e Validator::string()-\u003emax(200),\n        'city' =\u003e Validator::string()-\u003emax(50),\n        'postal_code' =\u003e Validator::string()\n            -\u003emin(1)\n            -\u003emax(15),\n    ])\n]);\n\n// Data to be validated\n$data = [\n    'name' =\u003e 'Alice Johnson',\n    'email' =\u003e 'alice.johnson@example.com',\n    'address' =\u003e [\n        'street' =\u003e '123 Maple St',\n        'city' =\u003e 'Somewhere',\n        'postal_code' =\u003e '12345'\n    ]\n];\n\n// Validate the data\n$isValid = $validator-\u003evalidate($data);\n\nif ($isValid) {\n    echo \"Data is valid!\";\n} else {\n    echo \"Data is invalid!\";\n}\n```\n\nFor objects, just use `Validator::object()` in a similar way.\n\n### Validation Error Handling\n\nIf the data is invalid, you can get more detailed error information:\n\n```php\nuse Webdevcave\\SchemaValidator\\Validator;\n\n// Data to be validated\n$data = [\n    'name' =\u003e 'John Doe',\n    'age' =\u003e 'thirty'\n];\n\n// Define the validation schema\n$validator = Validator::array([\n    'name'  =\u003e Validator::string(),\n    'age'   =\u003e Validator::numeric()\n        -\u003einteger('Only integer numbers are allowed')\n        -\u003epositive('Age field must be positive')\n]);\n\n// Validate the data\nif (!$validator-\u003evalidate($data)) {\n    // Get and print the validation errors\n    print_r($validator-\u003eerrorMessages());\n}\n```\n\nThis will output something like:\n```\nArray\n(\n    [age] =\u003e Array \n    (\n        [0] =\u003e Only integer numbers are allowed,\n        [1] =\u003e Age field must be positive,   \n    )\n)\n```\n\n## Contributing\n\nWe welcome contributions to this project! If you'd like to help improve the Schema Validator PHP library, please follow these steps:\n\n### How to Contribute\n\n1. Fork this repository to your GitHub account.\n2. Create a new branch for your feature or fix.\n3. Make your changes and test them thoroughly.\n4. Submit a pull request with a description of your changes and why they're needed.\n\n### Code Style\n\nPlease follow the [PSR-12](https://www.php-fig.org/psr/psr-12/) coding standards for PHP when making contributions.\n\n### Issues\n\nIf you encounter any bugs or have suggestions for improvements, please open an issue in the GitHub repository.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebdevcave%2Fschema-validator-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebdevcave%2Fschema-validator-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebdevcave%2Fschema-validator-php/lists"}