Getting list of all CodeDefinitions
I needed list of all code definitions Parser can handle, but could not find a way to get it.
I suggest expanding class Parser with something like this:
public function getCodeDefinitions() {
return $this->bbcodes;
}
It wouldn't be bad, but I suggest a little change to your patch:
-public function getCodeDefinitions() {
+public function getCodeDefinitions() : CodeDefinitionSet {
return $this->bbcodes;
}
And then let CodeDefinitionSet interface extend the IteratorAggregate interface, create a base abstract class implementing Iterator and CodeDefinitionSet interfaces, and let IteratorAggregate::getIterator() return $this. Oh, this is pretty theorethical and I think really impossible. Oh, hell.
But it would be beatiful code :-) I will take a look at it when I have some time.
But it would be beatiful code :-)
@Kubo2 Really? This sounds a bit like "let's use SPL for the sake of having used SPL"
When I was working on the parser, I've been tempted to let it implement an iterator interface, which would make sense to some degree. But in the end I found this to bring little advantage while introducing bc-breaking api changes.
It may still be worth to let nodes and nodevisitors implement \SplSubject and \SplObserver once a major release is in sight.
Well, then maybe it would be a good solution to create getter methods on the CodeDefinition class. For now, you could probably just extend the CodeDefinition class and __construct it with a CodeDefinition object as an argument:
o = $o; } function getA() { return $this->a; } function getB() { return $this->b; } } You get the idea, hope it helps for now. Kubis On 15-Mar-2017 9:34 am, "pedjas"
Actually, there is getter for Tag name: getTagName(); I did not notice it before, my bad.