-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Debug] Create a main guide for Debugging #7071
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5dc304c
Bootstrap main debugging guide
wouterj 4c065fd
Added the VarDumper to the debug/debugging page
hiddewie a92b746
Rewrote the VarDump section a bit
wouterj c015760
Added a section about interactive debugging tools
wouterj bb389ee
Moved the debug commands below again
wouterj 779983d
Fixes after great reviews
wouterj 758a9f7
Removed doc on load cache class
wouterj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,103 @@ | ||
Debugging | ||
========= | ||
.. index:: | ||
single: Debugging | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
:glob: | ||
How to Optimize Your Development Environment for Debugging | ||
========================================================== | ||
|
||
debug/* | ||
When you work on a Symfony project on your local machine, you should use the | ||
``dev`` environment (``app_dev.php`` front controller). This environment | ||
configuration is optimized for two main purposes: | ||
|
||
* Give the developer accurate feedback whenever something goes wrong (provided | ||
by the web debug toolbar, nice exception pages, profiler, ...); | ||
* Be as close as possible to the production environment to avoid problems when | ||
deploying the project. | ||
|
||
Using Interactive Debug Tools | ||
----------------------------- | ||
|
||
Interactive debug tools allow you to walk through the code step by step, | ||
making it easier to identify which step is causing problems. Symfony works | ||
with any PHP debug environment, among them: | ||
|
||
* `Xdebug`_, the most well-known PHP debugger; | ||
* `PsySH`_, a PHP `REPL`_ (Read-eval-print loop) debugger. Use the | ||
`FidryPsyshBundle`_ for a dedicated Symfony integration of PsySH. | ||
|
||
Dumping Variables with the VarDumper | ||
------------------------------------ | ||
|
||
To ease the debugging of a variable in your application, you can use the | ||
:doc:`VarDumper component </components/var_dumper>` to dump the content of a | ||
variable. The component provides the ``dump()`` function, an alternative to | ||
PHP's :phpfunction:`var_dump()` function:: | ||
|
||
// create a variable with a value | ||
$myVar = ...; | ||
|
||
// and dump it | ||
dump($myVar); | ||
|
||
The dumper is not limited to scalar values. Arrays and objects can also be | ||
visualized using the VarDumper. One of the most important advantages of using | ||
``dump()`` is a nicer and more specialized dump of objects (e.g. Doctrine | ||
internals are filtered out when dumping an entity proxy). | ||
|
||
If the dumper is used on a command line, the result is a formatted string. | ||
Otherwise, the result is a piece of HTML, which can be expanded to show nested | ||
structures in the dumped value. | ||
|
||
You can also dump values from inside templates: | ||
|
||
.. code-block:: html+twig | ||
|
||
{# dumps the variable inline as HTML #} | ||
{{ dump(myVar) }} | ||
|
||
{# dumps the variable to the web debug toolbar to not modify the template #} | ||
{% dump myVar %} | ||
|
||
Useful Debugging Commands | ||
------------------------- | ||
|
||
When developing a large application, it can be hard to keep track of all the | ||
different services, routes and translations. Luckily, Symfony has some commands | ||
that can help you visualize and find the information: | ||
|
||
``debug:container`` | ||
Displays information about the contents of the Symfony container for all public | ||
services. Append a service ID as an argument to find only those matching the ID. | ||
|
||
``debug:config`` | ||
Shows all configured bundles, their classes and their aliases. | ||
|
||
``debug:event-dispatcher`` | ||
Displays information about all the registered listeners in the event dispatcher. | ||
|
||
``debug:router`` | ||
Displays information about all configured routes in the application as a | ||
table with the name, method, scheme, host and path for each route. | ||
|
||
``router:match <path_info>`` | ||
Shows the route information matching the provided path info or an error if | ||
no route matches. | ||
|
||
``debug:translation <locale>`` | ||
Shows a table of the translation key, the domain, the translation and the | ||
fallback translation for all known messages if translations exist for | ||
the given locale. | ||
|
||
.. tip:: | ||
|
||
When in doubt how to use a console command, open the help section by | ||
appending the ``--help`` (``-h``) option. | ||
|
||
.. tip:: | ||
|
||
When in doubt how to use a console command, open the help section by | ||
appending the ``--help`` option. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ( |
||
|
||
.. _Xdebug: https://xdebug.org/ | ||
.. _PsySH: http://psysh.org/ | ||
.. _REPL: https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop | ||
.. _FidryPsyshBundle: https://github.com/theofidry/PsyshBundle |
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add a not on how to install it or a link for it, as IIRC, unless the application is booted and if you forget to add the
dump.php
file in yourcomposer.json
,dump()
won't workThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The section refers to the VarDumper component installation docs. I don't think we have to duplicate the info here.