{"id":20917450,"url":"https://github.com/wamphlett/input-collection","last_synced_at":"2026-05-27T18:31:31.372Z","repository":{"id":144501981,"uuid":"243639464","full_name":"wamphlett/input-collection","owner":"wamphlett","description":"A smarter and stricter way to capture and validate request data","archived":false,"fork":false,"pushed_at":"2020-02-28T00:48:53.000Z","size":6,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-12T21:36:49.961Z","etag":null,"topics":["data","dto","forms","php","validation"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wamphlett.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2020-02-27T23:42:48.000Z","updated_at":"2022-11-08T18:04:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"850bb76b-b390-4719-82b3-e7a93adbfbff","html_url":"https://github.com/wamphlett/input-collection","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/wamphlett/input-collection","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wamphlett%2Finput-collection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wamphlett%2Finput-collection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wamphlett%2Finput-collection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wamphlett%2Finput-collection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wamphlett","download_url":"https://codeload.github.com/wamphlett/input-collection/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wamphlett%2Finput-collection/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33579665,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-27T02:00:06.184Z","response_time":53,"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":["data","dto","forms","php","validation"],"created_at":"2024-11-18T16:33:21.046Z","updated_at":"2026-05-27T18:31:31.357Z","avatar_url":"https://github.com/wamphlett.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Input Collection\n\n## Usage\nCollections are filled by being passed through the Collector with an array of data, this usually come from your request. See more about [Collections](#collections). If any of the values in the collection fail validaton, a `CollectionValidationException` is thrown otherwise a filled instance of the collection is returned and deemed valid.\n\n```php\nuse App\\Http\\InputCollections\\CreateUser;\nuse InputCollection\\Collector;\nuse InputCollection\\Exceptions\\CollectionValidationException;\n\n$requestData = [\n\t'name' =\u003e 'Joe Bloggs',\n\t'age'  =\u003e '20',\n];\n\ntry {\n\t$collection = Collector::collect(new CreateUser, $requestData);\n} (CollectionValidationException $e) {\n\t// Handle exception\n}\n\n$name = $collection-\u003egetName();\n$email = $collection-\u003egetAge();\n```\n\n## Collections\nCollections are definitions of expected payloads. Each collection must define a set of expected inputs and how to validate those inputs upon collection. Every defined input **must** have a protected property with the same name on the collection, faliure to do this will result in an exception when the collection is instantiated. You can define inputs in 3 seperate arrays, `required`, `requireOne` or `optional`.\n\nOnce a collection has been run through the collector, if no exception was thrown, your collection is deemed valid and can safely be passed around your application using the defined getters to access the data.\n\n```php\nnamespace App\\Http\\InputCollections;\n\nuse InputCollection\\Collection;\nuse InputCollection\\Values\\Email;\nuse InputCollection\\Values\\Text;\n\nclass CreateUser extends Collection\n{\n\t/** @var string */\n\tprotected $name;\n\n\t/** @var int */\n\tprotected $age;\n\n\tprotected $required = [\n\t\t'name' =\u003e Text::class,\n\t\t'age'  =\u003e Number::class,\n\t];\n\n\tpublic function getName(): string\n\t{\n\t\treturn $this-\u003ename;\n\t}\n\n\tpublic function getAge(): int\n\t{\n\t\treturn $this-\u003eage;\n\t}\n}\n```\n\n## Values\nValues are definitions designed to validate the incomming data. If a value does not pass validiton, it will throw a `CollectionInputValueException`. \n\n### Custom values\nYou can create your own custom values to cover bespoke use cases. Each value must carry out it's validation in the `__construct` method, must implement `\\InputCollection\\Contracts\\Value` and must throw a `CollectionInputValueException` when the value is deemed invalid.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwamphlett%2Finput-collection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwamphlett%2Finput-collection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwamphlett%2Finput-collection/lists"}