{"id":18750661,"url":"https://github.com/webiny/validation","last_synced_at":"2025-10-15T12:55:19.283Z","repository":{"id":68107183,"uuid":"66214976","full_name":"webiny/Validation","owner":"webiny","description":"[READ ONLY] Webiny Framework validation component","archived":false,"fork":false,"pushed_at":"2017-11-26T21:25:45.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-12T08:07:02.776Z","etag":null,"topics":[],"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/webiny.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-08-21T18:47:39.000Z","updated_at":"2017-05-15T17:48:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"9a9eca82-aef4-4110-94c5-000a76909075","html_url":"https://github.com/webiny/Validation","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/webiny/Validation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FValidation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FValidation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FValidation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FValidation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webiny","download_url":"https://codeload.github.com/webiny/Validation/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FValidation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279080200,"owners_count":26098930,"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-10-15T02:00:07.814Z","response_time":56,"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":[],"created_at":"2024-11-07T17:12:43.631Z","updated_at":"2025-10-15T12:55:19.265Z","avatar_url":"https://github.com/webiny.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Validation Component\n=====================\n\n## Using validation\nUse `ValidationTrait` to access the component. The component does not require any configuration.\nYou can validate agains single validator or pass an array of validators, or event a comma-separated string of validators:\n\n```php\nclass MyClass {\n    use ValidationTrait;\n    \n    public function example() {\n        try{\n            $this-\u003evalidation()-\u003evalidate(123, 'number');\n            $this-\u003evalidation()-\u003evalidate('my@email.com', 'email');\n            $this-\u003evalidation()-\u003evalidate(20, ['number','gte:100']);\n            $this-\u003evalidation()-\u003evalidate(10, 'number,lt:50']);\n        } catch (ValidationException $e) {\n            // Handle exception\n        }\n        \n        // You can also tell validation to NOT THROW but simply return `false`\n        // NOTE: make sure you use `===` because if value is invalid we return an error message!\n        if($this-\u003evalidation()-\u003evalidate(123, 'number', false) === true) {\n            // I am a valid number\n        } else {\n            // I am an invalid number\n        }\n    }\n}\n```\n\n## Adding custom validators\nYou can add/override validators by implementing a `ValidatorInterface`:\n\n```php\nclass MyValidator implements ValidatorInterface {\n    \n    public function getName() {\n        return 'myCustomValidator';\n    }\n    \n    public function validate($value, $params = [], $throw = true) {\n        $message = 'Value must be this and that';\n        \n        $myExpectedValue = 'myExpectedValue';\n        \n        if ($value == $myExpectedValue) {\n            return true;\n        }\n        \n        if ($throw) {\n            throw new ValidationException($message);\n        }\n        \n        return $message;\n    }\n}\n\n// Add new validator\n$this-\u003evalidation()-\u003eaddValidator(new MyValidator());\n\n// And now call your validator\n$this-\u003evalidation()-\u003evalidate(123, 'myCustomValidator');\n```\n\nYou can also register your validators through services, by tagging them with `validation-plugin`. \n\n```yaml\nServices:\n    MyCustomValidator:\n        Class: \\My\\Custom\\Validator\n        Tags: ['validation-plugin']\n```\n\n## Validator parameters\nIf you pass params to your validator, like `$this-\u003evalidation()-\u003evalidate(123, 'myCustomValidator:50:20');` they will be passed to your \nvalidator class in `$params`. `$params` are index based, so your parameters will look like `[50, 20]`.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebiny%2Fvalidation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebiny%2Fvalidation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebiny%2Fvalidation/lists"}