refactor how to assign template to parser

This commit is contained in:
Manuel Raynaud
2013-11-06 11:12:39 +01:00
parent 1ccd2e63ce
commit 2d291cf5a0
5 changed files with 40 additions and 25 deletions

View File

@@ -42,7 +42,8 @@ abstract class BaseModuleGenerate extends ContainerAwareCommand
'Config', 'Config',
'Model', 'Model',
'Loop', 'Loop',
'AdminIncludes' 'AdminIncludes',
'templates',
); );
protected function verifyExistingModule() protected function verifyExistingModule()

View File

@@ -50,7 +50,6 @@
<argument type="service" id="request" /> <argument type="service" id="request" />
<argument type="service" id="event_dispatcher"/> <argument type="service" id="event_dispatcher"/>
<argument type="service" id="thelia.parser.context"/> <argument type="service" id="thelia.parser.context"/>
<argument >false</argument> <!-- Template name, or false -->
<argument >%kernel.environment%</argument> <argument >%kernel.environment%</argument>
<argument >%kernel.debug%</argument> <argument >%kernel.debug%</argument>
</service> </service>

View File

@@ -199,7 +199,7 @@ class BaseAdminController extends BaseController
$parser = $this->container->get("thelia.parser"); $parser = $this->container->get("thelia.parser");
// Define the template thant shoud be used // Define the template thant shoud be used
$parser->setTemplate($template ?: ConfigQuery::read('base-admin-template', 'admin/default')); $parser->addTemplateDir($template ?: ConfigQuery::read('base-admin-template', 'admin/default'), 'default');
return $parser; return $parser;
} }

View File

@@ -37,13 +37,12 @@ class SmartyParser extends Smarty implements ParserInterface
* @param Request $request * @param Request $request
* @param EventDispatcherInterface $dispatcher * @param EventDispatcherInterface $dispatcher
* @param ParserContext $parserContext * @param ParserContext $parserContext
* @param bool $template
* @param string $env * @param string $env
* @param bool $debug * @param bool $debug
*/ */
public function __construct( public function __construct(
Request $request, EventDispatcherInterface $dispatcher, ParserContext $parserContext, Request $request, EventDispatcherInterface $dispatcher, ParserContext $parserContext,
$template = false, $env = "prod", $debug = false) $env = "prod", $debug = false)
{ {
parent::__construct(); parent::__construct();
@@ -62,7 +61,7 @@ class SmartyParser extends Smarty implements ParserInterface
$this->setCompileDir($compile_dir); $this->setCompileDir($compile_dir);
$this->setCacheDir($cache_dir); $this->setCacheDir($cache_dir);
$this->setTemplate($template ?: ConfigQuery::read('active-template', 'default')); //$this->setTemplate($template ?: ConfigQuery::read('active-template', 'default'));
$this->debugging = $debug; $this->debugging = $debug;

View File

@@ -123,8 +123,10 @@ class Thelia extends Kernel
if (defined("THELIA_INSTALL_MODE") === false) { if (defined("THELIA_INSTALL_MODE") === false) {
$modules = \Thelia\Model\ModuleQuery::getActivated(); $modules = \Thelia\Model\ModuleQuery::getActivated();
$translator = $container->getDefinition('thelia.translator');
$dirs = array(); $translationDirs = array();
$templateDirs = array();
$parser = $container->getDefinition('thelia.parser');
foreach ($modules as $module) { foreach ($modules as $module) {
try { try {
@@ -138,33 +140,49 @@ class Thelia extends Kernel
$defintion $defintion
); );
$loader = new XmlFileLoader($container, new FileLocator(THELIA_MODULE_DIR . "/" . ucfirst($module->getCode()) . "/Config")); $code = ucfirst($module->getCode());
$loader = new XmlFileLoader($container, new FileLocator(THELIA_MODULE_DIR . "/" . $code . "/Config"));
$loader->load("config.xml"); $loader->load("config.xml");
if (is_dir($dir = THELIA_MODULE_DIR . "/" . ucfirst($module->getCode()) . "/I18n")) { if (is_dir($dir = THELIA_MODULE_DIR . "/" . $code . "/I18n")) {
$dirs[] = $dir; $translationDirs[] = $dir;
}
if (is_dir($dir = THELIA_MODULE_DIR . "/" . $code . "/templates")) {
//$templateDirs[$code] = $dir;
$parser->addMethodCall('addTemplateDir', array($dir, $code));
} }
} catch (\InvalidArgumentException $e) { } catch (\InvalidArgumentException $e) {
// FIXME: process module configuration exception // TODO: process module configuration exception
} }
} }
//Load translation from templates //Load translation from templates
//core translation //core translation
$dirs[] = THELIA_ROOT . "/core/lib/Thelia/Config/I18n"; $translationDirs[] = THELIA_ROOT . "/core/lib/Thelia/Config/I18n";
//admin template //admin template
if(is_dir($dir = THELIA_TEMPLATE_DIR . '/admin/default/I18n')) { if(is_dir($dir = THELIA_TEMPLATE_DIR . '/admin/default/I18n')) {
$dirs[] = $dir; $translationDirs[] = $dir;
} }
//front template //front template
$template = ConfigQuery::getActiveTemplate(); $template = ConfigQuery::getActiveTemplate();
if(is_dir($dir = THELIA_TEMPLATE_DIR . $template . "/I18n")) { if(is_dir($dir = THELIA_TEMPLATE_DIR . $template . "/I18n")) {
$dirs[] = $dir; $translationDirs[] = $dir;
} }
if ($dirs) { if ($translationDirs) {
$this->loadTranslation($container, $translationDirs);
}
}
}
private function loadTranslation(ContainerBuilder $container, array $dirs)
{
$translator = $container->getDefinition('thelia.translator');
$finder = Finder::create() $finder = Finder::create()
->files() ->files()
->depth(0) ->depth(0)
@@ -175,8 +193,6 @@ class Thelia extends Kernel
$translator->addMethodCall('addResource', array($format, (string) $file, $locale)); $translator->addMethodCall('addResource', array($format, (string) $file, $locale));
} }
} }
}
}
/** /**
* *