{"id":18832638,"url":"https://github.com/datto/php-json-rpc-validator","last_synced_at":"2025-04-14T04:31:01.069Z","repository":{"id":56963140,"uuid":"47975916","full_name":"datto/php-json-rpc-validator","owner":"datto","description":"Validation extension for the JSON-RPC library ","archived":false,"fork":false,"pushed_at":"2017-12-19T16:10:23.000Z","size":24,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-27T18:21:28.484Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/datto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-14T13:12:31.000Z","updated_at":"2017-12-18T16:37:38.000Z","dependencies_parsed_at":"2022-08-21T08:20:56.535Z","dependency_job_id":null,"html_url":"https://github.com/datto/php-json-rpc-validator","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datto%2Fphp-json-rpc-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datto%2Fphp-json-rpc-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datto%2Fphp-json-rpc-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datto%2Fphp-json-rpc-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/datto","download_url":"https://codeload.github.com/datto/php-json-rpc-validator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248821664,"owners_count":21166925,"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":[],"created_at":"2024-11-08T01:58:35.393Z","updated_at":"2025-04-14T04:31:01.049Z","avatar_url":"https://github.com/datto.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSON-RPC Endpoint Validator Extension\n\nThis is an annotation-based validation extension for the [php-json-rpc](https://github.com/datto/php-json-rpc) library. It validates the JSON-RPC API endpoints against well-defined constraints, e.g. type checking, regex checking, etc.\n\nThe library depends on [symfony/Validator](https://github.com/symfony/Validator), [doctrine/annotations](https://github.com/doctrine/annotations) as well as on [php-json-rpc-simple](https://github.com/datto/php-json-rpc-simple). \n\nExamples\n--------\nAnnotate your API endpoint classes like this:\n\n```php\nnamespace Datto\\API;\n\nuse Datto\\JsonRpc\\Validator\\Validate;\nuse Symfony\\Component\\Validator\\Constraints as Assert;\n\nclass Math\n{\n    /**\n     * @Validate(fields={\n     *   \"a\" = @Assert\\Type(type=\"integer\"),\n     *   \"b\" = {\n     *     @Assert\\Type(type=\"integer\"),\n     *     @Assert\\NotEqualTo(value=\"0\"),\n     *   }\n     * })\n     */\n    public function divide($a, $b)\n    {\n        return $a / $b;\n    }\n```\n\nOnce you have that, just use it like this. This example uses the `Simple\\Evaluator` (see [php-json-rpc-simple](https://github.com/datto/php-json-rpc-simple)) as underlying mapping mechanism:\n\n```php\n$server = new Server(new Validator\\Evaluator(new Simple\\Evaluator()));\n$result = $server-\u003ereply('{\"jsonrpc\": \"2.0\", \"method\": \"math/divide\", \"params\": { \"a\": 1, \"b\": 0 }, \"id\": 1}');\n\n// Because 'b' cannot be 0, this will return\n// {\"jsonrpc\":\"2.0\",\"id\":1,\"error\":{\"code\":-32602,\"message\":\"Invalid params\"}}\n```\n\nRequirements\n------------\n* PHP \u003e= 5.3\n\nInstallation\n------------\n```javascript\n\"require\": {\n  \"datto/json-rpc-validator\": \"~2.0\"\n}\n```   \n\nLicense\n-------\nThis package is released under an open-source license: [LGPL-3.0](https://www.gnu.org/licenses/lgpl-3.0.html).\n\nAuthor\n------\nWritten by [Philipp C. Heckel](https://github.com/binwiederhier).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatto%2Fphp-json-rpc-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdatto%2Fphp-json-rpc-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatto%2Fphp-json-rpc-validator/lists"}