10000 Update the way to retrieve the template source · SofHad/symfony@86203de · GitHub
[go: up one dir, main page]

Skip to content

Commit 86203de

Browse files
committed
Update the way to retrieve the template source
Latest Twig versions allow to get the source from the Twig_Template object itself, making it work with any loader (and without needing the loader).
1 parent 9df6e8c commit 86203de

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

src/CodeExplorerBundle/EventListener/ControllerListener.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@
2828
*/
2929
class ControllerListener
3030
{
31-
/**
32-
* @var SourceCodeExtension
33-
*/
34-
protected $twigExtension;
31+
private $twigExtension;
3532

3633
public function __construct(SourceCodeExtension $twigExtension)
3734
{

src/CodeExplorerBundle/Resources/config/services.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ services:
22
code_explorer.twig.source_code_extension:
33
public: false
44
class: CodeExplorerBundle\Twig\SourceCodeExtension
5-
arguments: [@twig.loader, %kernel.root_dir%]
5+
arguments: [%kernel.root_dir%]
66
tags:
77
- { name: twig.extension }
88

src/CodeExplorerBundle/Twig/SourceCodeExtension.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@
2222
*/
2323
class SourceCodeExtension extends \Twig_Extension
2424
{
25-
protected $loader;
26-
protected $controller;
27-
protected $kernelRootDir;
25+
private $controller;
26+
private $kernelRootDir;
2827

29-
public function __construct(\Twig_LoaderInterface $loader, $kernelRootDir)
28+
public function __construct($kernelRootDir)
3029
{
3130
$this->kernelRootDir = $kernelRootDir;
32-
$this->loader = $loader;
3331
}
3432

3533
public function setController($controller)
@@ -101,12 +99,10 @@ private function getCallableReflector($callable)
10199

102100
private function getTemplateSource(\Twig_Template $template)
103101
{
104-
$templateName = $template->getTemplateName();
105-
106102
return array(
107-
'file_path' => $this->kernelRootDir.'/Resources/views/'.$templateName,
103+
'file_path' => $this->kernelRootDir.'/Resources/views/'.$template->getTemplateName(),
108104
'starting_line' => 1,
109-
'source_code' => $this->loader->getSource($templateName),
105+
'source_code' => $template->getSource(),
110106
);
111107
}
112108

0 commit comments

Comments
 (0)
0