8000 [Templating] remove Engine as a dependency for the Helper objects · CodingFabian/symfony@bf08289 · GitHub
[go: up one dir, main page]

Skip to content

Commit bf08289

Browse files
committed
[Templating] remove Engine as a dependency for the Helper objects
1 parent bce240b commit bf08289

File tree

6 files changed

+43
-25
lines changed

6 files changed

+43
-25
lines changed

src/Symfony/Components/Templating/Engine.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public function set(HelperInterface $helper, $alias = null)
182182
$this->helpers[$alias] = $helper;
183183
}
184184

185-
$helper->setEngine($this);
185+
$helper->setCharset($this->charset);
186186
}
187187

188188
/**

src/Symfony/Components/Templating/Helper/Helper.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Symfony\Components\Templating\Helper;
44

5-
use Symfony\Components\Templating\Engine;
6-
75
/*
86
* This file is part of the symfony package.
97
*
@@ -22,25 +20,25 @@
2220
*/
2321
abstract class Helper implements HelperInterface
2422
{
25-
protected $engine;
23+
protected $charset = 'UTF-8';
2624

2725
/**
28-
* Sets the engine associated with this helper.
26+
* Sets the default charset.
2927
*
30-
* @param Engine $engine A Engine instance
28+
* @param string $charset The charset
3129
*/
32-
public function setEngine(Engine $engine = null)
30+
public function setCharset($charset)
3331
{
34-
$this->engine = $engine;
32+
$this->charset = $charset;
3533
}
3634

3735
/**
38-
* Gets the engine associated with this helper.
36+
* Gets the default charset.
3937
*
40-
* @return Engine A Engine instance
38+
* @return string The default charset
4139
*/
42-
public function getEngine()
40+
public function getCharset()
4341
{
44-
return $this->engine;
42+
return $this->charset;
4543
}
4644
}

src/Symfony/Components/Templating/Helper/HelperInterface.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Symfony\Components\Templating\Helper;
44

5-
use Symfony\Components\Templating\Engine;
6-
75
/*
86
* This file is part of the symfony package.
97
*
@@ -30,16 +28,16 @@ interface HelperInterface
3028
function getName();
3129

3230
/**
33-
* Sets the engine associated with this helper.
31+
* Sets the default charset.
3432
*
35-
* @param Engine $engine A Engine instance
33+
* @param string $charset The charset
3634
*/
37-
function setEngine(Engine $engine = null);
35+
function setCharset($charset);
3836

3937
/**
40-
* Gets the engine associated with this helper.
38+
* Gets the default charset.
4139
*
42-
* @return Engine A Engine instance
40+
* @return string The default charset
4341
*/
44-
function getEngine();
42+
function getCharset();
4543
}

src/Symfony/Components/Templating/Helper/JavascriptsHelper.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@
2828
class JavascriptsHelper extends Helper
2929
{
3030
protected $javascripts = array();
31+
protected $assetHelper;
32+
33+
/**
34+
* Constructor.
35+
*
36+
* @param AssetsHelper $assetHelper A AssetsHelper instance
37+
*/
38+
public function __construct(AssetsHelper $assetHelper)
39+
{
40+
$this->assetHelper = $assetHelper;
41+
}
3142

3243
/**
3344
* Adds a JavaScript file.
@@ -37,7 +48,7 @@ class JavascriptsHelper extends Helper
3748
*/
3849
public function add($javascript, $attributes = array())
3950
{
40-
$this->javascripts[$this->engine->get('assets')->getUrl($javascript)] = $attributes;
51+
$this->javascripts[$this->assetHelper->getUrl($javascript)] = $attributes;
4152
}
4253

4354
/**
@@ -63,7 +74,7 @@ public function render()
6374
$atts = '';
6475
foreach ($attributes as $key => $value)
6576
{
66-
$atts .= ' '.sprintf('%s="%s"', $key, $this->engine->escape($value));
77+
$atts .= ' '.sprintf('%s="%s"', $key, htmlspecialchars($value, ENT_QUOTES, $this->charset));
6778
}
6879

6980
$html .= sprintf('<script type="text/javascript" src="%s"%s></script>', $path, $atts)."\n";

src/Symfony/Components/Templating/Helper/StylesheetsHelper.php

+13Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@
2828
class StylesheetsHelper extends Helper
2929
{
3030
protected $stylesheets = array();
31+
protected $assetHelper;
32+
33+
/**
34+
* Constructor.
35+
*
36+
* @param AssetsHelper $assetHelper A AssetsHelper instance
37+
*/
38+
public function __construct(AssetsHelper $assetHelper)
39+
{
40+
$this->assetHelper = $assetHelper;
41+
}
3142

3243
/**
3344
* Adds a stylesheets file.
@@ -37,7 +48,7 @@ class StylesheetsHelper extends Helper
3748
*/
3849
public function add($stylesheet, $attributes = array())
3950
{
40-
$this->stylesheets[$this->engine->get('assets')->getUrl($stylesheet)] = $attributes;
51+
$this->stylesheets[$this->assetHelper->getUrl($stylesheet)] = $attributes;
4152
}
4253

4354
/**
@@ -63,7 +74,7 @@ public function render()
6374
$atts = '';
6475
foreach ($attributes as $key => $value)
6576
{
66-
$atts .= ' '.sprintf('%s="%s"', $key, $this->engine->escape($value));
77+
$atts .= ' '.sprintf('%s="%s"', $key, htmlspecialchars($value, ENT_QUOTES, $this->charset));
6778
}
6879

6980
$html .= sprintf('<link href="%s" rel="stylesheet" type="text/css"%s />', $path, $atts)."\n";

src/Symfony/Framework/WebBundle/Templating/Engine.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function get($name)
8787
if (is_string($this->helpers[$name]))
8888
{
8989
$this->helpers[$name] = $this->container->getService('templating.helper.'.$name);
90-
$this->helpers[$name]->setEngine($this);
90+
$this->helpers[$name]->setCharset($this->charset);
9191
}
9292

9393
return $this->helpers[$name];

0 commit comments

Comments
 (0)
0