I'm using Dwoo with Zend Framework. I'm using custom delimeters (<%, %>) for the compiler. First i used following code:
<pre>
public function initDwoo()
{
$viewInterface = new Dwoo_Adapters_ZendFramework_View(self::$oConfig->template->dwoo);
$viewInterface->setScriptPath(self::$oConfig->template->dwoo->engine->templateDir);
$viewInterface->addPluginDir('../library/Dwoo/Plugins');
/* Set custom delimeters */
list($leftDelimeter,$rightDelimeter) = explode(',',self::$oConfig->template->dwoo->compiler->delimeters);
$viewInterface->getCompiler()->setDelimiters($leftDelimeter,$rightDelimeter);
$viewInterface->getCompiler()->setLooseOpeningHandling(true);
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($viewInterface);
$viewRenderer->setViewSuffix('tpl');
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
}
</pre>
The Main templates work. But if i use "include" function in a template it expects {,} as delimeters in the included file.
Workaround:
<pre>
public function initDwoo()
{
...
/* Set custom delimeters */
list($leftDelimeter,$rightDelimeter) = explode(',',self::$oConfig->template->dwoo->compiler->delimeters);
$viewInterface->getCompiler()->setDelimiters($leftDelimeter,$rightDelimeter);
$viewInterface->getCompiler()->setLooseOpeningHandling(true);
/* Set custom compiler factory */
$viewInterface->getEngine()->setDefaultCompilerFactory('file', array($this,'dwooCompilerFactory'));
...
}
public static function dwooCompilerFactory()
{
if(self::$oDwooCompiler === null)
{
self::$oDwooCompiler = Dwoo_Compiler::compilerFactory();
/* Set custom delimeters once more */
list($leftDelimeter,$rightDelimeter) = explode(',',self::$oConfig->template->dwoo->compiler->delimeters);
self::$oDwooCompiler->setDelimiters($leftDelimeter,$rightDelimeter);
self::$oDwooCompiler->setLooseOpeningHandling(true);
}
return self::$oDwooCompiler;
}
</pre>
As you see, i have to set my deimeters in two places. If i remove the first one - nothing works. If i remote the second one - included templates do not work.
Jordi Boggiano at Tuesday 7 April 2009 14:20:03 UTC
Interesting issue. Well it's just interesting the various way a bug can come up.
Anyway, the first issue you describe can be fixed I believe, if I store the compiler that's been passed to Dwoo::get and then re-use it in the include plugin. That being said it's not really the way to do it.. I mean instanciating a compiler each time is quite a waste of resources, so the factory is a much better approach..
...which fails for you apparently. I don't really know why just by looking at your code extracts there. The only guess I could make is that you didn't clear the compiled templates and it didn't go into the compilerFactory path for the templates that were compiled already. Apart from that, if it's set at the time you render the main template, it should work for the main as well as the included ones. Can you please check for that compiled dir thingy ?
Boris D. at Tuesday 7 April 2009 14:26:27 UTC
$viewInterface->getCompiler()->setDelimiters($leftDelimeter,$rightDelimeter); $viewInterface->getCompiler()->setLooseOpeningHandling(true);
</pre>
and clear the compiled dir, i get the Exception: "Dwoo_Exception: Plugin title can not be found, maybe you forgot to bind it if it's a custom plugin ?", so i guess he is searching for standard delimeters in the template.
Boris D. at Tuesday 7 April 2009 14:32:02 UTC
The factory is being called only for the included template. I guess the Compiler for the first template already created before i define my own factory.
Jordi Boggiano at Tuesday 7 April 2009 14:38:10 UTC
Okay sorry I missed the fact that you were in ZF World, and the ZF Adapter indeed creates a default Dwoo_Compiler instance in _run(). I guess it should be refactored a bit so that it registers a compiler factory and buffers the compiler settings until the last minute so we don't have to create it every time for nothing. I'll see about that with Denis.
Denis Arh at Friday 10 April 2009 04:26:28 UTC
@Boris - can you try these changes and tell me if it works for you. <pre> Index: lib/Dwoo/Adapters/ZendFramework/View.php =================================================================== --- lib/Dwoo/Adapters/ZendFramework/View.php (revision 258) +++ lib/Dwoo/Adapters/ZendFramework/View.php (working copy) @@ -33,6 +33,14 @@ * @var Dwoo_Compiler */ protected $_compiler = null; + + /** + * Changing Filter's scope to play nicely + * + * @var array + */ + protected $_filter = array(); + /** * @var string @@ -95,15 +103,9 @@ } // end BC - // Making sure that everything is loaded. - $defaults = array( - 'engine' => 'Dwoo', - 'dataProvider' => 'Dwoo_Data', - 'compiler' => 'Dwoo_Compiler', - ); + // Making sure that everything is loaded. + $classes = array('engine', 'dataProvider', 'compiler'); - $opt = array_merge($defaults, $opt); - // Setting options to Dwoo objects... foreach ($opt as $type => $settings) { if (!method_exists($this, 'set' . $type)) { @@ -118,7 +120,7 @@ call_user_func(array($this, 'set' . $type), $settings['type']); } - if (array_key_exists($type, $defaults)) { + if (in_array($type, $classes)) { // Call get so that the class is initialized $rel = call_user_func(array($this, 'get' . $type)); @@ -330,9 +332,9 @@ * @return Dwoo_Data */ public function getCompiler() - { - if (null === $this->_compiler) { - $this->_compiler = new Dwoo_Compiler; + { + if (null === $this->_compiler) { + $this->_compiler = Dwoo_Compiler::compilerFactory(); } return $this->_compiler; </pre>Boris D. at Sunday 19 April 2009 13:23:19 UTC
Yeah, that worked. Now it uses the factory. Thanks.
Denis Arh at Sunday 19 April 2009 14:41:46 UTC
Applied in changeset r259.
Boris D. at Sunday 19 April 2009 17:10:16 UTC
Sorry, it DOESN'T work :( Here is my fix (I have hardcoded resource 'file' in there. I think it must be corrected somehow) <pre> Index: View.php =================================================================== --- View.php (revision 259) +++ View.php (working copy) @@ -333,8 +333,18 @@ */ public function getCompiler() { - if (null === $this->_compiler) { - $this->_compiler = Dwoo_Compiler::compilerFactory(); + if (null === $this->_compiler) + { + $compiler = $this->_engine->getDefaultCompilerFactory('file'); + + if ($compiler === null || $compiler === array('Dwoo_Compiler', 'compilerFactory')) { + if (class_exists('Dwoo_Compiler', false) === false) { + include DWOO_DIRECTORY . 'Dwoo/Compiler.php'; + } + $compiler = Dwoo_Compiler::compilerFactory(); + } else { + $compiler = call_user_func($compiler); + } } return $this->_compiler; </pre>Denis Arh at Sunday 19 April 2009 19:29:11 UTC
Will check.
Denis Arh at Tuesday 30 June 2009 05:15:38 UTC
Denis Arh wrote: > Will check.
Soon :)
Really. In a day or two.
Denis Arh at Tuesday 30 June 2009 20:58:11 UTC
Boris D. wrote: > Sorry, it DOESN'T work :( Here is my fix (I have hardcoded resource 'file' in there. I think it must be corrected somehow)
> [...]
I've recreated my old testing environment, but that fix (replacing new Dwoo_Compiler with Dwoo_Compiler::compilerFactory()) works with the problem described.
Could you provide sample templates and php lines where you initialize and set-up Dwoo?
Jordi Boggiano at Wednesday 7 October 2009 08:01:49 UTC
Could you please try it again with latest svn version (trunk or branches/1.1) ? I believe it's fixed..
Jordi Boggiano at Sunday 24 January 2010 04:20:00 UTC
I would like to release 1.1.1 soon, so here is a last call for action, if nobody gets back to me I'll consider this fixed.
Jordi Boggiano at Sunday 7 February 2010 16:24:43 UTC
This is hereby assumed to be fixed, feel free to reopen or create a new ticket if there is still an issue.