{"id":37011773,"url":"https://github.com/guardsman/guardsman","last_synced_at":"2026-01-14T01:01:11.070Z","repository":{"id":36933195,"uuid":"41240483","full_name":"guardsman/guardsman","owner":"guardsman","description":"Guard clause assertion library to enforce parameter preconditions in PHP","archived":true,"fork":false,"pushed_at":"2016-07-15T05:58:31.000Z","size":71,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-25T09:42:06.256Z","etag":null,"topics":["assertion-library","guard","php","preconditions"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":false,"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/guardsman.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-23T07:35:40.000Z","updated_at":"2023-01-28T03:48:53.000Z","dependencies_parsed_at":"2022-07-07T20:44:55.429Z","dependency_job_id":null,"html_url":"https://github.com/guardsman/guardsman","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/guardsman/guardsman","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guardsman%2Fguardsman","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guardsman%2Fguardsman/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guardsman%2Fguardsman/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guardsman%2Fguardsman/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guardsman","download_url":"https://codeload.github.com/guardsman/guardsman/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guardsman%2Fguardsman/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28407635,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T00:40:43.272Z","status":"ssl_error","status_checked_at":"2026-01-14T00:40:42.636Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["assertion-library","guard","php","preconditions"],"created_at":"2026-01-14T01:00:56.354Z","updated_at":"2026-01-14T01:01:10.895Z","avatar_url":"https://github.com/guardsman.png","language":"PHP","funding_links":["https://paypal.me/le6o/10"],"categories":[],"sub_categories":[],"readme":"# Guardsman :guardsman:\n\n![travis](https://travis-ci.org/guardsman/guardsman.svg)\n\nA guard clause assertion library to enforce parameter preconditions.\n\nThis provides a framework free, simple, chainable api for method parameter validation that throws\nexceptions on failure.\n\nIt is not intended as a validation library for end user input. If this is your use case then you should\ntry one of these [validation libraries](https://packagist.org/search/?q=validation) instead.\n\n## Installation\n\n```bash\ncomposer require guardsman/guardsman\n```\n\n## Example Usage\n\n```php\npublic function rename($name) {\n    \\Guardsman\\check($name)\n        -\u003eisString()\n        -\u003eisNotEmpty();\n\n    …\n}\n```\n\n```php\npublic function setSeconds($seconds) {\n    \\Guardsman\\check($seconds)\n        -\u003eisInteger()\n        -\u003eisGreaterThanOrEqualTo(0)\n        -\u003eisLessThan(60);\n\n    …\n}\n```\n\n```php\npublic function changeStatus($status) {\n    \\Guardsman\\check($status)\n        -\u003eisValueOf(self::validStatuses);\n\n    …\n}\n```\n\n## Preconditions\n\n### Array\n\n```php\n\\Guardsman\\check($subject)-\u003eisValueOf(array $array);\n\\Guardsman\\check($subject)-\u003eisNotValueOf(array $array);\n\\Guardsman\\check($subject)-\u003eisKeyOf(array $array);\n\\Guardsman\\check($subject)-\u003eisNotKeyOf(array $array);\n```\n\n### DateTime\n\n*Methods will first check that the subject is an instance of `\\DateTimeInterface`*\n\n```php\n\\Guardsman\\check($subject)-\u003eisBefore(\\DateTimeInterface $limit);\n\\Guardsman\\check($subject)-\u003eisBeforeOrEqualTo(\\DateTimeInterface $limit);\n\\Guardsman\\check($subject)-\u003eisAfter(\\DateTimeInterface $limit);\n\\Guardsman\\check($subject)-\u003eisAfterOrEqualTo(\\DateTimeInterface $limit);\n```\n\n### Empty\n\n```php\n\\Guardsman\\check($subject)-\u003eisNotEmpty();\n```\n\n### Number\n\n*Methods that accept a limit will first check that the subject is numeric.*\n*Limits will then be checked to ensure they are numeric and positive.*\n\n```php\n\\Guardsman\\check($subject)-\u003eisNumeric();\n\\Guardsman\\check($subject)-\u003eisInteger();\n\\Guardsman\\check($subject)-\u003eisFloat();\n\\Guardsman\\check($subject)-\u003eisGreaterThan($limit);\n\\Guardsman\\check($subject)-\u003eisGreaterThanOrEqualTo($limit);\n\\Guardsman\\check($subject)-\u003eisLessThan($limit);\n\\Guardsman\\check($subject)-\u003eisLessThanOrEqualTo($limit);\n\\Guardsman\\check($subject)-\u003eisPositive();\n\\Guardsman\\check($subject)-\u003eisNegative();\n```\n\n### String\n\n*Methods that accept a limit will first check that the subject is a string and that the encoding matches mb_internal_encoding*\n*Limits will then be checked to ensure they are numeric and positive.*\n\n```php\n\\Guardsman\\check($subject)-\u003eisString();\n\\Guardsman\\check($subject)-\u003eisShorterThan($limit);\n\\Guardsman\\check($subject)-\u003eisShorterThanOrEqualTo($limit);\n\\Guardsman\\check($subject)-\u003eisLongerThan($limit);\n\\Guardsman\\check($subject)-\u003eisLongerThanOrEqualTo($limit);\n\\Guardsman\\check($subject)-\u003ematchesRegex($pattern);\n```\n\n## Extending Guardsman\n\nSimply extend the Guardsman class with your own methods and create a check function under your namespace.\n\nsrc\\Your\\Namespace\\SuperGuard.php\n\n```php\nnamespace Your\\Namespace;\n\nclass SuperGuard extends \\Guardsman\\Guardsman\n{\n    public function isYourPreconditionMethod()\n    {\n        …\n    }\n}\n```\n\nsrc\\Your\\Namespace\\check.php\n\n```php\nnamespace Your\\Namespace;\n\nfunction check($subject)\n{\n    return new SuperGuard($subject);\n}\n\n```\n\ncomposer.json\n\n```\n    \"autoload\": {\n        \"files\": [\"src/Your/Namespace/check.php\"]\n    }\n```\n\nUsage:\n\n```php\n\\Your\\Namespace\\check($subject)-\u003eisYourPreconditionMethod();\n```\n\n### Show Thanks\n\nIf you find this useful then please show your thanks with [a small donation](https://paypal.me/le6o/10).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguardsman%2Fguardsman","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguardsman%2Fguardsman","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguardsman%2Fguardsman/lists"}