mercredi 25 février 2015

Passing an iterative object reference to the factory in PHP?

I have a class that takes some basic HTML5 and with some DOM magic turns it into a class which is an extension simpleXMLElement.


Thus we might have



<?php
$MyPage = new XPage($HTML);


So far so good. What I now need to do is select some parts of the XML doc so that they can be "bookmarked" (I am sure that there is a better name for it) so one can go like this



$MyPage->ThatBit("foo")->addChild('p',$MyParagraph);


Ideally I would like to be able to go



$MyPage->page()->body->header->RememberThisBitAs("foo");


Or something intuitively similar. The idea being that the most commonly access areas can be gotten to more smoothly.


However it is the XPage class that holds the array of "bookmarks" which would leave me doing nasty things like



$MyPage->addBookmark("foo",
$MyPage->page()->body->header->getChildren() );


Which just does not seem right.


or



$MyPage->page()->body->header->RememberThisBitAs("foo",$MyPage);


which is not so bad but still "feels" wrong.


How do I approach this without excessive object coupling or ugly self referencing?


Aucun commentaire:

Enregistrer un commentaire