-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
using html format throws error on dump() directives not inside a controller #9
Comments
Maybe we should just extend Symfonys HtmlDescriptor and create our own that works with this too? |
@mpociot I’d be happy to check it out this week probably Monday or Tuesday |
If you have not already looked into it, I tinkered a bit with it today. Here is the result: https://github.com/mattlibera/laravel-dump-server/tree/implement-htmldescriptor To extend Symfony's HtmlDescriptor requires us to re-implement most everything in the class, as much of it is private. It also may require us to pull in our own version of their Resources (js and css). That is what I have done in the fork above. We could also refer to Symfony's copies of those files ( @mpociot I just wanted to run this by you, to see how you feel about having to maintain basically your own copy of the HtmlDescriptor files, not just the PHP class, but also the assets. Feel free to comment and I can tweak things, or if @paulredmond is already working on his own fix, I can stand down :) |
I am wondering your thoughts on this... Closure routes aren't a good idea if you want to support This is the only line that will need to change: if ($request['controller']) {
$controller = "<span class='dumped-tag'>{$this->dumper->dump($request['controller'], true, array('maxDepth' => 0))}</span>";
} And later in the $tags = array_filter(array(
'controller' => $controller ?? null,
'project dir' => $projectDir ?? null,
)); |
After more digging I think we can work through this by updating the I'll open another PR and we can work through it style-wise @mpociot so you're happy with the method in which we check if it's a closure. |
Check to see if the controller isn't defined and set it as the route's closure. The check uses the same logic as the `Route` class to determine if the route defines a controller action. Fixes beyondcode#9
Yes, this solution feels much more "right" to me. I hadn't even looked at that file! Thanks for taking time to look at this, even though in practice it probably won't be encountered too much (I agree re: closure routes). I just know I got tripped up when the HTML output blew up with the example from the README. And, thanks to you both for your innumerable contributions to the Laravel community! |
Awesome, I’m glad we could figure it out with a simple tweak 👍 |
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 yourroutes/web.php
file).Sample case I used was the one from the README file. Running
php artisan dump-server
worked fine, but when runningphp artisan dump-server --format=html
the result is aFatalThrowableError
:After looking into some of the code, it seems that this is an inconsistency in the
describe()
method betweenCliDescriptor
andHtmlDescriptor
. See below -CliDescriptor
checks to see if the$request
contains acontroller
index before invoking thedump()
method to output the controller name, whereasHtmlDescriptor
does not:I was able to get around this in a very hacky way by modifying
DumpServerCommand
, lines 69-71 to be as follows:To 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.
Thoughts? 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?The text was updated successfully, but these errors were encountered: