{"action":"created","issue":{"url":"https://api.github.com/repos/beyondcode/laravel-dump-server/issues/9","repository_url":"https://api.github.com/repos/beyondcode/laravel-dump-server","labels_url":"https://api.github.com/repos/beyondcode/laravel-dump-server/issues/9/labels{/name}","comments_url":"https://api.github.com/repos/beyondcode/laravel-dump-server/issues/9/comments","events_url":"https://api.github.com/repos/beyondcode/laravel-dump-server/issues/9/events","html_url":"https://github.com/beyondcode/laravel-dump-server/issues/9","id":340402625,"node_id":"MDU6SXNzdWUzNDA0MDI2MjU=","number":9,"title":"using html format throws error on dump() directives not inside a controller","user":{"login":"mattlibera","id":6657359,"node_id":"MDQ6VXNlcjY2NTczNTk=","avatar_url":"https://avatars2.githubusercontent.com/u/6657359?v=4","gravatar_id":"","url":"https://api.github.com/users/mattlibera","html_url":"https://github.com/mattlibera","followers_url":"https://api.github.com/users/mattlibera/followers","following_url":"https://api.github.com/users/mattlibera/following{/other_user}","gists_url":"https://api.github.com/users/mattlibera/gists{/gist_id}","starred_url":"https://api.github.com/users/mattlibera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattlibera/subscriptions","organizations_url":"https://api.github.com/users/mattlibera/orgs","repos_url":"https://api.github.com/users/mattlibera/repos","events_url":"https://api.github.com/users/mattlibera/events{/privacy}","received_events_url":"https://api.github.com/users/mattlibera/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-07-11T20:59:25Z","updated_at":"2018-07-16T21:59:50Z","closed_at":null,"author_association":"NONE","body":"At first I thought this was an overall problem with the HTML output, but after digging a bit discovered that this occurs only if running `dump()` directives when not inside a Controller (e.g. from within a closure inside of your `routes/web.php` file).\r\n\r\nSample case I used was the one from the README file. Running `php artisan dump-server` worked fine, but when running `php artisan dump-server --format=html` the result is a `FatalThrowableError`:\r\n\r\n```\r\n   Symfony\\Component\\Debug\\Exception\\FatalThrowableError  : Argument 1 passed to Symfony\\Component\\VarDumper\\Dumper\\HtmlDumper::dump() must be an instance of Symfony\\Component\\VarDumper\\Cloner\\Data, null given, called in /var/www/html/test-app/vendor/symfony/var-dumper/Command/Descriptor/HtmlDescriptor.php on line 47\r\n\r\n  at /var/www/html/test-app/vendor/symfony/var-dumper/Dumper/HtmlDumper.php:111\r\n    107| \r\n    108|     /**\r\n    109|      * {@inheritdoc}\r\n    110|      */\r\n  > 111|     public function dump(Data $data, $output = null, array $extraDisplayOptions = array())\r\n    112|     {\r\n    113|         $this->extraDisplayOptions = $extraDisplayOptions;\r\n    114|         $result = parent::dump($data, $output);\r\n    115|         $this->dumpId = 'sf-dump-'.mt_rand();\r\n\r\n  Exception trace:\r\n\r\n  1   Symfony\\Component\\VarDumper\\Dumper\\HtmlDumper::dump([])\r\n      /var/www/html/test-app/vendor/symfony/var-dumper/Command/Descriptor/HtmlDescriptor.php:47\r\n\r\n  2   Symfony\\Component\\VarDumper\\Command\\Descriptor\\HtmlDescriptor::describe(Object(Symfony\\Component\\Console\\Style\\SymfonyStyle), Object(Symfony\\Component\\VarDumper\\Cloner\\Data), [])\r\n      /var/www/html/test-app/vendor/beyondcode/laravel-dump-server/src/DumpServerCommand.php:70\r\n\r\n  3   BeyondCode\\DumpServer\\DumpServerCommand::BeyondCode\\DumpServer\\{closure}(Object(Symfony\\Component\\VarDumper\\Cloner\\Data), [])\r\n      /var/www/html/test-app/vendor/symfony/var-dumper/Server/DumpServer.php:76\r\n\r\n  4   Symfony\\Component\\VarDumper\\Server\\DumpServer::listen(Object(Closure))\r\n      /var/www/html/test-app/vendor/beyondcode/laravel-dump-server/src/DumpServerCommand.php:71\r\n\r\n  5   BeyondCode\\DumpServer\\DumpServerCommand::handle()\r\n      /var/www/html/test-app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:29\r\n\r\n  6   call_user_func_array([])\r\n      /var/www/html/test-app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:29\r\n\r\n  7   Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()\r\n      /var/www/html/test-app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:87\r\n\r\n  8   Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Object(Closure))\r\n      /var/www/html/test-app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:31\r\n\r\n  9   Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), [])\r\n      /var/www/html/test-app/vendor/laravel/framework/src/Illuminate/Container/Container.php:564\r\n\r\n  10  Illuminate\\Container\\Container::call()\r\n      /var/www/html/test-app/vendor/laravel/framework/src/Illuminate/Console/Command.php:184\r\n\r\n  11  Illuminate\\Console\\Command::execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))\r\n      /var/www/html/test-app/vendor/symfony/console/Command/Command.php:251\r\n\r\n  12  Symfony\\Component\\Console\\Command\\Command::run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))\r\n      /var/www/html/test-app/vendor/laravel/framework/src/Illuminate/Console/Command.php:171\r\n\r\n  13  Illuminate\\Console\\Command::run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))\r\n      /var/www/html/test-app/vendor/symfony/console/Application.php:886\r\n\r\n  14  Symfony\\Component\\Console\\Application::doRunCommand(Object(BeyondCode\\DumpServer\\DumpServerCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))\r\n      /var/www/html/test-app/vendor/symfony/console/Application.php:262\r\n\r\n  15  Symfony\\Component\\Console\\Application::doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))\r\n      /var/www/html/test-app/vendor/symfony/console/Application.php:145\r\n\r\n  16  Symfony\\Component\\Console\\Application::run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))\r\n      /var/www/html/test-app/vendor/laravel/framework/src/Illuminate/Console/Application.php:89\r\n\r\n  17  Illuminate\\Console\\Application::run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))\r\n      /var/www/html/test-app/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:122\r\n\r\n  18  Illuminate\\Foundation\\Console\\Kernel::handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))\r\n      /var/www/html/test-app/artisan:37\r\n```\r\n\r\nAfter looking into some of the code, it seems that this is an inconsistency in the `describe()` method between `CliDescriptor` and `HtmlDescriptor`. See below - `CliDescriptor` checks to see if the `$request` contains a `controller` index before invoking the `dump()` method to output the controller name, whereas `HtmlDescriptor` does not:\r\n\r\n```php\r\n// from Symfony\\Component\\VarDumper\\Command\\Descriptor\\CliDescriptor, line 51-53\r\nif ($controller = $request['controller']) {\r\n    $rows[] = array('controller', rtrim($this->dumper->dump($controller, true), \"\\n\"));\r\n}\r\n// from Symfony\\Component\\VarDumper\\Command\\Descriptor\\HtmlDescriptor, line 47\r\n$controller = \"<span class='dumped-tag'>{$this->dumper->dump($request['controller'], true, array('maxDepth' => 0))}</span>\";\r\n```\r\n\r\nI was able to get around this in a very hacky way by modifying `DumpServerCommand`, lines 69-71 to be as follows:\r\n\r\n```php\r\n$this->server->listen(function (Data $data, array $context, int $clientId) use ($descriptor, $io) {\r\n    // workaround for dumping html content when not within a controller\r\n    if (is_null($context['request']['controller'])) {\r\n        $context['request']['controller'] = new Data([\"-\"]);\r\n    }\r\n    $descriptor->describe($io, $data, $context, $clientId);\r\n });\r\n```\r\n\r\nTo me this is probably something that should be addressed within the Symfony var-dumper package, but I wanted to check with @mpociot to see if this workaround is something worth adding to this package, if temporarily.\r\n\r\nThoughts? Is there a different way to accomplish this that is a bit more elegant? Or, does it even matter - how many people will be `dump()`-ing things to HTML format from their routes file?"},"comment":{"url":"https://api.github.com/repos/beyondcode/laravel-dump-server/issues/comments/405394932","html_url":"https://github.com/beyondcode/laravel-dump-server/issues/9#issuecomment-405394932","issue_url":"https://api.github.com/repos/beyondcode/laravel-dump-server/issues/9","id":405394932,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNTM5NDkzMg==","user":{"login":"paulredmond","id":177773,"node_id":"MDQ6VXNlcjE3Nzc3Mw==","avatar_url":"https://avatars3.githubusercontent.com/u/177773?v=4","gravatar_id":"","url":"https://api.github.com/users/paulredmond","html_url":"https://github.com/paulredmond","followers_url":"https://api.github.com/users/paulredmond/followers","following_url":"https://api.github.com/users/paulredmond/following{/other_user}","gists_url":"https://api.github.com/users/paulredmond/gists{/gist_id}","starred_url":"https://api.github.com/users/paulredmond/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paulredmond/subscriptions","organizations_url":"https://api.github.com/users/paulredmond/orgs","repos_url":"https://api.github.com/users/paulredmond/repos","events_url":"https://api.github.com/users/paulredmond/events{/privacy}","received_events_url":"https://api.github.com/users/paulredmond/received_events","type":"User","site_admin":false},"created_at":"2018-07-16T21:59:50Z","updated_at":"2018-07-16T21:59:50Z","author_association":"CONTRIBUTOR","body":"I am wondering your thoughts on this...\r\n\r\nClosure routes aren't a good idea if you want to support `php artisan route:cache`, so perhaps we can leave as-is for now @mpociot and in the meantime send a PR to the Symfony team that checks for `$request['controller']` in the `HtmlDescriptor`.\r\n\r\nThis is the only line that will need to change:\r\n\r\n```php\r\nif ($request['controller']) {\r\n    $controller = \"<span class='dumped-tag'>{$this->dumper->dump($request['controller'], true, array('maxDepth' => 0))}</span>\";\r\n}\r\n```\r\n\r\nAnd later in the `HtmlDescriptor::describe()` there's a check for `$controller`:\r\n\r\n```php\r\n$tags = array_filter(array(\r\n    'controller' => $controller ?? null,\r\n    'project dir' => $projectDir ?? null,\r\n));\r\n```"}}
{"actor":{"display_login":"paulredmond"}}