Skip to content

[Var-Dumper] added feature to set default nodes collapsed #18148

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
wants to merge 11 commits into from
Closed

[Var-Dumper] added feature to set default nodes collapsed #18148

wants to merge 11 commits into from

Conversation

MGDSoft
Copy link
Contributor

@MGDSoft MGDSoft commented Mar 13, 2016

Q A
Branch master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #16741
License MIT
Doc PR

modify js htmldumper and add options variable to configure js

Code to test it

       $array = [
            'level 1',
            'level 1',
            ['level 2','level 2'],
            [['level 3'],['level 3']],
        ];

        $cloner = new VarCloner();
        $dumper = new HtmlDumper();

        VarDumper::setHandler(function ($var) use ($cloner, $dumper) {
            $dumper->dump($cloner->cloneVar($var));
        });

        // default (set to 1)
        dump($array);

        // all collapsed
        $dumper->setJsProperties( array('collapsedByDefaultNodesHigherThan' => 0 ));

        dump($array);

        $dumper->setJsProperties( array('collapsedByDefaultNodesHigherThan' => 3 ));

        dump($array);

@MGDSoft
Copy link
Contributor Author

MGDSoft commented Mar 13, 2016

I dont know why travis fails for php 5.6 && 7 and Its fine for 5.5 && hhvm. my code is 80% js

@nicolas-grekas
Copy link
Member

I understand the need but the current interface (method) is really tailored to one single use case.
What if now I want to expand key foo.bar.baz? Then should we add a new method for each way of collapsing/expanding we can think of? Is there a more generic solution?

@MGDSoft
Copy link
Contributor Author

MGDSoft commented Mar 16, 2016

I think it is the best generic solution.
If u want replace foo.bar.baz the steps are

  • add in array jsPropertiesDefault default Value like 'fooBarBaz' => 'hi'
  • in js where used replace hardcode value to var fooVar = options.fooBarBaz
  • To override default values call setJsProperties(['fooBarBaz' => 'bye!'])

@MGDSoft
Copy link
Contributor Author

MGDSoft commented Mar 17, 2016

ping @nicolas-grekas

@nicolas-grekas
Copy link
Member

I think its worth it. Here are a few suggestions:

I'd rename setJsProperties() to setDisplayOptions().
I'd add a third argument to dump(), called $displayOptions, that overwrites the default options when provided (and thus keep only one $this->displayOptions property, that holds the default config).
I'd then allow more display options. Dump limiting is controlled by a few more options, amongst them:

  1. maxItems: max total number of items to dump
  2. maxDepth: well, max depth
  3. maxItemsPerDepth: max number of items per depth level
  4. maxStringLength: max sumber of chars for strings
  5. maxStringWidth: max number of characters per line for strings

1. and 5. are not applicable, but 2., 3. and 4. could also exist to control default collapsing of elements in the browser. I'd keep the same wording (maxDepth instead of collapsedByDefaultNodesHigherThan, etc.).

WDYT?

@MGDSoft
Copy link
Contributor Author

MGDSoft commented Mar 18, 2016

Ey Nicolas thx for your reply!.

  • I think displayOptions var instead of (propertiesJs && propertiesJsDefault ) its perfect
  • Add displayOptions to HtmlDumper->dump() its ok and we can also add to VarDumper::dump() because it can be used for CliDumper (in the future?), isn't it?
  • maxItemsPerDepth and maxStringLength its ok, but maxDepth I think is ambiguos. It would be maxDepthByDefault or something like that.

I have a another question. Sorry if its a dumb question (is my 1º pullrequest here ...)
If I break a test like my pullrequest 62c6ab5 (build: https://travis-ci.org/symfony/symfony/builds/115623557 deps=high)
I think this test is looking for a bc breaks, because its executing in branch 3.0, and in my local machine all test are passed.

What is the process to correct or warn of this problem?
Thanks!

@nicolas-grekas
Copy link
Member

add to VarDumper::dump() because it can be used for CliDumper (in the future?)

This doesn't apply to CliDumper, because we are talking about collapsing options, which doesn't exist on the cli. We already handle these kind of limits (max depth) at the state extraction level, they are not exposed by the dump functions but could be one day (see #17290).

but maxDepth I think is ambiguos

that's the way it is now and changing it would be a bc break, no way to change :)

If I break a test

We'll look at them once the feature is ready, but the fix usually is to raise the lowest required versions in the composer.json file of the failing components (at least for the deps=low matrix line).

Sfdump = window.Sfdump || (function (doc) {

var defaultOptions = '.json_encode($this->jsPropertiesDefault).';
Copy link
Member

Choose a reason for hiding this comment

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

since the actual max depth is provided as argument to the Sfdump function, there is no need to put the default value here (and thus neither no need to handle any merging (extend))

@nicolas-grekas
Copy link
Member

Status: needs work

@fabpot
Copy link
Member

fabpot commented Mar 31, 2016

What's the status of this PR?

@MGDSoft
Copy link
Contributor Author

MGDSoft commented Apr 1, 2016

currently working, I was on vacation

@MGDSoft
Copy link
Contributor Author

MGDSoft commented Apr 2, 2016

Hi,

If I use a single var to displayOptions, I break a some test like TwigDumpExtension.
What should we do to fix this problem?

I think it would be good, add a parameter in TwigDumpExtension to change displayOptions, but it can have a random number of arguments.

I am stuck :/

@MGDSoft
Copy link
Contributor Author

MGDSoft commented Apr 2, 2016

The option maxItemsPerDepth require modify all samp elements to ul because each row must be delimited by a element like li. WDYT?

@nicolas-grekas
Copy link
Member

Let's do maxItemsPerDepth later in an other PR then. I can't look at this right now but will definitely try it soon!

@nicolas-grekas
Copy link
Member

Continued in #18948
Thank you @MGDSoft !

fabpot added a commit that referenced this pull request Jun 28, 2016
…ions (MGDSoft, nicolas-grekas)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[VarDumper] Add maxDepth & maxStringLength display options

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #16741
| License       | MIT
| Doc PR        | -

Takes over #18148 to add display options to html dumps.
Status: needs work

Commits
-------

998ff33 [VarDumper] Tweak display options implementation
58eb665 [VarDumper] Add maxDepth & maxStringLength display options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants