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\Parser\Block;
15
 
16
use League\CommonMark\Parser\Cursor;
17
use League\CommonMark\Parser\CursorState;
18
 
19
/**
20
 * Result object for starting parsing of a block; see static methods for constructors
21
 */
22
final class BlockStart
23
{
24
    /**
25
     * @var BlockContinueParserInterface[]
26
     *
27
     * @psalm-readonly
28
     */
29
    private array $blockParsers;
30
 
31
    /** @psalm-readonly-allow-private-mutation */
32
    private ?CursorState $cursorState = null;
33
 
34
    /** @psalm-readonly-allow-private-mutation */
35
    private bool $replaceActiveBlockParser = false;
36
 
37
    private bool $isAborting = false;
38
 
39
    private function __construct(BlockContinueParserInterface ...$blockParsers)
40
    {
41
        $this->blockParsers = $blockParsers;
42
    }
43
 
44
    /**
45
     * @return BlockContinueParserInterface[]
46
     */
47
    public function getBlockParsers(): iterable
48
    {
49
        return $this->blockParsers;
50
    }
51
 
52
    public function getCursorState(): ?CursorState
53
    {
54
        return $this->cursorState;
55
    }
56
 
57
    public function isReplaceActiveBlockParser(): bool
58
    {
59
        return $this->replaceActiveBlockParser;
60
    }
61
 
62
    /**
63
     * @internal
64
     */
65
    public function isAborting(): bool
66
    {
67
        return $this->isAborting;
68
    }
69
 
70
    /**
71
     * Signal that we want to parse at the given cursor position
72
     *
73
     * @return $this
74
     */
75
    public function at(Cursor $cursor): self
76
    {
77
        $this->cursorState = $cursor->saveState();
78
 
79
        return $this;
80
    }
81
 
82
    /**
83
     * Signal that we want to replace the active block parser with this one
84
     *
85
     * @return $this
86
     */
87
    public function replaceActiveBlockParser(): self
88
    {
89
        $this->replaceActiveBlockParser = true;
90
 
91
        return $this;
92
    }
93
 
94
    /**
95
     * Signal that we cannot parse whatever is here
96
     *
97
     * @return null
98
     */
99
    public static function none(): ?self
100
    {
101
        return null;
102
    }
103
 
104
    /**
105
     * Signal that we'd like to register the given parser(s) so they can parse the current block
106
     */
107
    public static function of(BlockContinueParserInterface ...$blockParsers): self
108
    {
109
        return new self(...$blockParsers);
110
    }
111
 
112
    /**
113
     * Signal that the block parsing process should be aborted (no other block starts should be checked)
114
     *
115
     * @internal
116
     */
117
    public static function abort(): self
118
    {
119
        $ret             = new self();
120
        $ret->isAborting = true;
121
 
122
        return $ret;
123
    }
124
}