{"id":15030337,"url":"https://github.com/anshu-krishna/php-data-validator","last_synced_at":"2026-01-04T23:06:20.437Z","repository":{"id":39373290,"uuid":"418855636","full_name":"anshu-krishna/PHP-Data-Validator","owner":"anshu-krishna","description":"A PHP library for simplifying complexly-structured-data validation.","archived":false,"fork":false,"pushed_at":"2024-09-15T21:16:20.000Z","size":68,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-15T06:36:54.096Z","etag":null,"topics":["data-validation","data-validator","php","php81","validation","validator"],"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/anshu-krishna.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":"2021-10-19T09:26:14.000Z","updated_at":"2024-09-15T21:14:58.000Z","dependencies_parsed_at":"2024-09-28T20:40:37.640Z","dependency_job_id":"0677bd03-ef3c-4d8a-9215-0de673321010","html_url":"https://github.com/anshu-krishna/PHP-Data-Validator","commit_stats":{"total_commits":37,"total_committers":1,"mean_commits":37.0,"dds":0.0,"last_synced_commit":"d21b61301f84b2c2fb16268d5e9cebfde429dfa6"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anshu-krishna%2FPHP-Data-Validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anshu-krishna%2FPHP-Data-Validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anshu-krishna%2FPHP-Data-Validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anshu-krishna%2FPHP-Data-Validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anshu-krishna","download_url":"https://codeload.github.com/anshu-krishna/PHP-Data-Validator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239060464,"owners_count":19574969,"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":["data-validation","data-validator","php","php81","validation","validator"],"created_at":"2024-09-24T20:13:08.519Z","updated_at":"2025-10-30T21:30:19.228Z","avatar_url":"https://github.com/anshu-krishna.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP Data-Validator\r\nA PHP library for simplifying complexly-structured-data validation.\r\n\r\n***Note: Version \u003e=2.0 is incompatible with older versions.***\r\n\r\n### Installation\r\n```\r\ncomposer require anshu-krishna/data-validator\r\n```\r\n## Features:\r\n* Supported types:\r\n\t* `bool` : Boolean value\r\n\t* `email` : String containing an email address\r\n\t* `float` : Float value\r\n\t* `hex` : String containing a hex value\r\n\t* `int` : Int value\r\n\t* `ipv4` : String containing an IPv4 address\r\n\t* `ipv6` : String containing an IPv6 address\r\n\t* `mac` : String containing a MAC address\r\n\t* `mixed` : Any value\r\n\t* `null` : Null value\r\n\t* `number` : Int or Float value\r\n\t* `string` : String value\r\n\t* `timestamp` : String containing a timestamp.\\\r\n\t\t\t\t\teg: '2021-01-31', 'today', 'yesterday', '01-Jan-2021', 'January 1, 2021 05:00:10 AM GMT+05:30', etc.\r\n\t* `timestamp_utc` : String containing a timestamp (it will be converted to UTC timezone).\\\r\n\t\t\t\t\teg: '2021-01-31', 'today', 'yesterday', '01-Jan-2021', 'January 1, 2021 05:00:10 AM GMT+05:30', '2024-06-15T20:12:52+05:30:10', etc.\r\n\t* `unsigned` : Int \u003e= 0\r\n\t* `url` : String containing a URL\r\n\t* `uuid` : String containing a UUIDv4\r\n\r\n* Custom data types can also be added. For example see `./examples`\r\n\r\n* Multiple alternative data types can be set for a data item. eg: `'int|float|null'`, `'ipv4|ipv6'`, etc.\r\n\r\n* Supports Ranger/Formatter for validated data\r\n\r\n## Example:\r\n```php\r\n\u003c?php\r\nrequire_once 'vendor/autoload.php';\r\n\r\nuse Krishna\\DataValidator\\ComplexException;\r\nuse Krishna\\DataValidator\\OutOfBoundAction;\r\nuse Krishna\\DataValidator\\Validator;\r\ntry {\r\n   $dv = new Validator([\r\n      'a' =\u003e 'int',\r\n      // a is required and must be an integer\r\n      \r\n      '?b' =\u003e 'float',\r\n      // b is optional and must be a float\r\n      \r\n      '??c' =\u003e 'unsigned',\r\n      // c is optional and must be an unsigned integer;\r\n      // if not provided, it will be set to null\r\n      \r\n      'd' =\u003e 'null|int|uuid',\r\n      // d is required and must be an integer or a UUIDv4 or null\r\n   ], OutOfBoundAction::Trim);\r\n}\r\ncatch (ComplexException $e) {\r\n   echo 'Unable to create validator';\r\n   var_dump($th-\u003egetInfo());\r\n   die();\r\n}\r\n\r\n$result = $dv-\u003evalidate([\r\n   'a' =\u003e 10,\r\n   'b' =\u003e '20.5',\r\n   'd' =\u003e 'f47ac10b-58cc-4372-a567-0e02b2c3d479',\r\n]);\r\nvar_dump($result);\r\n/*\r\nOutput:\r\nobject(Krishna\\DataValidator\\Returner)[14]\r\npublic readonly mixed 'value' =\u003e \r\narray (size=4)\r\n   'a' =\u003e int 10\r\n   'b' =\u003e float 20.5\r\n   'c' =\u003e null\r\n   'd' =\u003e string 'f47ac10b-58cc-4372-a567-0e02b2c3d479' (length=36)\r\npublic readonly mixed 'error' =\u003e null\r\npublic readonly bool 'valid' =\u003e boolean true\r\n*/\r\n\r\n$result = $dv-\u003evalidate([\r\n   'a' =\u003e '10',\r\n   'b' =\u003e 20,\r\n   'c' =\u003e 5,\r\n   'd' =\u003e 'f47ac10b-58cc-4372-a567-0e02b2c3d479',\r\n]);\r\nvar_dump($result);\r\n/*\r\nOutput:\r\nobject(Krishna\\DataValidator\\Returner)[7]\r\npublic readonly mixed 'value' =\u003e \r\narray (size=4)\r\n   'a' =\u003e int 10\r\n   'b' =\u003e float 20\r\n   'c' =\u003e int 5\r\n   'd' =\u003e string 'f47ac10b-58cc-4372-a567-0e02b2c3d479' (length=36)\r\npublic readonly mixed 'error' =\u003e null\r\npublic readonly bool 'valid' =\u003e boolean true\r\n*/\r\n\r\n$result = $dv-\u003evalidate([\r\n   'a' =\u003e '0x10',\r\n   'd' =\u003e 20,\r\n   'e' =\u003e 30,\r\n]);\r\nvar_dump($result);\r\n/*\r\nOutput:\r\nobject(Krishna\\DataValidator\\Returner)[17]\r\npublic readonly mixed 'value' =\u003e \r\narray (size=3)\r\n   'a' =\u003e int 16\r\n   'c' =\u003e null\r\n   'd' =\u003e int 20\r\npublic readonly mixed 'error' =\u003e null\r\npublic readonly bool 'valid' =\u003e boolean true\r\n*/\r\n\r\n$result = $dv-\u003evalidate([\r\n   'b' =\u003e 'abc',\r\n   'c' =\u003e 'def',\r\n   'd' =\u003e 'null',\r\n]);\r\nvar_dump($result);\r\n/*\r\nOutput:\r\nobject(Krishna\\DataValidator\\Returner)[7]\r\npublic readonly mixed 'value' =\u003e null\r\npublic readonly mixed 'error' =\u003e \r\nobject(Krishna\\DataValidator\\ErrorReader)[14]\r\n   public 0 =\u003e string '[a]: Missing' (length=12)\r\n   public 1 =\u003e string '[b]: Expected 'float'' (length=21)\r\n   public 2 =\u003e string '[c]: Expected 'unsigned'' (length=24)\r\npublic readonly bool 'valid' =\u003e boolean false\r\n*/\r\n```\r\n___\r\n\r\n### See `./examples` for more info.\r\n### Documentation/Examples is under construction","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanshu-krishna%2Fphp-data-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanshu-krishna%2Fphp-data-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanshu-krishna%2Fphp-data-validator/lists"}