{"id":16954349,"url":"https://github.com/nanosector/validation-closures","last_synced_at":"2026-02-21T22:06:33.931Z","repository":{"id":57087961,"uuid":"95682444","full_name":"NanoSector/validation-closures","owner":"NanoSector","description":"Closures useful for validating data. Provides type validation amongst other filters.","archived":false,"fork":false,"pushed_at":"2019-05-26T15:27:50.000Z","size":38,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-09T06:35:08.232Z","etag":null,"topics":["closure","closures","filter","php","validation-closures"],"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/NanoSector.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":"2017-06-28T15:09:51.000Z","updated_at":"2019-05-26T15:27:51.000Z","dependencies_parsed_at":"2022-08-24T14:42:28.329Z","dependency_job_id":null,"html_url":"https://github.com/NanoSector/validation-closures","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/NanoSector/validation-closures","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NanoSector%2Fvalidation-closures","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NanoSector%2Fvalidation-closures/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NanoSector%2Fvalidation-closures/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NanoSector%2Fvalidation-closures/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NanoSector","download_url":"https://codeload.github.com/NanoSector/validation-closures/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NanoSector%2Fvalidation-closures/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281086019,"owners_count":26441337,"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-26T02:00:06.575Z","response_time":61,"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":["closure","closures","filter","php","validation-closures"],"created_at":"2024-10-13T22:09:29.422Z","updated_at":"2025-10-26T09:39:54.724Z","avatar_url":"https://github.com/NanoSector.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Validation Closures\n[![Build Status](https://scrutinizer-ci.com/g/Yoshi2889/validation-closures/badges/build.png)](https://scrutinizer-ci.com/g/Yoshi2889/validation-closures/build-status/master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Yoshi2889/validation-closures/badges/quality-score.png)](https://scrutinizer-ci.com/g/Yoshi2889/validation-closures/?branch=master)\n[![Scrutinizer Code Coverage](https://scrutinizer-ci.com/g/Yoshi2889/validation-closures/badges/coverage.png)](https://scrutinizer-ci.com/g/Yoshi2889/validation-closures/code-structure/master/code-coverage)\n[![Latest Stable Version](https://poser.pugx.org/yoshi2889/validation-closures/v/stable)](https://packagist.org/packages/yoshi2889/validation-closures)\n[![Latest Unstable Version](https://poser.pugx.org/yoshi2889/validation-closures/v/unstable)](https://packagist.org/packages/yoshi2889/validation-closures)\n[![Total Downloads](https://poser.pugx.org/yoshi2889/validation-closures/downloads)](https://packagist.org/packages/yoshi2889/validation-closures)\n\nClosures useful for validating data. Provides type validation amongst other filters.\n\n## Installation\nYou can install this class via `composer`:\n\n```composer require yoshi2889/validation-closures```\n\n## Usage\nAll closures are exposed as public static methods. For example, to use the Types\\string() closure:\n\n```php\n$closure = \\ValidationClosures\\Types::string();\n\n$is_string = $closure('This is a string');\n\n// True\necho $is_string ? 'True' : 'False';\n```\n\nIn the following documentation, all methods return a value of type `boolean` unless stated otherwise.\n\n### Ranges\nThe Ranges class contains methods to check if values are within a range. It contains the following methods:\n\n* `stringWithLengthBetween(int $minimumLength, int $maximumLength)`: Test if a given string has a length within the range\n`$minimumLength \u003c= length \u003c= $maximumLength`\n* `intBetween(int $minimum, int $maximum)`: Test if a given int is inside the range of `$minimum \u003c= int \u003c= $maximum`\n* `intBetweenExclusive(int $minimum, int $maximum)`: Test if a given int is inside the range of `$minimum \u003c int \u003c $maximum`\n* `floatBetween(float $minimum, float $maximum)`: Identical to `intBetween`, except it tests on floats.\n* `floatBetweenExclusive(float $minimum, float $maximum)`: Identical to `intBetweenExclusive`, except it tests on floats.\n* `enum(...$allowedValues)`: Test if a given value exists inside `$allowedValues`, similar to an Enum type in other languages.\n* `typeEnum(...$allowedTypes)`: Test if a given value is of a type inside `$allowedTypes`.\n* `stringOneOf(...$allowedValues)`: Test if a given string exists inside `$allowedValues`.\n\n### Reflection\nThe Reflection class allows you to create closures out of all methods found in [PHP's ReflectionClass](http://php.net/manual/en/class.reflectionclass.php).\nIt is most useful with the `is*` methods. For example, to create a closure for the [implementsInterface method](http://php.net/manual/en/reflectionclass.implementsinterface.php):\n\n```php\n$closure = Reflection::implementsInterface(stdClass::class);\n```\n\nThe Reflection class will take care of instantiating a `ReflectionClass` object automatically.\n\n### Types\nThe Types class contains methods to use for type validation. It contains the following methods:\n\n* `string()`: Test if a given value is a string.\n* `int()`: Test if a given value is an integer.\n* `float()`: Test if a given value is a float.\n* `boolean()`: Test if a given value is a boolean.\n* `array()`: Test if a given value is an array.\n* `callable()`: Test if a given value is a callable function/method.\n* `object()`: Test if a given value is an instantiated object.\n* `numeric()`: Test if a given value is a numeric value. (see [is_numeric](https://secure.php.net/manual/en/function.is-numeric.php) in the PHP manual for details)\n* `instanceof(string $class)`: Test if a given value is an instance of the given class.\n\n### Utils\nThe Utils class contains methods to manipulate closures. It contains the following methods:\n\n* `invert(\\Closure $closure): \\Closure`: Invert a closure. For example, `Types::string()` inverted would pass all values which are **not** strings.\n* `merge(\\Closure $closure1, \\Closure $closure2): \\Closure`: Merge two closures together. The resulting closure will return true if **either** closure\nor both closures resolve(s) to true.\n* `both(\\Closure $closure1, \\Closure $closure2): \\Closure`: Merge two closures together. The resulting closure will return true only if **both**\nclosures resolve to true.\n* `validateArray(\\Closure $closure, array $values): bool`: Tests if all values in a given array validate with the given closure.\nReturns false if 1 or more values do not validate, returns true if all elements validate.\n\n## License\nThis code is released under the MIT License. Please see `LICENSE` to read it.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanosector%2Fvalidation-closures","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnanosector%2Fvalidation-closures","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanosector%2Fvalidation-closures/lists"}