Skip to content

[Bridge][Twig] Optionally pass dumper into DumpExtension #18466

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 1 commit into from
Jun 22, 2016
Merged

[Bridge][Twig] Optionally pass dumper into DumpExtension #18466

merged 1 commit into from
Jun 22, 2016

Conversation

CarsonF
Copy link
Contributor

@CarsonF CarsonF commented Apr 6, 2016

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
License MIT

Allow the dumper to be passed into DumpExtension constructor. This allows a different dumper to be used or even just HtmlDumper with a non-default configuration, such as different styles.

Note: The dumper's output is ignored.

@@ -22,7 +23,7 @@ class DumpExtensionTest extends \PHPUnit_Framework_TestCase
*/
public function testDumpTag($template, $debug, $expectedOutput, $expectedDumped)
{
$extension = new DumpExtension(new VarCloner());
$extension = new DumpExtension(new VarCloner(), new HtmlDumper());
Copy link
Member

Choose a reason for hiding this comment

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

This change should be reverted to check that the expected behaviour does not change when still not injecting a dumper. You could add another test which gets another dumper injected and test for the expected output.

@CarsonF
Copy link
Contributor Author

CarsonF commented Apr 6, 2016

@xabbuh Created a separate test. Tests are passing other than an unrelated HHVM/Travis failure.

@@ -67,11 +70,14 @@ public function dump(\Twig_Environment $env, $context)
}

$dump = fopen('php://memory', 'r+b');
$dumper = new HtmlDumper($dump);
$prevOutput = $this->dumper->setOutput($dump);
Copy link
Member

Choose a reason for hiding this comment

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

The setOutput() method is not part of the DataDumperInterface.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ouch...that's an oversight.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you recommend? Should I require AbstractDumper in constructor? I don't think it would be ok to assume the dumper has null output.

Copy link
Member

Choose a reason for hiding this comment

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

Instead of setOutput, you could use dump's 2nd arg.
An you could also create a new interface to enforce what you need here.

Copy link
Contributor Author

@CarsonF CarsonF Apr 18, 2016

Choose a reason for hiding this comment

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

@nicolas-grekas Using the 2nd arg doesn't work as it resets the header sent flag which causes tests to fail (due to recursion I'm assuming).

Even now isn't ideal with the header being dumped once per twig call. Thoughts?

Maybe we set the header to empty string after the first dump call? .... Hmm or maybe not. I guess we can't guarantee that that twig block will get into the actual html page.

@fabpot
Copy link
Member

fabpot commented Jun 14, 2016

Any progress on this one? @nicolas-grekas What would be your take on fixing the setOutput() issue here?

@nicolas-grekas
Copy link
Member

👍, ok for setOutput & for the HtmlDumper type check

@fabpot fabpot merged commit d8c0f1d into symfony:master Jun 22, 2016
fabpot added a commit that referenced this pull request Jun 22, 2016
…on (CarsonF)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[Bridge][Twig] Optionally pass dumper into DumpExtension

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT

Allow the dumper to be passed into `DumpExtension` constructor. This allows a different dumper to be used or even just `HtmlDumper` with a non-default configuration, such as different styles.

Note: The dumper's output is ignored.

Commits
-------

d8c0f1d [Bridge][Twig] Optionally pass dumper into DumpExtension
@CarsonF CarsonF deleted the ioc-dump-extension branch August 31, 2016 17:37
@fabpot fabpot mentioned this pull request Oct 27, 2016
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.

6 participants