Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | 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;
991 lars 17
use League\CommonMark\Exception\MissingDependencyException;
148 lars 18
use League\CommonMark\Extension\Embed\Embed;
19
use League\CommonMark\Extension\Embed\EmbedAdapterInterface;
20
 
21
final class OscaroteroEmbedAdapter implements EmbedAdapterInterface
22
{
23
    private EmbedLib $embedLib;
24
 
25
    public function __construct(?EmbedLib $embed = null)
26
    {
27
        if ($embed === null) {
28
            if (! \class_exists(EmbedLib::class)) {
991 lars 29
                throw new MissingDependencyException('The embed/embed package is not installed. Please install it with Composer to use this adapter.');
148 lars 30
            }
31
 
32
            $embed = new EmbedLib();
33
        }
34
 
35
        $this->embedLib = $embed;
36
    }
37
 
38
    /**
39
     * {@inheritDoc}
40
     */
41
    public function updateEmbeds(array $embeds): void
42
    {
43
        $extractors = $this->embedLib->getMulti(...\array_map(static fn (Embed $embed) => $embed->getUrl(), $embeds));
44
        foreach ($extractors as $i => $extractor) {
45
            if ($extractor->code !== null) {
46
                $embeds[$i]->setEmbedCode($extractor->code->html);
47
            }
48
        }
49
    }
50
}