Issue 47 in piwi: getGeneratorById should be public

3 views
Skip to first unread message

pi...@googlecode.com

unread,
Nov 18, 2010, 5:37:55 AM11/18/10
to piwi...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium Milestone-Unscheduled

New issue 47 by simonkastenhuber: getGeneratorById should be public
http://code.google.com/p/piwi/issues/detail?id=47

I need Generators in my php template but can't call it because,
getGeneratorById is set to private.

I propose to change the methods signature to:

public function getGeneratorById($generatorId) {
$this->_initializeGenerator($generatorId);
return $this->generators[$generatorId];
}

pi...@googlecode.com

unread,
Nov 21, 2010, 8:11:25 AM11/21/10
to piwi...@googlegroups.com
Updates:
Status: WontFix

Comment #1 on issue 47 by danielpalme82: getGeneratorById should be public
http://code.google.com/p/piwi/issues/detail?id=47

The method can not simply become public. To call a generator in your
template use this code:

<?php
$content = BeanFactory ::
getBeanById('generatorFactory')->callGenerator('datagrid');
$processor = new XSLTProcessor();
$processor->registerPHPFunctions();
$processor->importStyleSheet(DOMDocument ::
load($GLOBALS['PIWI_ROOT'] . "resources/xslt/GeneratorTransformation.xsl"));
$content = $processor->transformToXML($content);

echo $content ?>

This is required to execute the whole generator pipeline.
If you need this often, you could create a static helper method for this
task.

But don't make getGeneratorById($generatorId) public. It won't work in all
cases!

pi...@googlecode.com

unread,
Nov 25, 2010, 10:31:37 AM11/25/10
to piwi...@googlegroups.com

Comment #2 on issue 47 by grobme...@gmail.com: getGeneratorById should be
public
http://code.google.com/p/piwi/issues/detail?id=47

Why wouldn't it work in all cases?

callGenerator executes the same and just puts the content in a section tag.
but its static and should not be used on an object as your comment
suggests. We cannot make it non-static b/c its used in the XSLT templates.

A public getGeneratorById does work on a fully initialized GeneratorFactory
(created by the Bean container). it initializes the Factory if not done.
The only difference is, its not static and does not wrap the generator xml
into a section tag.

Probably this code should be doable:

echo BeanFactory ::
getBeanById('generatorFactory')->getGeneratorById('mygenerator')->generate();

What are your objections?

pi...@googlecode.com

unread,
Nov 25, 2010, 11:07:13 AM11/25/10
to piwi...@googlegroups.com

Comment #3 on issue 47 by danielpalme82: getGeneratorById should be public
http://code.google.com/p/piwi/issues/detail?id=47

As you can see in my example you have to execute
the 'GeneratorTransformation.xsl' after calling 'callGenerator(...)'. This
is required to resolve LABELS and to execute custom transformations.

As long as you don't use labels, your approach will work. But it won't work
for every possible Generator, that's what i mean with 'in all cases'.

pi...@googlecode.com

unread,
Nov 25, 2010, 11:30:07 AM11/25/10
to piwi...@googlegroups.com

Comment #4 on issue 47 by grobme...@gmail.com: getGeneratorById should be
public
http://code.google.com/p/piwi/issues/detail?id=47

Yes, I saw this - but not in all cases somebody generates piwi tags and
transformation. Shouldn't this risk be taken by the user who calls
getGeneratorById? He should read the documentation in this case. If he
needs transformation, he could probably call "generate" on the GeneratorIf
with an parameter?

I am looking for a straightforward solution for generating stuff for the
work in templates, thats why I started with this topic again. Maybe we
should create TemplateGenerator or something; just think its important to
have this or a similar Generator concept available. Reusing standard
generators in templates would be a cool feature. Maybe a wrapper class as
you suggested at the beginning of this discussion?

pi...@googlecode.com

unread,
Dec 3, 2010, 5:02:42 AM12/3/10
to piwi...@googlegroups.com

Comment #5 on issue 47 by danielpalme82: getGeneratorById should be public
http://code.google.com/p/piwi/issues/detail?id=47

The problem is, that the lifecycle is different. A generator within a
content file is transformed after execution. If you call it from a
template, the transformation is missing.

I would suggest a helper method/class to make clear what is happening.
That would avoid duplicated code within the templates and can be changed
more easily.

pi...@googlecode.com

unread,
Dec 3, 2010, 5:41:20 AM12/3/10
to piwi...@googlegroups.com

Comment #6 on issue 47 by grobme...@gmail.com: getGeneratorById should be
public
http://code.google.com/p/piwi/issues/detail?id=47

Yes understood the transformation problem. But we haven't defined that a
Generator is only producing piwi xml. It might be ok for a Generator to
produce plain html which might not be transformed

Reply all
Reply to author
Forward
0 new messages