8000 [WIP] var-dumper component by nicolas-grekas · Pull Request #4243 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

[WIP] var-dumper component #4243

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

Merged
merged 14 commits into from
Nov 5, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
§ about DebugBundle config
  • Loading branch information
nicolas-grekas committed Oct 30, 2014
commit 6a3e17088332f9dc499aa765fe6877584893b4d3
7 changes: 4 additions & 3 deletions components/var_dumper/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ Before dumping it, you can further limit the resulting
:class:`Symfony\\Component\\VarDumper\\Cloner\\Data` object by calling its
:method:`Symfony\\Component\\VarDumper\\Cloner\\Data::getLimitedClone`
method:
- the first `$maxDepth` argument allows limiting dumps in the depth dimension,
- the second `$maxItemsPerDepth` limits the number of items per depth level,
- and the last `$useRefHandles` defaults to `true` but allows removing internal

- the first ``$maxDepth`` argument allows limiting dumps in the depth dimension,
- the second ``$maxItemsPerDepth`` limits the number of items per depth level,
- and the last ``$useRefHandles`` defaults to ``true`` but allows removing internal
objects' handles for sparser output,
- but unlike the previous limits on cloners that remove data on purpose, these
limits can be changed back and forth before dumping since they do not affect
Expand Down
56 changes: 38 additions & 18 deletions components/var_dumper/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ You can install the component in 2 different ways:
The dump() function
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function should be capitialized

-------------------

The VarDumper component creates a global ``dump()`` function that is
configured out of the box: HTML or CLI output is automatically selected based
on the current PHP SAPI.

The advantages of this function are:
The VarDumper component creates a global ``dump()`` function that you can
use instead of e.g. :phpfunction:`var_dump`. By using it, you'll gain:

- per object and resource types specialized view to e.g. filter out
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

start with an uppercase letter

Doctrine internals while dumping a single proxy entity, or get more
Expand All @@ -47,44 +44,67 @@ You can change the behavior of this function by calling
:method:`VarDumper::setHandler($callable) <Symfony\\Component\\VarDumper\\VarDumper::setHandler>`:
calls to ``dump()`` will then be forwarded to ``$callable``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not relevant in an introduction. That's something for further usage (advanced).


Where does the output go?
-------------------------
Output format and destination
-----------------------------

If you read the advanced documentation, you'll learn how to change the
format or redirect the output to wherever you want.
If you read the `advanced documentation <advanced>`, you'll learn how to
change the format or redirect the output to wherever you want.

By default, these are selected based on your current PHP SAPI:

- on the command line (CLI SAPI), the output is written on `STDERR`. This
- on the command line (CLI SAPI), the output is written on ``STDERR``. This
can be surprising to some because this bypasses PHP's output buffering
mechanism. On the other hand, this give the possibility to easily split
mechanism. On the other hand, it give the possibility to easily split
dumps from regular output by using pipe redirection.
- on other SAPIs, dumps are written as HTML on the regular output.

DebugBundle and Twig integration
--------------------------------

The `DebugBundle` allows greater integration of the component into the
The ``DebugBundle`` allows greater integration of the component into the
Symfony full stack framework. It is enabled by default in the dev
environement of the standard edition since version 2.6.

Since generating (even debug) output in the controller or in the model
of your application may just break it by e.g. sending HTTP headers or
corrupting your view, the bundle configures the `dump()` function so that
corrupting your view, the bundle configures the ``dump()`` function so that
variables are dumped in the web debug toolbar.

But if the toolbar can not be displayed because you e.g. called `die`/`exit`
But if the toolbar can not be displayed because you e.g. called ``die``/``exit``
or a fatal error occurred, then dumps are written on the regular output.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the components section. We should move all Symfony framework related things (bundles, web dev toolbar, etc.) to a cookbook article in cookbook/debug.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm mixed on this: scattering won't help the reader. This is not unprecedented: many other components tell about their configuration parameters.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please give an example? Those should be fixed too. The component docs are purely meant for standalone usage

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, not much in fact. In routing/hostname_pattern.rst?


In a Twig template, two constructs are available for dumping a variable.
Choosing between both is generally only a matter of personal taste:
Choosing between both is mostly a matter of personal taste, still:

- `{% dump foo.bar %}` is the way to go when the original template output
- ``{% dump foo.bar %}`` is the way to go when the original template output
shall not be modified: variables are not dumped inline, but in the web
debug toolbar.
- on the contrary, `{{ dump(foo.bar) }}` dumps inline and thus may or not
- on the contrary, ``{{ dump(foo.bar) }}`` dumps inline and thus may or not
be suited to your use case (e.g. you shouldn't use it in an HTML
attribute or a `script` tag).
attribute or a ``<script>`` tag).

By default for nested variables, dumps are limited to a subset of their
original value. You can configure the limits in terms of:
- maximum number of items to dump,
- maximum string length before truncation.

.. configuration-block::

.. code-block:: yaml

debug:
max_items: 250
max_string_length: -1

.. code-block:: xml

<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/debug"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/debug http://symfony.com/schema/dic/debug/debug-1.0.xsd">

<config max-items="250" max-string-length="-1" />
</container>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is the components, configuration like this isn't available (this is about the bundle). We should document setMaxItems and setMaxString instead. However, there might be a better location then here. We should give a user examples first and then talk about all customization imo

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above: I'm mixed on this, other components already do it (and telling about setMaxItems & co. is for the advanced doc)


Reading a dump
--------------
Expand Down
0