8000 [TwigBridge] Fix BC break due required twig environment by ro0NL · Pull Request #24851 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[TwigBridge] Fix BC break due required twig environment #24851

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 2 commits into from
Closed
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
Next Next commit
[TwigBridge] Fix BC break due required twig environment
  • Loading branch information
ro0NL authored Nov 7, 2017
commit 8937c5f7e27e6aee0ab29e7bca33ead72e2794d4
34 changes: 18 additions & 16 deletions src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TwigDataCollector extends DataCollector implements LateDataCollectorInterf
private $twig;
private $computed;

public function __construct(Profile $profile, Environment $twig)
public function __construct(Profile $profile, Environment $twig = null)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe passing null should trigger a deprecation warning, so we can remove the boilerplate below on the 4.0 branch again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds reasonable :) lets see what others think.

Copy link
Member

Choose a reason for hiding this comment

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

No need to "deprecate" that as we are talking about an additional feature.

{
$this->profile = $profile;
$this->twig = $twig;
Expand Down Expand Up @@ -62,24 +62,26 @@ public function lateCollect()
$this->data['profile'] = serialize($this->profile);
$this->data['template_paths'] = array();

$templateFinder = function (Profile $profile) use (&$templateFinder) {
if ($profile->isTemplate()) {
try {
$template = $this->twig->load($name = $profile->getName());
} catch (\Twig_Error_Loader $e) {
$template = null;
if (null !== $this->twig) {
Copy link
Member

Choose a reason for hiding this comment

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

if (null === $this->twig) {return;}?
about the deprecation, too late IMHO if we want to be strict about the feat freeze

$templateFinder = function (Profile $profile) use (&$templateFinder) {
if ($profile->isTemplate()) {
try {
$template = $this->twig->load($name = $profile->getName());
} catch (\Twig_Error_Loader $e) {
$template = null;
}

if (null !== $template && '' !== $path = $template->getSourceContext()->getPath()) {
$this->data['template_paths'][$name] = $path;
}
}

if (null !== $template && '' !== $path = $template->getSourceContext()->getPath()) {
$this->data['template_paths'][$name] = $path;
foreach ($profile as $p) {
$templateFinder($p);
}
}

foreach ($profile as $p) {
$templateFinder($p);
}
};
$templateFinder($this->profile);
};
$templateFinder($this->profile);
}
}

public function getTime()
Expand Down
0