poc integrate smarty in DI
This commit is contained in:
@@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
namespace Thelia\Admin\Templating\Smarty;
|
namespace Thelia\Admin\Templating\Smarty;
|
||||||
|
|
||||||
use Thelia\Template\Assets\AsseticManager;
|
use Thelia\Core\Template\Assets\AsseticManager;
|
||||||
|
|
||||||
class AssetsManager extends AsseticManager {
|
class AssetsManager extends AsseticManager {
|
||||||
|
|
||||||
|
|||||||
@@ -28,13 +28,17 @@
|
|||||||
|
|
||||||
<service id="controller_resolver" class="Symfony\Component\HttpKernel\Controller\ControllerResolver"/>
|
<service id="controller_resolver" class="Symfony\Component\HttpKernel\Controller\ControllerResolver"/>
|
||||||
|
|
||||||
<service id="parser" class="Thelia\Core\Template\SmartyParser">
|
<service id="smarty" class="Thelia\Core\Template\SmartyParser">
|
||||||
<argument type="service" id="service_container"/>
|
<argument type="service" id="service_container"/>
|
||||||
<call method="setLoopList">
|
<call method="setLoopList">
|
||||||
<argument>%tpex.loop%</argument>
|
<argument>%tpex.loop%</argument>
|
||||||
</call>
|
</call>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
|
<service id="smarty.plugin.assetic" class="Thelia\Core\Template\Smarty\Plugins\AsseticManager" >
|
||||||
|
<tag name="smarty.register_plugin"/>
|
||||||
|
</service>
|
||||||
|
|
||||||
<service id="http_kernel" class="Thelia\Core\TheliaHttpKernel">
|
<service id="http_kernel" class="Thelia\Core\TheliaHttpKernel">
|
||||||
<argument type="service" id="event_dispatcher" />
|
<argument type="service" id="event_dispatcher" />
|
||||||
<argument type="service" id="service_container" />
|
<argument type="service" id="service_container" />
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ use Symfony\Component\DependencyInjection\Reference;
|
|||||||
use Symfony\Component\DependencyInjection\Scope;
|
use Symfony\Component\DependencyInjection\Scope;
|
||||||
|
|
||||||
use Thelia\Core\DependencyInjection\Compiler\RegisterListenersPass;
|
use Thelia\Core\DependencyInjection\Compiler\RegisterListenersPass;
|
||||||
|
use Thelia\Core\DependencyInjection\Compiler\RegisterSmartyPluginPass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* First Bundle use in Thelia
|
* First Bundle use in Thelia
|
||||||
@@ -56,5 +57,6 @@ class TheliaBundle extends Bundle
|
|||||||
$container->addScope(new Scope('request'));
|
$container->addScope(new Scope('request'));
|
||||||
|
|
||||||
$container->addCompilerPass(new RegisterListenersPass());
|
$container->addCompilerPass(new RegisterListenersPass());
|
||||||
|
$container->addCompilerPass(new RegisterSmartyPluginPass());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by JetBrains PhpStorm.
|
||||||
|
* User: manu
|
||||||
|
* Date: 18/06/13
|
||||||
|
* Time: 21:55
|
||||||
|
* To change this template use File | Settings | File Templates.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Thelia\Core\DependencyInjection\Compiler;
|
||||||
|
|
||||||
|
|
||||||
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
|
|
||||||
|
class RegisterSmartyPluginPass implements CompilerPassInterface {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* You can modify the container here before it is dumped to PHP code.
|
||||||
|
*
|
||||||
|
* @param ContainerBuilder $container
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
public function process(ContainerBuilder $container)
|
||||||
|
{
|
||||||
|
if (!$container->hasDefinition("smarty")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$smarty = $container->getDefinition("smarty");
|
||||||
|
|
||||||
|
foreach ($container->findTaggedServiceIds("smarty.register_plugin") as $id => $plugin) {
|
||||||
|
|
||||||
|
$smarty->addMethodCall("addPlugins", array(new Reference($id)));
|
||||||
|
|
||||||
|
/*$register_plugin = $container->get($id);
|
||||||
|
|
||||||
|
$reflectionObject = new \ReflectionObject($register_plugin);
|
||||||
|
$interface = "Thelia\Core\Template\Smarty\SmartyPluginInterface";
|
||||||
|
if (!$reflectionObject->implementsInterface($interface)) {
|
||||||
|
throw new \RuntimeException(sprintf("%s class must implement %s interface",$reflectionObject->getName(), $interface));
|
||||||
|
}
|
||||||
|
|
||||||
|
$plugins = $register_plugin->registerPlugins();
|
||||||
|
|
||||||
|
if(!is_array($plugins)) {
|
||||||
|
$plugins = array($plugins);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($plugins as $plugin) {
|
||||||
|
$smarty->addMethodCall("registerPlugin", array(
|
||||||
|
$plugin->type,
|
||||||
|
$plugin->name,
|
||||||
|
array(
|
||||||
|
$plugin->class,
|
||||||
|
$plugin->method
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -67,7 +67,7 @@ class ViewListener implements EventSubscriberInterface
|
|||||||
*/
|
*/
|
||||||
public function onKernelView(GetResponseForControllerResultEvent $event)
|
public function onKernelView(GetResponseForControllerResultEvent $event)
|
||||||
{
|
{
|
||||||
$parser = $this->container->get('parser');
|
$parser = $this->container->get('smarty');
|
||||||
try {
|
try {
|
||||||
$content = $parser->getContent();
|
$content = $parser->getContent();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by JetBrains PhpStorm.
|
||||||
|
* User: manu
|
||||||
|
* Date: 18/06/13
|
||||||
|
* Time: 22:44
|
||||||
|
* To change this template use File | Settings | File Templates.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Thelia\Core\Template\Smarty\Plugins;
|
||||||
|
|
||||||
|
|
||||||
|
use Thelia\Core\Template\Smarty\RegisterSmartyPlugin;
|
||||||
|
use Thelia\Core\Template\Smarty\SmartyPluginInterface;
|
||||||
|
use Thelia\Admin\Templating\Smarty\AssetsManager;
|
||||||
|
|
||||||
|
class AsseticManager implements SmartyPluginInterface{
|
||||||
|
|
||||||
|
public $asset_manager;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$web_root = THELIA_WEB_DIR;
|
||||||
|
|
||||||
|
$asset_dir_from_web_root = 'assets/admin/default'; // FIXME
|
||||||
|
|
||||||
|
$this->asset_manager = new AssetsManager($web_root, $asset_dir_from_web_root);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function smartyBlockJavascripts($params, $content, \Smarty_Internal_Template $template, &$repeat)
|
||||||
|
{
|
||||||
|
return $this->asset_manager->processSmartyPluginCall('js', $params, $content, $template, $repeat);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function smartyBlockImages($params, $content, \Smarty_Internal_Template $template, &$repeat)
|
||||||
|
{
|
||||||
|
return $this->asset_manager->processSmartyPluginCall(AssetsManager::ASSET_TYPE_AUTO, $params, $content, $template, $repeat);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function smartyBlockStylesheets($params, $content, \Smarty_Internal_Template $template, &$repeat)
|
||||||
|
{
|
||||||
|
return $this->asset_manager->processSmartyPluginCall('css', $params, $content, $template, $repeat);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function registerPlugins()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
new RegisterSmartyPlugin('block', 'stylesheets', $this, 'smartyBlockStylesheets'),
|
||||||
|
new RegisterSmartyPlugin('block', 'javascripts', $this, 'smartyBlockJavascripts'),
|
||||||
|
new RegisterSmartyPlugin('block', 'images', $this, 'smartyBlockImages')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by JetBrains PhpStorm.
|
||||||
|
* User: manu
|
||||||
|
* Date: 18/06/13
|
||||||
|
* Time: 22:41
|
||||||
|
* To change this template use File | Settings | File Templates.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Thelia\Core\Template\Smarty;
|
||||||
|
|
||||||
|
|
||||||
|
class RegisterSmartyPlugin {
|
||||||
|
public $type;
|
||||||
|
public $name;
|
||||||
|
public $class;
|
||||||
|
public $method;
|
||||||
|
|
||||||
|
public function __construct($type, $name, $class, $method)
|
||||||
|
{
|
||||||
|
$this->type = $type;
|
||||||
|
$this->name = $name;
|
||||||
|
$this->class = $class;
|
||||||
|
$this->method = $method;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by JetBrains PhpStorm.
|
||||||
|
* User: manu
|
||||||
|
* Date: 18/06/13
|
||||||
|
* Time: 22:38
|
||||||
|
* To change this template use File | Settings | File Templates.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Thelia\Core\Template\Smarty;
|
||||||
|
|
||||||
|
|
||||||
|
interface SmartyPluginInterface {
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function registerPlugins();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -6,9 +6,12 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||||||
use Thelia\Core\Template\ParserInterface;
|
use Thelia\Core\Template\ParserInterface;
|
||||||
use \Smarty;
|
use \Smarty;
|
||||||
use Thelia\Core\Template\Loop\Category;
|
use Thelia\Core\Template\Loop\Category;
|
||||||
|
use Thelia\Core\Template\Smarty\SmartyPluginInterface;
|
||||||
|
|
||||||
class SmartyParser extends Smarty implements ParserInterface {
|
class SmartyParser extends Smarty implements ParserInterface {
|
||||||
|
|
||||||
|
public $plugins;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Symfony\Component\DependencyInjection\ContainerInterface
|
* @var Symfony\Component\DependencyInjection\ContainerInterface
|
||||||
*/
|
*/
|
||||||
@@ -77,6 +80,33 @@ class SmartyParser extends Smarty implements ParserInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addPlugins(SmartyPluginInterface $plugin)
|
||||||
|
{
|
||||||
|
$this->plugins[] = $plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function registerPlugins()
|
||||||
|
{
|
||||||
|
foreach ($this->plugins as $register_plugin) {
|
||||||
|
$plugins = $register_plugin->registerPlugins();
|
||||||
|
|
||||||
|
if(!is_array($plugins)) {
|
||||||
|
$plugins = array($plugins);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($plugins as $plugin) {
|
||||||
|
$this->registerPlugin(
|
||||||
|
$plugin->type,
|
||||||
|
$plugin->name,
|
||||||
|
array(
|
||||||
|
$plugin->class,
|
||||||
|
$plugin->method
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function extractParam($loop, $smartyParam)
|
private function extractParam($loop, $smartyParam)
|
||||||
{
|
{
|
||||||
$defaultItemsParams = array('required' => true);
|
$defaultItemsParams = array('required' => true);
|
||||||
@@ -242,6 +272,7 @@ class SmartyParser extends Smarty implements ParserInterface {
|
|||||||
*/
|
*/
|
||||||
public function getContent()
|
public function getContent()
|
||||||
{
|
{
|
||||||
|
$this->registerPlugins();
|
||||||
return $this->fetch($this->getTemplateFilePath());
|
return $this->fetch($this->getTemplateFilePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
1109
templates/smarty-sample/assets/bootstrap/css/bootstrap-responsive.css
vendored
Normal file
1109
templates/smarty-sample/assets/bootstrap/css/bootstrap-responsive.css
vendored
Normal file
File diff suppressed because it is too large
Load Diff
9
templates/smarty-sample/assets/bootstrap/css/bootstrap-responsive.min.css
vendored
Normal file
9
templates/smarty-sample/assets/bootstrap/css/bootstrap-responsive.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
6167
templates/smarty-sample/assets/bootstrap/css/bootstrap.css
vendored
Normal file
6167
templates/smarty-sample/assets/bootstrap/css/bootstrap.css
vendored
Normal file
File diff suppressed because it is too large
Load Diff
9
templates/smarty-sample/assets/bootstrap/css/bootstrap.min.css
vendored
Normal file
9
templates/smarty-sample/assets/bootstrap/css/bootstrap.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
Binary file not shown.
|
After Width: | Height: | Size: 8.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
2280
templates/smarty-sample/assets/bootstrap/js/bootstrap.js
vendored
Normal file
2280
templates/smarty-sample/assets/bootstrap/js/bootstrap.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
6
templates/smarty-sample/assets/bootstrap/js/bootstrap.min.js
vendored
Normal file
6
templates/smarty-sample/assets/bootstrap/js/bootstrap.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
135
templates/smarty-sample/assets/css/admin.less
Normal file
135
templates/smarty-sample/assets/css/admin.less
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
// -- Tools --------------------------------------------------------------------
|
||||||
|
|
||||||
|
.border-radius(@radius: 5px) {
|
||||||
|
-webkit-border-radius: @radius;
|
||||||
|
-moz-border-radius: @radius;
|
||||||
|
border-radius: @radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
.box-shadow(@shadow: 0 1px 2px rgba(0,0,0,.05)) {
|
||||||
|
-webkit-box-shadow: @shadow;
|
||||||
|
-moz-box-shadow: @shadow;
|
||||||
|
box-shadow: @shadow;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- Base styling ------------------------------------------------------------
|
||||||
|
|
||||||
|
html, body {
|
||||||
|
height: 100%;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background: url("img/bg.jpg") repeat;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3, h4 {
|
||||||
|
color: #5a6876;
|
||||||
|
background: -webkit-gradient(linear, left top, left bottom, from(#42505d), to(#72808e));
|
||||||
|
-webkit-background-clip: text;
|
||||||
|
-webkit-text-fill-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
padding: 0px;
|
||||||
|
margin: 0px 0px 20px 0px;
|
||||||
|
text-align: left;
|
||||||
|
font-size : 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h4 {
|
||||||
|
padding: 0px 0px 20px 0px;
|
||||||
|
margin: 0px;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
#wrapper {
|
||||||
|
padding-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #e9720f;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- Brandbar ----------------------------------------------------------------
|
||||||
|
|
||||||
|
/* --- BRAND BAR ---*/
|
||||||
|
.brandbar {
|
||||||
|
|
||||||
|
background: url("images/header.jpg") repeat-x;
|
||||||
|
height: 90px;
|
||||||
|
|
||||||
|
a.brand {
|
||||||
|
text-indent: -133337px;
|
||||||
|
display: block;
|
||||||
|
float: left;
|
||||||
|
margin-right: 20px;
|
||||||
|
background: url("images/logo.png") 0px 12px no-repeat;
|
||||||
|
width: 124px;
|
||||||
|
height: 63px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.breadcrumb {
|
||||||
|
border-radius: 0px;
|
||||||
|
padding: 25px 0px 25px 30px;
|
||||||
|
background: url("images/logo-light.png") left center no-repeat;
|
||||||
|
float: left;
|
||||||
|
margin: 12px 0px 0px 0px;
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #949aa1;
|
||||||
|
text-shadow: 0px 1px 0px rgba(0,0,0,0.8);
|
||||||
|
}
|
||||||
|
|
||||||
|
.active {
|
||||||
|
color: #FFF;
|
||||||
|
text-shadow: 0px 1px 0px rgba(0,0,0,0.8);
|
||||||
|
border-bottom: 1px dotted white;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.Blocmoncompte {
|
||||||
|
float: right;
|
||||||
|
margin: 0px;
|
||||||
|
padding: 0px;
|
||||||
|
margin-top: 35px;
|
||||||
|
|
||||||
|
color: white;
|
||||||
|
font-size: 13px;
|
||||||
|
text-shadow: 0px 1px 0px rgba(0,0,0,0.8);
|
||||||
|
}
|
||||||
|
|
||||||
|
dt {
|
||||||
|
float: left;
|
||||||
|
margin-right: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.deconnexion {
|
||||||
|
float: right;
|
||||||
|
margin: 0px;
|
||||||
|
|
||||||
|
a {
|
||||||
|
text-indent: -13337px;
|
||||||
|
display: block;
|
||||||
|
background: url("images/deconnexion.png") no-repeat;
|
||||||
|
width: 23px;
|
||||||
|
height: 24px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -- Login form --------------------------------------------------------------
|
||||||
|
|
||||||
|
.form-signin {
|
||||||
|
max-width: 400px;
|
||||||
|
padding: 19px 29px 29px;
|
||||||
|
margin: 0 auto 20px;
|
||||||
|
background-color: #fff;
|
||||||
|
border: 1px solid #e5e5e5;
|
||||||
|
.border-radius;
|
||||||
|
.box-shadow;
|
||||||
|
}
|
||||||
6
templates/smarty-sample/assets/js/jquery.min.js
vendored
Normal file
6
templates/smarty-sample/assets/js/jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
13
templates/smarty-sample/includes/footer.inc.tpl
Normal file
13
templates/smarty-sample/includes/footer.inc.tpl
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{* Include required JS files *}
|
||||||
|
|
||||||
|
{javascripts file='../assets/js/jquery.min.js'}
|
||||||
|
<link rel="stylesheet" href="{$asset_url}" target="screen">
|
||||||
|
{/javascripts}
|
||||||
|
|
||||||
|
{javascripts file='../assets/bootstrap/js/bootstrap.min.js'}
|
||||||
|
<link rel="stylesheet" href="{$asset_url}" target="screen">
|
||||||
|
{/javascripts}
|
||||||
|
|
||||||
|
{* TODO allow modules to include JS here *}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
21
templates/smarty-sample/includes/header.inc.tpl
Normal file
21
templates/smarty-sample/includes/header.inc.tpl
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="{$lang}">
|
||||||
|
<head>
|
||||||
|
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
|
||||||
|
{stylesheets file='../assets/css/*' filters='less,cssrewrite'}
|
||||||
|
<link rel="stylesheet" href="{$asset_url}">
|
||||||
|
{/stylesheets}
|
||||||
|
|
||||||
|
{stylesheets file='../assets/bootstrap/css/bootstrap.min.css' filters='cssrewrite'}
|
||||||
|
<link rel="stylesheet" href="{$asset_url}">
|
||||||
|
{/stylesheets}
|
||||||
|
|
||||||
|
{stylesheets file='../assets/bootstrap/css/bootstrap-responsive.min.css' filters='cssrewrite'}
|
||||||
|
<link rel="stylesheet" href="{$asset_url}">
|
||||||
|
{/stylesheets}
|
||||||
|
|
||||||
|
{* TODO allow modules to include CSS here *}
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
0
templates/smarty-sample/includes/menu.tpl
Normal file
0
templates/smarty-sample/includes/menu.tpl
Normal file
@@ -1,9 +1,4 @@
|
|||||||
<!DOCTYPE html>
|
{include file='includes/header.inc.tpl'}
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title></title>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
||||||
</head>
|
|
||||||
<body>
|
<body>
|
||||||
<div>
|
<div>
|
||||||
<p>Category loop example</p>
|
<p>Category loop example</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user