{"action":"created","issue":{"url":"https://api.github.com/repos/GrahamCampbell/Laravel-Exceptions/issues/7","labels_url":"https://api.github.com/repos/GrahamCampbell/Laravel-Exceptions/issues/7/labels{/name}","comments_url":"https://api.github.com/repos/GrahamCampbell/Laravel-Exceptions/issues/7/comments","events_url":"https://api.github.com/repos/GrahamCampbell/Laravel-Exceptions/issues/7/events","html_url":"https://github.com/GrahamCampbell/Laravel-Exceptions/issues/7","id":78481378,"number":7,"title":"Proposal Custom Displayers","user":{"login":"vinkla","id":499192,"avatar_url":"https://avatars.githubusercontent.com/u/499192?v=3","gravatar_id":"","url":"https://api.github.com/users/vinkla","html_url":"https://github.com/vinkla","followers_url":"https://api.github.com/users/vinkla/followers","following_url":"https://api.github.com/users/vinkla/following{/other_user}","gists_url":"https://api.github.com/users/vinkla/gists{/gist_id}","starred_url":"https://api.github.com/users/vinkla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vinkla/subscriptions","organizations_url":"https://api.github.com/users/vinkla/orgs","repos_url":"https://api.github.com/users/vinkla/repos","events_url":"https://api.github.com/users/vinkla/events{/privacy}","received_events_url":"https://api.github.com/users/vinkla/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-05-20T11:12:40Z","updated_at":"2015-05-20T11:15:15Z","closed_at":null,"body":"I would really like to see custom displayers and the ability to customize the existing ones. My idea is to create a configuration file with all displayers that should be loaded as well as a default one. The configuration file would look something like to this:\r\n\r\n```php\r\n/*\r\n|--------------------------------------------------------------------------\r\n| Default Exception Displayer\r\n|--------------------------------------------------------------------------\r\n|\r\n| Here you may specify which of the exception displayers below you wish to\r\n| use as your default displayer for all exceptions.\r\n|\r\n*/\r\n\r\n'default' => 'plain',\r\n\r\n/*\r\n|--------------------------------------------------------------------------\r\n| Exception Displayers\r\n|--------------------------------------------------------------------------\r\n|\r\n| Here are each of the exception displayers setup for your application.\r\n| Default displayers has been included, but you may add as many displayers\r\n| as you would like.\r\n|\r\n*/\r\n\r\n'displayers' => [\r\n    'array' => 'GrahamCampbell\\Exceptions\\Displayers\\ArrayDisplayer',\r\n    'debug' => 'GrahamCampbell\\Exceptions\\Displayers\\DebugDisplayer',\r\n    'plain' => 'GrahamCampbell\\Exceptions\\Displayers\\PlainDisplayer',\r\n],\r\n```\r\n\r\nEach displayer class should have a class that we can call to determine if this displayer should be used or not. Currently named it `use`, there probably is a much better name.\r\n```php\r\n/**\r\n * This is the array displayer class.\r\n *\r\n * @author Graham Campbell <graham@mineuk.com>\r\n */\r\nclass ArrayDisplayer implements DisplayerInterface\r\n{\r\n    /**\r\n     * Get the content associated with the given exception.\r\n     *\r\n     * @param \\Exception $exception\r\n     * @param int        $code\r\n     *\r\n     * @return array\r\n     */\r\n    public function display(Exception $exception, $code)\r\n    {\r\n        $info = ExceptionInfo::generate($code, $exception->getMessage());\r\n        \r\n        return ['success' => false, 'code' => $info['code'], 'msg' => $info['extra']];\r\n    }\r\n    \r\n    /**\r\n     * The method to decide if this displayer should be used or not.\r\n     *\r\n     * @param \\Exception               $exception\r\n     * @param \\Illuminate\\Http\\Request $request\r\n     *\r\n     * @return bool\r\n     */\r\n    public function use(Exception $exception, Request $request)\r\n    {\r\n      \treturn $request->ajax();\r\n    }\r\n}\r\n```\r\n\r\nThen at last the `getContent` method in the `ExceptionHandler` class loops over the displayers specified in the configuration file and then sees which one to use. In this way we won't break any current setup. You wont have to publish the configuration if you don't want to.\r\n\r\nWhat do you think @GrahamCampbell? Is this solution too complex?"},"comment":{"url":"https://api.github.com/repos/GrahamCampbell/Laravel-Exceptions/issues/comments/103846532","html_url":"https://github.com/GrahamCampbell/Laravel-Exceptions/issues/7#issuecomment-103846532","issue_url":"https://api.github.com/repos/GrahamCampbell/Laravel-Exceptions/issues/7","id":103846532,"user":{"login":"vinkla","id":499192,"avatar_url":"https://avatars.githubusercontent.com/u/499192?v=3","gravatar_id":"","url":"https://api.github.com/users/vinkla","html_url":"https://github.com/vinkla","followers_url":"https://api.github.com/users/vinkla/followers","following_url":"https://api.github.com/users/vinkla/following{/other_user}","gists_url":"https://api.github.com/users/vinkla/gists{/gist_id}","starred_url":"https://api.github.com/users/vinkla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vinkla/subscriptions","organizations_url":"https://api.github.com/users/vinkla/orgs","repos_url":"https://api.github.com/users/vinkla/repos","events_url":"https://api.github.com/users/vinkla/events{/privacy}","received_events_url":"https://api.github.com/users/vinkla/received_events","type":"User","site_admin":false},"created_at":"2015-05-20T11:15:15Z","updated_at":"2015-05-20T11:15:15Z","body":"Awesome! Then I'll try to work something out. Soon available in a pull request near you :)"}}