thunderer/Shortcode

View on GitHub
src/Handler/UrlHandler.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php
namespace Thunder\Shortcode\Handler;

use Thunder\Shortcode\Shortcode\ShortcodeInterface;

/**
 * @author Tomasz Kowalczyk <tomasz@kowalczyk.cc>
 */
final class UrlHandler
{
    /**
     * [url="http://example.org"]Click![/url]
     * [url="http://example.org" /]
     * [url]http://example.org[/url]
     *
     * @param ShortcodeInterface $shortcode
     *
     * @return string
     */
    public function __invoke(ShortcodeInterface $shortcode)
    {
        $url = $shortcode->getBbCode() ?: $shortcode->getContent();

        return '<a href="'.(string)$url.'">'.(string)$shortcode->getContent().'</a>';
    }
}