I searching for a best practice in the Iterator interface of PHP.
Imagine I have a Menu with different Items. For each of the Items I can turn on or off the visibilty. Do you know a good place to place this filter? I thought about the Iterator::rewind() Method to do a seperate loop but dislike the fact of looping through the items a second time.
I think I see the wood for the trees. Hope you can help.
Have a look at the abstrakt FilterIterator class. Would look something like
This way you also separate the menu from the filter, what makes it easier to replace the filter, if you want to change it.