Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
/*
6
 * This file is part of the league/commonmark package.
7
 *
8
 * (c) Colin O'Dell <colinodell@gmail.com>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
 
14
namespace League\CommonMark\Extension\Embed\Bridge;
15
 
16
use Embed\Embed as EmbedLib;
17
use League\CommonMark\Extension\Embed\Embed;
18
use League\CommonMark\Extension\Embed\EmbedAdapterInterface;
19
 
20
final class OscaroteroEmbedAdapter implements EmbedAdapterInterface
21
{
22
    private EmbedLib $embedLib;
23
 
24
    public function __construct(?EmbedLib $embed = null)
25
    {
26
        if ($embed === null) {
27
            if (! \class_exists(EmbedLib::class)) {
28
                throw new \RuntimeException('The embed/embed package is not installed. Please install it with Composer to use this adapter.');
29
            }
30
 
31
            $embed = new EmbedLib();
32
        }
33
 
34
        $this->embedLib = $embed;
35
    }
36
 
37
    /**
38
     * {@inheritDoc}
39
     */
40
    public function updateEmbeds(array $embeds): void
41
    {
42
        $extractors = $this->embedLib->getMulti(...\array_map(static fn (Embed $embed) => $embed->getUrl(), $embeds));
43
        foreach ($extractors as $i => $extractor) {
44
            if ($extractor->code !== null) {
45
                $embeds[$i]->setEmbedCode($extractor->code->html);
46
            }
47
        }
48
    }
49
}