1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the league/commonmark-ext-smartpunct package. |
5
|
|
|
* |
6
|
|
|
* (c) Colin O'Dell <[email protected]> |
7
|
|
|
* |
8
|
|
|
* Original code based on the CommonMark JS reference parser (http://bitly.com/commonmark-js) |
9
|
|
|
* - (c) John MacFarlane |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please view the LICENSE |
12
|
|
|
* file that was distributed with this source code. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace League\CommonMark\Ext\SmartPunct; |
16
|
|
|
|
17
|
|
|
use League\CommonMark\Delimiter\DelimiterInterface; |
18
|
|
|
use League\CommonMark\Delimiter\Processor\DelimiterProcessorInterface; |
19
|
|
|
use League\CommonMark\Extension\SmartPunct\Quote; |
|
|
|
|
20
|
|
|
use League\CommonMark\Extension\SmartPunct\QuoteProcessor as CoreProcessor; |
21
|
|
|
use League\CommonMark\Inline\Element\AbstractStringContainer; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @deprecated The league/commonmark-ext-smartpunct extension is now deprecated. All functionality has been moved into league/commonmark 1.3+, so use that instead. |
25
|
|
|
*/ |
26
|
|
|
final class QuoteProcessor implements DelimiterProcessorInterface |
27
|
|
|
{ |
28
|
|
|
/** @var CoreProcessor */ |
29
|
|
|
private $coreProcessor; |
30
|
|
|
|
31
|
4 |
|
private function __construct(CoreProcessor $coreProcessor) |
32
|
|
|
{ |
33
|
4 |
|
@trigger_error(sprintf('league/commonmark-ext-external-link is deprecated; use %s from league/commonmark 1.3+ instead', CoreProcessor::class), E_USER_DEPRECATED); |
|
|
|
|
34
|
4 |
|
$this->coreProcessor = $coreProcessor; |
35
|
4 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
4 |
|
public function getOpeningCharacter(): string |
41
|
|
|
{ |
42
|
4 |
|
return $this->coreProcessor->getOpeningCharacter(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
4 |
|
public function getClosingCharacter(): string |
49
|
|
|
{ |
50
|
4 |
|
return $this->coreProcessor->getClosingCharacter(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
4 |
|
public function getMinLength(): int |
57
|
|
|
{ |
58
|
4 |
|
return $this->coreProcessor->getMinLength(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
4 |
|
public function getDelimiterUse(DelimiterInterface $opener, DelimiterInterface $closer): int |
65
|
|
|
{ |
66
|
4 |
|
return $this->coreProcessor->getDelimiterUse($opener, $closer); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritdoc} |
71
|
|
|
*/ |
72
|
4 |
|
public function process(AbstractStringContainer $opener, AbstractStringContainer $closer, int $delimiterUse) |
73
|
|
|
{ |
74
|
4 |
|
return $this->coreProcessor->process($opener, $closer, $delimiterUse); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Create a double-quote processor |
79
|
|
|
* |
80
|
|
|
* @param string $opener |
81
|
|
|
* @param string $closer |
82
|
|
|
* |
83
|
|
|
* @return QuoteProcessor |
84
|
|
|
*/ |
85
|
2 |
|
public static function createDoubleQuoteProcessor(string $opener = Quote::DOUBLE_QUOTE_OPENER, string $closer = Quote::DOUBLE_QUOTE_CLOSER): self |
86
|
|
|
{ |
87
|
2 |
|
return new self(CoreProcessor::createDoubleQuoteProcessor($opener, $closer)); |
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Create a single-quote processor |
92
|
|
|
* |
93
|
|
|
* @param string $opener |
94
|
|
|
* @param string $closer |
95
|
|
|
* |
96
|
|
|
* @return QuoteProcessor |
97
|
|
|
*/ |
98
|
2 |
|
public static function createSingleQuoteProcessor(string $opener = Quote::SINGLE_QUOTE_OPENER, string $closer = Quote::SINGLE_QUOTE_CLOSER): self |
99
|
|
|
{ |
100
|
2 |
|
return new self(CoreProcessor::createSingleQuoteProcessor($opener, $closer)); |
|
|
|
|
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: