Skip to content

Extending an existing renderer #687

Answered by colinodell
nvayalil asked this question in Q&A
Discussion options

You must be logged in to vote

Most renderers have only one method - render(). If you were to extend a renderer (like MyImageRenderer extends ImageRenderer) you wouldn't be able to change the inside of the parent render() method. You should instead consider implementing the decorator design pattern:

final class MyImageRenderer implements InlineRendererInterface, ConfigurationAwareInterface
{
    private ImageRenderer $innerRenderer;

    public function __construct(ImageRenderer $imageRenderer)
    {
        $this->innerRenderer = $imageRenderer;
    }

    public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
    {
        if (!($inline instanceof Image)) {
            throw new \Inval…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by colinodell
Comment options

You must be logged in to vote
2 replies
@colinodell
Comment options

@nvayalil
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants