{"id":23359784,"url":"https://github.com/firehed/input","last_synced_at":"2025-04-10T10:32:06.417Z","repository":{"id":47154624,"uuid":"41769048","full_name":"Firehed/input","owner":"Firehed","description":"PHP Input Handling","archived":false,"fork":false,"pushed_at":"2024-09-19T22:50:42.000Z","size":113,"stargazers_count":2,"open_issues_count":6,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-08T13:44:57.177Z","etag":null,"topics":["framework","input","php","php-framework","php-validation","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/Firehed.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2015-09-01T23:42:02.000Z","updated_at":"2023-10-10T04:12:28.000Z","dependencies_parsed_at":"2024-12-21T11:12:43.148Z","dependency_job_id":"ef14893e-cfba-4112-9cb3-8ade5a4ecee4","html_url":"https://github.com/Firehed/input","commit_stats":{"total_commits":44,"total_committers":2,"mean_commits":22.0,"dds":"0.31818181818181823","last_synced_commit":"66f952aecfe6563a0ea8140287d808849fced128"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Firehed%2Finput","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Firehed%2Finput/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Firehed%2Finput/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Firehed%2Finput/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Firehed","download_url":"https://codeload.github.com/Firehed/input/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248199136,"owners_count":21063641,"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":["framework","input","php","php-framework","php-validation","validation"],"created_at":"2024-12-21T11:11:57.907Z","updated_at":"2025-04-10T10:32:06.396Z","avatar_url":"https://github.com/Firehed.png","language":"PHP","readme":"Input\n=====\nAn input validation framework with a boring name\n\n[![Test](https://github.com/Firehed/input/actions/workflows/test.yml/badge.svg)](https://github.com/Firehed/input/actions/workflows/test.yml)\n[![Static analysis](https://github.com/Firehed/input/actions/workflows/static-analysis.yml/badge.svg)](https://github.com/Firehed/input/actions/workflows/static-analysis.yml)\n[![Lint](https://github.com/Firehed/input/actions/workflows/lint.yml/badge.svg)](https://github.com/Firehed/input/actions/workflows/lint.yml)\n[![codecov](https://codecov.io/gh/Firehed/input/branch/master/graph/badge.svg?token=gTzlnli3QV)](https://codecov.io/gh/Firehed/input)\n\n[Changelog](CHANGELOG.md)\n\nConcept\n-----\nInput validation is an important task in any web application, but remains an\nextremely tedious task.  This replaces intermingled checks with a proper data\nstructure that clearly defines the required and optional inputs.\n\nThe design reolves around the idea of API-driven design, where each API\nendpoint is its own object, however does not explicitly require this format\n- it is capable of validating for any object that defines the input\nrequirements. What it cannot easily handle is the common pattern of large\ncontrolelrs that are respnsible for many URLs, since each URL has its own\nvalidation requirements. It's certainly possible to structure your code in\na way to make this work, but that is liable to become more complicated than the\nbenefit it provides.\n\n\nData handling steps\n-----\nRaw input is transformed into safe data in two primary steps:\n\n* Parsing\n* Validation\n\nParsing is responsible for transforming the raw input string into an associative\narray. If your application is structured to do so, this step can be skipped\nentirely.\n\nValidation is the most useful part of the library - taking a defined set of\noptional and required parameters and their types, and comparing the input\nvalues to the spec. The implementation prevents invalid data from being\npropagated entirely; it is not possible to create a `SafeInput` object (which\nyour application will use) from invalid data!\n\nUpon completion of this process, a `SafeInput` object is returned that contains\ndata in accordance with the spec defined by the object implementing\n`ValidationInterface` (missing optional values are null).\n\nBecause this library exists to provide trustable data, it will actively prevent\nyou from second-guessing it; for example, using `isset` or `empty` on the data\nstructure will throw an exception. It is the author's experience that acting\nunable to trust your validated data is an anti-pattern and a code smell; if you\ninsist on doing so, this is not the right tool for you. Forcing trust like this\ntends to prevent documentation from driting apart from reality.\n\nExample\n-----\n\nA basic example follows:\n\n`some_controller_file.php`\n\n```php\n\u003c?php\n// This would be in its own file\nuse Firehed\\Input\\Interfaces\\ValidationInterface;\n\nuse Firehed\\Input\\Containers\\SafeInput;\nuse Firehed\\Input\\Objects as O;\nclass Endpoint\n    implements ValidationInterface {\n\n    public function getOptionalInputs() {\n        return [\n            'bar' =\u003e new O\\Text(),\n            'baz' =\u003e (new O\\Text())-\u003esetDefaultValue('my baz'),\n        ];\n    }\n\n    public function getRequiredInputs() {\n        return [\n            'foo' =\u003e new O\\Text(),\n        ];\n    }\n\n    public function execute(SafeInput $i) {\n        // ... do some magic\n        // $i['foo'] will be a string\n        // $i['bar'] will be a string or null, since it was optional\n        // $i['baz'] will be a string or 'my baz', since it was an optional with a default value\n    }\n}\n```\n\n`index.php`\n\n```php\n\u003c?php\n// This is the core of your Front Controller\n\nuse Firehed\\Input\\Containers\\RawInput;\nuse Firehed\\Input\\Parsers\\URLEncoded;\n\n// The endpoint should be detrmined by your router\n$endpoint = new Endpoint();\n\n// The parser should be determined by the Content-Type header\n$parser = new URLEncoded();\n\n\ntry {\n    $input = (new RawInput(\"foo=world\"))\n        -\u003eparse($parser)\n        -\u003evalidate($endpoint);\n    $endpoint-\u003eexecute($input);\n} catch (Firehed\\Input\\Exceptions\\InputException $e) {\n    // The input contained invalid data\n} catch (Exception $e) {\n    // Do any logging, error responses, etc.\n    echo $e;\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirehed%2Finput","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffirehed%2Finput","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffirehed%2Finput/lists"}