{"id":36620711,"url":"https://github.com/philiagus/parser","last_synced_at":"2026-01-12T09:22:22.574Z","repository":{"id":49687011,"uuid":"95036329","full_name":"philiagus/parser","owner":"philiagus","description":"PHP converter classes for asserting, parsing and converting of inputs.","archived":false,"fork":false,"pushed_at":"2025-07-28T18:27:43.000Z","size":440,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-02T10:45:10.825Z","etag":null,"topics":["composer-package","extract","parser","php","sanitize"],"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/philiagus.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,"zenodo":null}},"created_at":"2017-06-21T18:55:40.000Z","updated_at":"2025-07-28T18:27:47.000Z","dependencies_parsed_at":"2024-02-10T16:42:07.814Z","dependency_job_id":"da7d4e85-c490-419b-b316-c9cd54d3fda3","html_url":"https://github.com/philiagus/parser","commit_stats":{"total_commits":54,"total_committers":1,"mean_commits":54.0,"dds":0.0,"last_synced_commit":"899a0f795352061a3360d3b23e5d2ea97609bbba"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/philiagus/parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philiagus%2Fparser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philiagus%2Fparser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philiagus%2Fparser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philiagus%2Fparser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/philiagus","download_url":"https://codeload.github.com/philiagus/parser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/philiagus%2Fparser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28337689,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T06:09:07.588Z","status":"ssl_error","status_checked_at":"2026-01-12T06:05:18.301Z","response_time":98,"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":["composer-package","extract","parser","php","sanitize"],"created_at":"2026-01-12T09:22:21.863Z","updated_at":"2026-01-12T09:22:22.565Z","avatar_url":"https://github.com/philiagus.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# philiagus/parser\n\nPHP classes to assert, convert and parse data.\n\n# Is it tested?\n\nTested on the following PHP Version:\n\n- PHP8.3\n\n100% test covered. Test coverage generated on PHP8.3\n\n## Why do I need it?\n\nMaking sure your inputs are what they should be is one of the core principles of secure coding.\n\nObviously there are more, but we must tackle them one step at a time.\n\nThe basic idea of the parsers is, that the developer defines a structure through code and later throws a set of data\nagainst it. The parsers make sure, that the data is following the rules of defined in the structure.\n\n## How does it work?\n\nA more in depth documentation and tutorials on how to write own parsers can be found [here](doc/index.md).\n\nA simple example to assert that a provided value lies within defined boundaries:\n\n```php\n\u003c?php\nuse Philiagus\\Parser\\Base\\Subject;\nuse Philiagus\\Parser\\Parser\\Assert\\AssertInteger;\n\n$integer = 100;\n\n$parsingResult = AssertInteger::range(0, 100)\n    -\u003eparse(Subject::default($integer))\n    -\u003egetValue();\n\n// or, also possible:\nAssertInteger::range(0, 100)\n    -\u003ethenAssignTo($target)\n    -\u003eparse(Subject::default($integer))\n    -\u003egetValue();\n```\n\nThe real fun begins, when you start stacking parsers into one another:\n\n```php\n\u003c?php\nuse Philiagus\\Parser\\Base\\Subject;\nuse Philiagus\\Parser\\Parser\\Assert\\AssertFloat;\nuse Philiagus\\Parser\\Parser\\Assert\\AssertInteger;\nuse Philiagus\\Parser\\Parser\\Logic\\OneOf;\nuse Philiagus\\Parser\\Parser\\Parse\\ParseArray;\n\n$input = [\n    1, 1.0, 2, 4, 4.20\n];\n\n$integers = [];\n$floats = [];\n\nParseArray::new()\n    -\u003eassertSequentialKeys()\n    -\u003egiveEachValue(\n        OneOf::new()\n            -\u003eparser(\n                AssertInteger::minimum(0)\n                    -\u003ethenAppendTo($integers),\n                AssertFloat::minimum(0.0)\n                    -\u003ethenAppendTo($floats)\n            )\n    )\n-\u003eparse(Subject::default($input));\n\n// $integers will contain [1, 2, 4]\n// $floats will contain [1.0, 4.20]\n\n```\n\nLet's say: You have an API which receives requests from a client in JSON format, and you need to find the relevant information.\n\n```php\n\u003c?php\nuse Philiagus\\Parser\\Base\\Subject;\nuse Philiagus\\Parser\\Parser\\Assert\\AssertInteger;\nuse Philiagus\\Parser\\Parser\\Assert\\AssertStdClass;\nuse Philiagus\\Parser\\Parser\\Assert\\AssertStringMultibyte;\nuse Philiagus\\Parser\\Parser\\Convert\\ConvertToDateTime;\nuse Philiagus\\Parser\\Parser\\Parse\\ParseJSONString;\n\n$sourceValue = '{\"name\":\"Frank Herbert\",\"birthday\":\"1920-10-08\"}';\n\n$parser = ParseJSONString::new()\n    -\u003ethen(\n        AssertStdClass::new()\n            -\u003egivePropertyValue(\n                'name',\n                AssertStringMultibyte::UTF8()\n                    -\u003egiveLength(\n                        AssertInteger::new()\n                            -\u003eassertMinimum(1)\n                            -\u003eassertMaximum(64)\n                    )\n                    -\u003ethenAssignTo($name)\n            )\n            -\u003egivePropertyValue(\n                'birthday',\n                ConvertToDateTime::fromSourceFormat(\n                    '!Y-m-d', new \\DateTimeZone('UTC'),\n                    'The provided birthday is not a valid date'\n                )\n                    -\u003esetTimezone(new \\DateTimeZone('UTC'))\n                    -\u003ethenAssignTo($birthday)\n            )\n    );\n    \n$result = $parser-\u003eparse(Subject::default($sourceValue, 'Input', false));\n\nif ($result-\u003ehasErrors()) {\n    foreach ($result-\u003egetErrors() as $error) {\n        echo $error-\u003egetPathAsString(), ': ', $error-\u003egetMessage(), PHP_EOL;\n    }\n    exit;\n}\n\n$today = new \\DateTime();\n$delta = $today-\u003ediff($birthday);\nif ($today \u003c $birthday) {\n    echo \"$name will be born in \", $delta-\u003ey, \" years\", PHP_EOL;\n} else {\n    echo \"$name was born \", $delta-\u003ey, \" years ago\", PHP_EOL;\n}\n```\n\nIf you execute this code the result will be `Frank herbert was born 101 years ago` (at least on the date of this typing).\n\nWould you change the input to `{\"name\":123,\"birthday\":\"1920-10-0f\"}`, the result would be:\n```text\nInput.name: Provided value is not of type string\nInput.birthday: The provided birthday is not a valid date\n```\n\n## What if something is missing?\n\nFear not! All parsers implement `Philiagus\\Parser\\Contract\\Parser`, so you can easily write your own to fit your specific need. Check out `Philiagus\\Parser\\Base\\Parser` for a base class you can easily extend.\n\nSome hints:\n- If your parser validates a type (example: a parser the reads an XML, so non-strings are a no-go), the `Philiagus\\Parser\\Base\\OverwritableTypeErrorMessage`-Trait might help\n- The `Philiagus\\Parser\\Base\\Parser` already implements basic things such as chaining using `-\u003ethen($parser)` among other things, so you don't have to worry about that\n- If you need more control over the behaviour of the parser or just don't like the `ResultBuilder`, you only need to implement the `Philiagus\\Parser\\Contract\\Parser`-Interface to be interoperable with other parsers. Just be aware that you MUST\n  - create a `ParserBegin` subject when you enter the parser, wrapping the provided subject into another subject to ensure that the value chain is upheld\n  - respect the `throwOnError()` info of the subject: If an error occurs and `throwOnError()` is active, you have to throw the Error (most times using `$error-\u003ethrow()`). Accordingly, if `throwOnError()` is not active you have to add the Errors to the Result object.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphiliagus%2Fparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphiliagus%2Fparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphiliagus%2Fparser/lists"}