MermaidInk.php
| 1 | <?php |
| 2 | /** |
| 3 | * MermaidInk.php |
| 4 | * |
| 5 | * @package Embera |
| 6 | * @author Michael Pratt <yo@michael-pratt.com> |
| 7 | * @link http://www.michael-pratt.com/ |
| 8 | * |
| 9 | * For the full copyright and license information, please view the LICENSE |
| 10 | * file that was distributed with this source code. |
| 11 | */ |
| 12 | |
| 13 | namespace Embera\Provider; |
| 14 | |
| 15 | use Embera\Url; |
| 16 | |
| 17 | /** |
| 18 | * MermaidInk Provider |
| 19 | * @link https://mermaid.ink |
| 20 | */ |
| 21 | class MermaidInk extends ProviderAdapter implements ProviderInterface |
| 22 | { |
| 23 | /** inline {@inheritdoc} */ |
| 24 | protected $endpoint = 'https://mermaid.ink/services/oembed?format=json'; |
| 25 | |
| 26 | /** inline {@inheritdoc} */ |
| 27 | protected static $hosts = [ |
| 28 | 'mermaid.ink' |
| 29 | ]; |
| 30 | |
| 31 | /** inline {@inheritdoc} */ |
| 32 | protected $httpsSupport = true; |
| 33 | |
| 34 | /** inline {@inheritdoc} */ |
| 35 | protected $responsiveSupport = false; |
| 36 | |
| 37 | /** inline {@inheritdoc} */ |
| 38 | public function validateUrl(Url $url) |
| 39 | { |
| 40 | return (bool) (preg_match('~mermaid\.ink/(img|svg)/([^/]+)~i', (string) $url)); |
| 41 | } |
| 42 | |
| 43 | /** inline {@inheritdoc} */ |
| 44 | public function normalizeUrl(Url $url) |
| 45 | { |
| 46 | $url->convertToHttps(); |
| 47 | |
| 48 | return $url; |
| 49 | } |
| 50 | |
| 51 | /** inline {@inheritdoc} */ |
| 52 | public function modifyResponse(array $response = []) |
| 53 | { |
| 54 | |
| 55 | if (empty($response['html']) && !empty($response['url'])) { |
| 56 | $response['html'] = '<img src="' . $response['url'] . '" alt="" title="" >'; |
| 57 | } |
| 58 | |
| 59 | return $response; |
| 60 | } |
| 61 | |
| 62 | } |
| 63 |