jBBCode icon indicating copy to clipboard operation
jBBCode copied to clipboard

Getting list of all CodeDefinitions

Open pedjas opened this issue 10 years ago • 4 comments

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;
}

pedjas avatar Jun 03 '15 17:06 pedjas

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.

Kubo2 avatar Jun 11 '15 18:06 Kubo2

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.

DaSourcerer avatar Jun 12 '15 13:06 DaSourcerer

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" wrote: I am still on this issue. I've created custom class that inherits Parser, and added this method to get list of BBC. Well I got the array if CodeDefinition but all properties are protected so I cannot access information about BBC. I need this so I can display list of supported codes to the user and allow him to insert bbcode by clicking its name. I need at least BBC name to be visible. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub , or mute the thread .

Kubo2 avatar Mar 15 '17 08:03 Kubo2

Actually, there is getter for Tag name: getTagName(); I did not notice it before, my bad.

pedjas avatar Mar 15 '17 09:03 pedjas