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
 * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
11
 *  - (c) John MacFarlane
12
 *
13
 * For the full copyright and license information, please view the LICENSE
14
 * file that was distributed with this source code.
15
 */
16
 
17
namespace League\CommonMark\Parser;
18
 
19
use League\CommonMark\Delimiter\DelimiterStack;
20
use League\CommonMark\Node\Block\AbstractBlock;
21
use League\CommonMark\Reference\ReferenceMapInterface;
22
 
23
final class InlineParserContext
24
{
25
    /** @psalm-readonly */
26
    private AbstractBlock $container;
27
 
28
    /** @psalm-readonly */
29
    private ReferenceMapInterface $referenceMap;
30
 
31
    /** @psalm-readonly */
32
    private Cursor $cursor;
33
 
34
    /** @psalm-readonly */
35
    private DelimiterStack $delimiterStack;
36
 
37
    /**
38
     * @var string[]
39
     * @psalm-var non-empty-array<string>
40
     *
41
     * @psalm-readonly-allow-private-mutation
42
     */
43
    private array $matches;
44
 
45
    public function __construct(Cursor $contents, AbstractBlock $container, ReferenceMapInterface $referenceMap)
46
    {
47
        $this->referenceMap   = $referenceMap;
48
        $this->container      = $container;
49
        $this->cursor         = $contents;
50
        $this->delimiterStack = new DelimiterStack();
51
    }
52
 
53
    public function getContainer(): AbstractBlock
54
    {
55
        return $this->container;
56
    }
57
 
58
    public function getReferenceMap(): ReferenceMapInterface
59
    {
60
        return $this->referenceMap;
61
    }
62
 
63
    public function getCursor(): Cursor
64
    {
65
        return $this->cursor;
66
    }
67
 
68
    public function getDelimiterStack(): DelimiterStack
69
    {
70
        return $this->delimiterStack;
71
    }
72
 
73
    /**
74
     * @return string The full text that matched the InlineParserMatch definition
75
     */
76
    public function getFullMatch(): string
77
    {
78
        return $this->matches[0];
79
    }
80
 
81
    /**
82
     * @return int The length of the full match (in characters, not bytes)
83
     */
84
    public function getFullMatchLength(): int
85
    {
86
        return \mb_strlen($this->matches[0], 'UTF-8');
87
    }
88
 
89
    /**
90
     * @return string[] Similar to preg_match(), index 0 will contain the full match, and any other array elements will be captured sub-matches
91
     *
92
     * @psalm-return non-empty-array<string>
93
     */
94
    public function getMatches(): array
95
    {
96
        return $this->matches;
97
    }
98
 
99
    /**
100
     * @return string[]
101
     */
102
    public function getSubMatches(): array
103
    {
104
        return \array_slice($this->matches, 1);
105
    }
106
 
107
    /**
108
     * @param string[] $matches
109
     *
110
     * @psalm-param non-empty-array<string> $matches
111
     */
112
    public function withMatches(array $matches): InlineParserContext
113
    {
114
        $ctx = clone $this;
115
 
116
        $ctx->matches = $matches;
117
 
118
        return $ctx;
119
    }
120
}