Closed Art4 closed 9 years ago
CodeDefinition::setTagName()
was deprecated in a shift to make CodeDefinition
objects immutable. They should be constructed through a CodeDefinitionBuilder
and then never modified. There's no way to achieve aliasing currently, but I'll look into how it might be added.
You could easily add the tag name property as a constructor parameter for your CodeDefinition class:
class Definition_Video extends JBBCode\CodeDefinition
{
public function __construct($tagName = 'video')
{
parent::__construct();
$this->setTagName($tagName);
}
}
Now just create two instances of Definition_Video
with different tag names:
$parser->addCodeDefinition(new Definition_Video());
$parser->addCodeDefinition(new Definition_Video('youtube'));
I didn't test this, but it should work fine.
CodeDefinition::setTagName()
was misleading here, because it changed the tag name of the same CodeDefinition
instance. Hence, it changed the tag name, not returned a new instance with a different tag name.
It is cleaner to define the tag name once per instance in the constructor, so that each instance is immutable after construction.
Hi,
I have created a class
Definition_Video
extendingCodeDefinition
to support the [video] tag. TheDefinition_Video
parse urls from vimeo.com, dailymotion.com and youtube.com.Now I want support the [youtube] tag for BC and I created the
Definition_Youtube
class:and add the classes to the parser.
This works fine for me, but I have a lot more tag aliases and have to create a lot of classes. I wish to do something like this:
I have also seen the deprecated
CodeDefinition::setTagName()
method, that allows easy aliasing as well:Is there a reason why
CodeDefinition::setTagName()
method is marked as deprecated? Or is it possible to add an aliasing funtionality?