Re: Question about OpenDocument API development
| From: | Michael Gauthier | Date: | Wed, 24 Jun 2009 03:05:59 +0000 |
| Subject: | Re: Question about OpenDocument API development | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-52041@lists.php.net to get a copy of this message | ||
On Tue, 2009-06-23 at 07:45 +0200, Christian Weiske wrote:
> Hi all,
>
>
> I'm making progress in understanding the OpenDocument package, reorganizing it and fixing
> bugs in it. While tinkering with new content types (e.g. lists and images), I found that he current
> API approach does not suffice. Let me explain:
>
> - class OpenDocument_Text has two methods regarding adding content: createHeading and
> createParagraph
> - OpenDocument_Element_Paragraph has createSpan, createHyperlink, createText
> - OpenDocument_Element_Heading has createSpan, createHyperlink, createText
> - all of them should support createBookmark which they don't do yet. Potentially all of
> them will be able to get images added to.
>
> Currently, every single element class (+ the opendocument one) implements the create*() methods
> itself, redirecting the calls to the element::instance() methods. What I don't like is that,
> when adding support for a new element - e.g. lists - I have to do this in every single element class
> that supports it!
>
> So there needs to be a better way - for example using __call and throwing exceptions in the
> cases the element-to-be-created is not supported. I could also try to find class hierarchies with
> elements that are supported in certain classes only, and base them all off a common element class.
> The problem with that approach is that I don't know yet if that hierarchy is tree-like or not.
> I could also do take the quickform approach and use a general create('elementtype',
> $params) function - as flexible as __call, but not very usable from a user's point of view in
> regard of capturing the supported parameters.
>
> What would you do?
>
>From your quick examples, it looks like the dependency chain will have a
lot of loops (text->createHeading, heading->createText). A class
hierarchy might not work in this case.
Instead, I would suggest something like the following mockup:
http://labs.silverorange.com/files/OpenDocument/class-mockup.phps
Each element would have a corresponding creator class. Each element
class would also define a list of supported creators and the correct one
is called using __call().
I haven't looked at OpenDocument's code at all, so I may just be spouting crazy talk!
Cheers,
Mike