{"action":"created","issue":{"url":"https://api.github.com/repos/laravel/framework/issues/15920","repository_url":"https://api.github.com/repos/laravel/framework","labels_url":"https://api.github.com/repos/laravel/framework/issues/15920/labels{/name}","comments_url":"https://api.github.com/repos/laravel/framework/issues/15920/comments","events_url":"https://api.github.com/repos/laravel/framework/issues/15920/events","html_url":"https://github.com/laravel/framework/pull/15920","id":183181303,"number":15920,"title":"[5.3] [WIP] Add a sanitizer","user":{"login":"phroggyy","id":7256451,"avatar_url":"https://avatars.githubusercontent.com/u/7256451?v=3","gravatar_id":"","url":"https://api.github.com/users/phroggyy","html_url":"https://github.com/phroggyy","followers_url":"https://api.github.com/users/phroggyy/followers","following_url":"https://api.github.com/users/phroggyy/following{/other_user}","gists_url":"https://api.github.com/users/phroggyy/gists{/gist_id}","starred_url":"https://api.github.com/users/phroggyy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phroggyy/subscriptions","organizations_url":"https://api.github.com/users/phroggyy/orgs","repos_url":"https://api.github.com/users/phroggyy/repos","events_url":"https://api.github.com/users/phroggyy/events{/privacy}","received_events_url":"https://api.github.com/users/phroggyy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-10-15T01:34:14Z","updated_at":"2016-10-15T22:08:10Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/laravel/framework/pulls/15920","html_url":"https://github.com/laravel/framework/pull/15920","diff_url":"https://github.com/laravel/framework/pull/15920.diff","patch_url":"https://github.com/laravel/framework/pull/15920.patch"},"body":"This PR aims to resolve #14467. I'm opening this PR now already to be able to take in feedback on functionality and usage. I have tried to keep this sanitiser as general purpose as I could. Right now, there is only a `Sanitizer` class but the idea is that the `FormRequest` will also have a more user-friendly access to it by simply return an array of sanitiser rules to apply. The current interface is this:\r\n\r\nRegister a globally available sanitizer:\r\n```\r\nSanitizer::register('name', function($name) {\r\n    return trim($name);\r\n});\r\n```\r\n\r\nAlias a custom sanitizer class (and optionally method):\r\n```\r\nSanitizer::alias('string', StringSanitizer::class);\r\n\r\nSanitizer::alias('name', StringSanitizer::class.'@sanitizeName');\r\n\r\nclass StringSanitizer {\r\n    /**\r\n     * The default sanitizer.\r\n     *\r\n     * @param  string  $string\r\n     * @return string\r\n     */\r\n    public function sanitize($string)\r\n    {\r\n        return trim($string);\r\n    }\r\n\r\n    /**\r\n     * A custom sanitizer.\r\n     *\r\n     * @param  string  $name\r\n     * @return string\r\n     */\r\n    public function sanitizeName($name)\r\n    {\r\n        return ucfirst($this->sanitize($name));\r\n    }\r\n}\r\n```\r\n\r\nFinally, to use the sanitiser:\r\n\r\n```\r\n$data = [\r\n    'first_name' => 'Taylor',\r\n];\r\n$rules = [\r\n    'first_name' => 'name',\r\n];\r\n$sanitizer = new Sanitizer($data, $rules);\r\n\r\n$sanitizedData = $sanitizer->sanitize();\r\n```\r\n\r\nTo-do:\r\n\r\n- [ ] Make data sanitization easily accessible through the `FormRequest`\r\n\r\nConsidered improvements\r\n\r\n- Allow applying a sanitizer to _every_ item of the array\r\n  - either through numeric key, or `*` as key\r\n- Allow applying a sanitizer to an array\r\n  - either supply just the array name (or `arrayName.*`, or individual items by dot notation `array.item`\r\n\r\n---\r\n\r\n**PLEASE NOTE: This PR is a work in progress and created early for input**"},"comment":{"url":"https://api.github.com/repos/laravel/framework/issues/comments/254014028","html_url":"https://github.com/laravel/framework/pull/15920#issuecomment-254014028","issue_url":"https://api.github.com/repos/laravel/framework/issues/15920","id":254014028,"user":{"login":"mdavis1982","id":199807,"avatar_url":"https://avatars.githubusercontent.com/u/199807?v=3","gravatar_id":"","url":"https://api.github.com/users/mdavis1982","html_url":"https://github.com/mdavis1982","followers_url":"https://api.github.com/users/mdavis1982/followers","following_url":"https://api.github.com/users/mdavis1982/following{/other_user}","gists_url":"https://api.github.com/users/mdavis1982/gists{/gist_id}","starred_url":"https://api.github.com/users/mdavis1982/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdavis1982/subscriptions","organizations_url":"https://api.github.com/users/mdavis1982/orgs","repos_url":"https://api.github.com/users/mdavis1982/repos","events_url":"https://api.github.com/users/mdavis1982/events{/privacy}","received_events_url":"https://api.github.com/users/mdavis1982/received_events","type":"User","site_admin":false},"created_at":"2016-10-15T22:08:10Z","updated_at":"2016-10-15T22:08:10Z","body":"I'm :+1: on this, especially when coupled with the enhancements to the `FormRequest` class."}}
{"actor":{"display_login":"mdavis1982"}}