{"id":22446793,"url":"https://github.com/ivangrigorov/vmvalidator","last_synced_at":"2025-08-01T21:32:16.009Z","repository":{"id":38679387,"uuid":"381169606","full_name":"IvanGrigorov/VMValidator","owner":"IvanGrigorov","description":"Hello, this is simple attribute validation for PHP Models, based on the new features, presented in PHP 8","archived":false,"fork":false,"pushed_at":"2022-11-19T02:37:59.000Z","size":137,"stargazers_count":97,"open_issues_count":0,"forks_count":3,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-12-06T04:11:10.882Z","etag":null,"topics":["packagist","php","php8","profiling","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/IvanGrigorov.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}},"created_at":"2021-06-28T21:52:27.000Z","updated_at":"2024-11-25T13:39:33.000Z","dependencies_parsed_at":"2023-01-22T02:51:23.117Z","dependency_job_id":null,"html_url":"https://github.com/IvanGrigorov/VMValidator","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IvanGrigorov%2FVMValidator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IvanGrigorov%2FVMValidator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IvanGrigorov%2FVMValidator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IvanGrigorov%2FVMValidator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IvanGrigorov","download_url":"https://codeload.github.com/IvanGrigorov/VMValidator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228407894,"owners_count":17915083,"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":["packagist","php","php8","profiling","validation"],"created_at":"2024-12-06T04:11:28.284Z","updated_at":"2024-12-06T04:11:29.312Z","avatar_url":"https://github.com/IvanGrigorov.png","language":"PHP","readme":"# VMValidator\n\n[![VMValidator test check](https://github.com/IvanGrigorov/VMValidator/actions/workflows/php.yml/badge.svg)](https://github.com/IvanGrigorov/VMValidator/actions/workflows/php.yml)\n\n![VMValidator](https://user-images.githubusercontent.com/10940601/150609303-c7566864-06ce-402b-90c8-85cfcb70e55c.jpg)\n\n![](https://badgen.net/badge/code%20coverage/70%20%25/green?icon=codecov) ![](https://badgen.net/badge/build/passing/green?icon=status) ![](https://badgen.net/badge/icon/buymeacoffee?icon=buymeacoffee\u0026label)\n\n[![\"Buy Me A Coffee\"](https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png)](https://www.buymeacoffee.com/ivangrigorov)\n\n\nHello, this is simple attribute validation for PHP Models, based on the new features, presented in [PHP 8](https://www.php.net/releases/8.0/en.php) It works as a standalone and can be use in custom projects or in libraries like Symfony and Laravel.\n\nUse just [three rows](https://github.com/IvanGrigorov/VMValidator/blob/2139877c4ca6ae01f60729db2d83f9c5e087096d/index.php), alogside some [attributes](https://github.com/IvanGrigorov/VMValidator/blob/2139877c4ca6ae01f60729db2d83f9c5e087096d/index.php):\n\n# Example \n\n```php\n\u003c?php\n\nuse RMValidator\\Attributes\\PropertyAttributes\\Collection\\UniqueAttribute;\nuse RMValidator\\Attributes\\PropertyAttributes\\File\\FileExtensionAttribute;\nuse RMValidator\\Attributes\\PropertyAttributes\\File\\FileSizeAttribute;\nuse RMValidator\\Attributes\\PropertyAttributes\\Numbers\\RangeAttribute;\nuse RMValidator\\Attributes\\PropertyAttributes\\Object\\NestedAttribute;\nuse RMValidator\\Attributes\\PropertyAttributes\\Strings\\StringContainsAttribute;\nuse RMValidator\\Enums\\ValidationOrderEnum;\nuse RMValidator\\Options\\OptionsModel;\nuse RMValidator\\Validators\\MasterValidator;\n\nrequire __DIR__ . '/vendor/autoload.php';\n\n\nclass Test \n{\n    public function __construct(\n        #[RangeAttribute(from:10, to:50)]\n        #[RangeAttribute(from:10, to:30)]\n        public int $param)\n    {\n        \n    }\n\n    #[RangeAttribute(from:10, to:30)]\n    const propTest = 40;\n\n    #[UniqueAttribute()]\n    public function custom() {\n        return ['asd', 'asdk'];\n    }\n\n    #[FileSizeAttribute(fileSizeBiggest: 20, fileSizeLowest: 10)]\n    #[FileExtensionAttribute(expected:['php'])]\n    private function getFile() {\n        return __FILE__;\n    }\n\n    #[FileSizeAttribute(fileSizeBiggest: 20, fileSizeLowest: 10)]\n    #[FileExtensionAttribute(expected:['php'])]\n    public string $file = __FILE__;\n\n    #[StringContainsAttribute(needle:\"asd\")]\n    public string $string = \"23asd\";\n\n    #[RangeAttribute(from:10, to:30)]\n    public int $prop = 40;\n}\n\nclass UpperTest\n{\n    #[NestedAttribute(excludedProperties:['param'])]\n    private Test $test;\n\n    public function __construct(Test $test) {\n        $this-\u003etest = $test;\n    }\n}\n\n$test = new Test(40);\n\ntry {\n    MasterValidator::validate(new UpperTest($test), \n    new OptionsModel(orderOfValidation: [ValidationOrderEnum::PROPERTIES, \n                                         ValidationOrderEnum::METHODS,\n                                         ValidationOrderEnum::CONSTANTS], \n                     excludedMethods: ['getFile'], \n                     excludedProperties: ['file']));\n} catch(Exception $e) {\n    var_dump($e);\n}\n```\n\n# Installation\n\n```bash\ncomposer require ivangrigorov/vmvalidator\n```\n\n\n# Options\n\nIn what order to validate the classes (methods or properties first),  and what to exclude is directly configurable runtime [here](https://github.com/IvanGrigorov/VMValidator/blob/master/RMValidator/Options/OptionsModel.php)\n\n# Extras\n\n - [x] Lots of validations\n - [x] Supports also nested object validation\n - [x] Supports also collection item types and collection item validations\n - [x] Supports also custom validations*\n - [x] Supports also or validations*\n - [x] Nullable check\n - [x] Repeatable validation attributes\n - [x] Works with private properties and methods\n - [x] Works with constructor promotion\n - [x] Memory and time profiling\n - [x] Custom error messages\n - [x] Custom property and method names for the exceptions\n - [x] Severity levels\n - [x] Debug explorer\n - [x] Callback execution*\n\n\n### *The custom validation should be declared as static in a validation class\n```php\nclass Validation \n{\n    public static function validate($valueToTest, $arg1): bool \n    {\n        return $valueToTest == $arg1;\n    }\n}\n```\nThe method should always return boolean: ```true``` for valid input and ```false``` for invalid.\n\nIn the declaration:\n```php\n#[CustomAttribute(staticClassName: Validation::class, staticMethodName: 'validate', args: [2])]\n```\nYou can pass additional arguments to use in the validation function, but the first parameter is always the value to be tested.\n\n\n### *The or validation uses custom attribute names\n```\n    #[RangeAttribute(from:10, to:30, name: \"orOne\")]\n    #[RangeAttribute(from:10, to:40, name: \"orTwo\")]\n    const tttt = 40;\n```\n\n```\n    MasterValidator::validate($test, new OptionsModel(orAttributes: ['orOne', 'orTwo']));\n\n```\n\n### *Callback execution\n\n```$successCallable``` is executed on successful validation\n\n```$failureCallable``` is executed on unsuccessful validation\n\n```$forcedCallable``` is executed on successful AND unsuccessful validation\n\n\n\n\n### Severity\nAdd option to make the failed validation throw NOTICE|WARNING|ERROR\n```\n    #[RangeAttribute(from:10, to:30, severity: SeverityEnum::ERROR)]\n\n```\n\n### Debugging\nAdd option to display all validations per class\n```\n    MasterValidator::debug(\u003cClassToDebug\u003e::class);\n```\n\n\n# Support\n\n - Request a new validation\n - Give a star\n - Just say hi !\n","funding_links":["https://www.buymeacoffee.com/ivangrigorov"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivangrigorov%2Fvmvalidator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fivangrigorov%2Fvmvalidator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivangrigorov%2Fvmvalidator/lists"}