Subversion-Projekte lars-tiefland.laravel_shop

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;
15
 
16
use League\CommonMark\Environment\EnvironmentBuilderInterface;
17
use League\CommonMark\Event\DocumentParsedEvent;
18
use League\CommonMark\Extension\ConfigurableExtensionInterface;
19
use League\Config\ConfigurationBuilderInterface;
20
use Nette\Schema\Expect;
21
 
22
final class EmbedExtension implements ConfigurableExtensionInterface
23
{
24
    public function configureSchema(ConfigurationBuilderInterface $builder): void
25
    {
26
        $builder->addSchema('embed', Expect::structure([
27
            'adapter' => Expect::type(EmbedAdapterInterface::class),
28
            'allowed_domains' => Expect::arrayOf('string')->default([]),
29
            'fallback' => Expect::anyOf('link', 'remove')->default('link'),
30
        ]));
31
    }
32
 
33
    public function register(EnvironmentBuilderInterface $environment): void
34
    {
35
        $adapter = $environment->getConfiguration()->get('embed.adapter');
36
        \assert($adapter instanceof EmbedAdapterInterface);
37
 
38
        $allowedDomains = $environment->getConfiguration()->get('embed.allowed_domains');
39
        if ($allowedDomains !== []) {
40
            $adapter = new DomainFilteringAdapter($adapter, $allowedDomains);
41
        }
42
 
43
        $environment
44
            ->addBlockStartParser(new EmbedStartParser(), 300)
45
            ->addEventListener(DocumentParsedEvent::class, new EmbedProcessor($adapter, $environment->getConfiguration()->get('embed.fallback')), 1010)
46
            ->addRenderer(Embed::class, new EmbedRenderer());
47
    }
48
}