8
8
use TypeLang \PHPDoc \DocBlock \Tag \Factory \MutableTagFactoryInterface ;
9
9
use TypeLang \PHPDoc \DocBlock \Tag \Factory \TagFactory ;
10
10
use TypeLang \PHPDoc \DocBlock \Tag \Factory \TagFactoryInterface ;
11
- use TypeLang \PHPDoc \DocBlock \Tag \MethodTag \MethodTagFactory ;
12
- use TypeLang \PHPDoc \DocBlock \Tag \ParamTag \ParamTagFactory ;
13
- use TypeLang \PHPDoc \DocBlock \Tag \PropertyTag \PropertyReadTagFactory ;
14
- use TypeLang \PHPDoc \DocBlock \Tag \PropertyTag \PropertyTagFactory ;
15
- use TypeLang \PHPDoc \DocBlock \Tag \PropertyTag \PropertyWriteTagFactory ;
16
- use TypeLang \PHPDoc \DocBlock \Tag \ReturnTag \ReturnTagFactory ;
17
- use TypeLang \PHPDoc \DocBlock \Tag \TemplateExtendsTag \TemplateExtendsTagFactory ;
18
- use TypeLang \PHPDoc \DocBlock \Tag \TemplateExtendsTag \TemplateImplementsTagFactory ;
19
- use TypeLang \PHPDoc \DocBlock \Tag \TemplateTag \TemplateCovariantTagFactory ;
20
- use TypeLang \PHPDoc \DocBlock \Tag \TemplateTag \TemplateTagFactory ;
21
- use TypeLang \PHPDoc \DocBlock \Tag \ThrowsTag \ThrowsTagFactory ;
22
- use TypeLang \PHPDoc \DocBlock \Tag \VarTag \VarTagFactory ;
23
11
use TypeLang \PHPDoc \Exception \ParsingException ;
24
12
use TypeLang \PHPDoc \Exception \RuntimeExceptionInterface ;
25
13
use TypeLang \PHPDoc \Parser \Comment \CommentParserInterface ;
30
18
use TypeLang \PHPDoc \Parser \SourceMap ;
31
19
use TypeLang \PHPDoc \Parser \Tag \RegexTagParser ;
32
20
use TypeLang \PHPDoc \Parser \Tag \TagParserInterface ;
21
+ use TypeLang \PHPDoc \Platform \PlatformInterface ;
22
+ use TypeLang \PHPDoc \Platform \StandardPlatform ;
33
23
34
24
class Parser implements ParserInterface
35
25
{
@@ -41,36 +31,28 @@ class Parser implements ParserInterface
41
31
42
32
private readonly MutableTagFactoryInterface $ factories ;
43
33
44
- /**
45
- * @param iterable<non-empty-string, TagFactoryInterface>|null $tags
46
- */
47
- public function __construct (?iterable $ tags = null )
34
+ public function __construct (
35
+ public readonly PlatformInterface $ platform = new StandardPlatform (),
36
+ ) {
37
+ $ this ->factories = new TagFactory ($ platform ->getTags ());
38
+ $ this ->tags = $ this ->createTagParser ($ this ->factories );
39
+ $ this ->descriptions = $ this ->createDescriptionParser ($ this ->tags );
40
+ $ this ->comments = $ this ->createCommentParser ();
41
+ }
42
+
43
+ protected function createTagParser (TagFactoryInterface $ factories ): TagParserInterface
48
44
{
49
- $ this ->factories = new TagFactory ($ tags ?? self ::createDefaultTags ());
50
- $ this ->tags = new RegexTagParser ($ this ->factories );
51
- $ this ->descriptions = new RegexDescriptionParser ($ this ->tags );
52
- $ this ->comments = new RegexCommentParser ();
45
+ return new RegexTagParser ($ factories );
53
46
}
54
47
55
- /**
56
- * @return iterable<non-empty-string, TagFactoryInterface>
57
- */
58
- private static function createDefaultTags (): iterable
48
+ protected function createDescriptionParser (TagParserInterface $ tags ): DescriptionParserInterface
49
+ {
50
+ return new RegexDescriptionParser ($ tags );
51
+ }
52
+
53
+ protected function createCommentParser (): CommentParserInterface
59
54
{
60
- yield 'method ' => new MethodTagFactory ();
61
- yield 'param ' => new ParamTagFactory ();
62
- yield 'property ' => new PropertyTagFactory ();
63
- yield 'property-read ' => new PropertyReadTagFactory ();
64
- yield 'property-write ' => new PropertyWriteTagFactory ();
65
- yield 'return ' => new ReturnTagFactory ();
66
- yield 'throws ' => new ThrowsTagFactory ();
67
- yield 'var ' => new VarTagFactory ();
68
- yield 'template ' => new TemplateTagFactory ();
69
- yield 'template-implements ' => $ implements = new TemplateImplementsTagFactory ();
70
- yield 'implements ' => $ implements ;
71
- yield 'template-extends ' => $ extends = new TemplateExtendsTagFactory ();
72
- yield 'extends ' => $ extends ;
73
- yield 'template-covariant ' => new TemplateCovariantTagFactory ();
55
+ return new RegexCommentParser ();
74
56
}
75
57
76
58
/**
0 commit comments