1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the league/commonmark 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\Extension; |
16
|
|
|
|
17
|
|
|
use League\CommonMark\Block\Renderer as BlockRenderer; |
18
|
|
|
use League\CommonMark\Inline\Parser as InlineParser; |
19
|
|
|
use League\CommonMark\Inline\Processor as InlineProcessor; |
20
|
|
|
use League\CommonMark\Inline\Renderer as InlineRenderer; |
21
|
|
|
|
22
|
|
|
class SmartPunctExtension extends Extension |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @return InlineParser\InlineParserInterface[] |
26
|
|
|
*/ |
27
|
45 |
|
public function getInlineParsers() |
28
|
|
|
{ |
29
|
|
|
return [ |
30
|
45 |
|
new InlineParser\QuoteParser(), |
31
|
45 |
|
new InlineParser\SmartPunctParser(), |
32
|
45 |
|
]; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return InlineProcessor\InlineProcessorInterface[] |
37
|
|
|
*/ |
38
|
45 |
|
public function getInlineProcessors() |
39
|
|
|
{ |
40
|
|
|
return [ |
41
|
45 |
|
new InlineProcessor\QuoteProcessor(), |
42
|
45 |
|
]; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return BlockRenderer\BlockRendererInterface[] |
47
|
|
|
*/ |
48
|
45 |
|
public function getBlockRenderers() |
49
|
|
|
{ |
50
|
|
|
return [ |
51
|
45 |
|
'League\CommonMark\Block\Element\Document' => new BlockRenderer\DocumentRenderer(), |
52
|
45 |
|
'League\CommonMark\Block\Element\Paragraph' => new BlockRenderer\ParagraphRenderer(), |
53
|
45 |
|
]; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return InlineRenderer\InlineRendererInterface[] |
58
|
|
|
*/ |
59
|
45 |
|
public function getInlineRenderers() |
60
|
|
|
{ |
61
|
|
|
return [ |
|
|
|
|
62
|
45 |
|
'League\CommonMark\Inline\Element\Text' => new InlineRenderer\TextRenderer(), |
63
|
45 |
|
]; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.