3
3
namespace PHPCR \Util \CND \Parser ;
4
4
5
5
use PHPCR \NodeType \NodeDefinitionTemplateInterface ;
6
+ use PHPCR \NodeType \NodeTypeDefinitionInterface ;
6
7
use PHPCR \NodeType \NodeTypeManagerInterface ;
7
8
use PHPCR \NodeType \NodeTypeTemplateInterface ;
8
9
use PHPCR \NodeType \PropertyDefinitionTemplateInterface ;
32
33
* @author Daniel Barsotti <daniel.barsotti@liip.ch>
33
34
* @author David Buchmann <mail@davidbu.ch>
34
35
*/
35
- class CndParser extends AbstractParser
36
+ final class CndParser extends AbstractParser
36
37
{
37
38
// node type attributes
38
- private $ ORDERABLE = ['o ' , 'ord ' , 'orderable ' ]; // , 'variant' => true);
39
- private $ MIXIN = ['m ' , 'mix ' , 'mixin ' ]; // , 'variant' => true);
40
- private $ ABSTRACT = ['a ' , 'abs ' , 'abstract ' ]; // , 'variant' => true);
41
- private $ NOQUERY = ['noquery ' , 'nq ' ]; // , 'variant' => false);
42
- private $ QUERY = ['query ' , 'q ' ]; // , 'variant' => false);
43
- private $ PRIMARYITEM = ['primaryitem ' , '! ' ]; // , 'variant' => false);
39
+ private array $ ORDERABLE = ['o ' , 'ord ' , 'orderable ' ]; // , 'variant' => true);
40
+ private array $ MIXIN = ['m ' , 'mix ' , 'mixin ' ]; // , 'variant' => true);
41
+ private array $ ABSTRACT = ['a ' , 'abs ' , 'abstract ' ]; // , 'variant' => true);
42
+ private array $ NOQUERY = ['noquery ' , 'nq ' ]; // , 'variant' => false);
43
+ private array $ QUERY = ['query ' , 'q ' ]; // , 'variant' => false);
44
+ private array $ PRIMARYITEM = ['primaryitem ' , '! ' ]; // , 'variant' => false);
44
45
45
46
// common for properties and child definitions
46
- private $ PRIMARY = ['! ' , 'pri ' , 'primary ' ]; // , 'variant' => true),
47
- private $ AUTOCREATED = ['a ' , 'aut ' , 'autocreated ' ]; // , 'variant' => true),
48
- private $ MANDATORY = ['m ' , 'man ' , 'mandatory ' ]; // , 'variant' => true),
49
- private $ PROTECTED = ['p ' , 'pro ' , 'protected ' ]; // , 'variant' => true),
50
- private $ OPV = ['COPY ' , 'VERSION ' , 'INITIALIZE ' , 'COMPUTE ' , 'IGNORE ' , 'ABORT ' ];
47
+ private array $ PRIMARY = ['! ' , 'pri ' , 'primary ' ]; // , 'variant' => true),
48
+ private array $ AUTOCREATED = ['a ' , 'aut ' , 'autocreated ' ]; // , 'variant' => true),
49
+ private array $ MANDATORY = ['m ' , 'man ' , 'mandatory ' ]; // , 'variant' => true),
50
+ private array $ PROTECTED = ['p ' , 'pro ' , 'protected ' ]; // , 'variant' => true),
51
+ private array $ OPV = ['COPY ' , 'VERSION ' , 'INITIALIZE ' , 'COMPUTE ' , 'IGNORE ' , 'ABORT ' ];
51
52
52
53
// property type attributes
53
- private $ MULTIPLE = ['* ' , 'mul ' , 'multiple ' ]; // , 'variant' => true),
54
- private $ QUERYOPS = ['qop ' , 'queryops ' ]; // , 'variant' => true), // Needs special handling !
55
- private $ NOFULLTEXT = ['nof ' , 'nofulltext ' ]; // , 'variant' => true),
56
- private $ NOQUERYORDER = ['nqord ' , 'noqueryorder ' ]; // , 'variant' => true),
54
+ private array $ MULTIPLE = ['* ' , 'mul ' , 'multiple ' ]; // , 'variant' => true),
55
+ private array $ QUERYOPS = ['qop ' , 'queryops ' ]; // , 'variant' => true), // Needs special handling !
56
+ private array $ NOFULLTEXT = ['nof ' , 'nofulltext ' ]; // , 'variant' => true),
57
+ private array $ NOQUERYORDER = ['nqord ' , 'noqueryorder ' ]; // , 'variant' => true),
57
58
58
59
// child node attributes
59
60
// multiple is actually a jackrabbit specific synonym for sns
60
61
// http://www.mail-archive.com/users@jackrabbit.apache.org/msg19268.html
61
- private $ SNS = ['* ' , 'sns ' , 'multiple ' ]; // , 'variant' => true),
62
+ private array $ SNS = ['* ' , 'sns ' , 'multiple ' ]; // , 'variant' => true),
62
63
63
- /**
64
- * @var NodeTypeManagerInterface
65
- */
66
- private $ ntm ;
64
+ private NodeTypeManagerInterface $ ntm ;
67
65
68
66
/**
69
- * @var array
67
+ * @var string[]
70
68
*/
71
- protected $ namespaces = [];
69
+ protected array $ namespaces = [];
72
70
73
71
/**
74
- * @var array
72
+ * @var string[]
75
73
*/
76
- protected $ nodeTypes = [];
74
+ protected array $ nodeTypes = [];
77
75
78
76
public function __construct (NodeTypeManagerInterface $ ntm )
79
77
{
@@ -85,10 +83,9 @@ public function __construct(NodeTypeManagerInterface $ntm)
85
83
*
86
84
* @param string $filename absolute path to the CND file to read
87
85
*
88
- * @return array with the namespaces map and the nodeTypes which is a
89
- * hashmap of typename = > NodeTypeDefinitionInterface
86
+ * @return array{namespaces: string[], nodeTypes: array<string, NodeTypeDefinitionInterface>}
90
87
*/
91
- public function parseFile ($ filename )
88
+ public function parseFile (string $ filename ): array
92
89
{
93
90
$ reader = new FileReader ($ filename );
94
91
@@ -100,17 +97,19 @@ public function parseFile($filename)
100
97
*
101
98
* @param string $cnd string with CND content
102
99
*
103
- * @return array with the namespaces map and the nodeTypes which is a
104
- * hashmap of typename = > NodeTypeDefinitionInterface
100
+ * @return array{namespaces: string[], nodeTypes: array<string, NodeTypeDefinitionInterface>}
105
101
*/
106
- public function parseString ($ cnd )
102
+ public function parseString (string $ cnd ): array
107
103
{
108
104
$ reader = new BufferReader ($ cnd );
109
105
110
106
return $ this ->parse ($ reader );
111
107
}
112
108
113
- private function parse (ReaderInterface $ reader )
109
+ /**
110
+ * @return array{namespaces: string[], nodeTypes: array<string, NodeTypeDefinitionInterface>}
111
+ */
112
+ private function parse (ReaderInterface $ reader ): array
114
113
{
115
114
$ scanner = new GenericScanner (new DefaultScannerContextWithoutSpacesAndComments ());
116
115
$ this ->tokenQueue = $ scanner ->scan ($ reader );
@@ -141,7 +140,7 @@ private function parse(ReaderInterface $reader)
141
140
* Prefix ::= String
142
141
* Uri ::= String
143
142
*/
144
- protected function parseNamespaceMapping ()
143
+ protected function parseNamespaceMapping (): void
145
144
{
146
145
$ this ->expectToken (Token::TK_SYMBOL , '< ' );
147
146
$ prefix = $ this ->parseCndString ();
@@ -161,7 +160,7 @@ protected function parseNamespaceMapping()
161
160
* [NodeTypeAttribute {NodeTypeAttribute}]
162
161
* {PropertyDef | ChildNodeDef}
163
162
*/
164
- protected function parseNodeType ()
163
+ protected function parseNodeType (): void
165
164
{
166
165
$ nodeType = $ this ->ntm ->createNodeTypeTemplate ();
167
166
$ this ->parseNodeTypeName ($ nodeType );
@@ -182,7 +181,7 @@ protected function parseNodeType()
182
181
*
183
182
* NodeTypeName ::= '[' String ']'
184
183
*/
185
- protected function parseNodeTypeName (NodeTypeTemplateInterface $ nodeType )
184
+ protected function parseNodeTypeName (NodeTypeTemplateInterface $ nodeType ): void
186
185
{
187
186
$ this ->expectToken (Token::TK_SYMBOL , '[ ' );
188
187
$ name = $ this ->parseCndString ();
@@ -199,7 +198,7 @@ protected function parseNodeTypeName(NodeTypeTemplateInterface $nodeType)
199
198
*
200
199
* Supertypes ::= '>' (StringList | '?')
201
200
*/
202
- protected function parseSupertypes (NodeTypeTemplateInterface $ nodeType )
201
+ protected function parseSupertypes (NodeTypeTemplateInterface $ nodeType ): void
203
202
{
204
203
$ this ->expectToken (Token::TK_SYMBOL , '> ' );
205
204
@@ -242,7 +241,7 @@ protected function parseSupertypes(NodeTypeTemplateInterface $nodeType)
242
241
* Query ::= ('noquery' | 'nq') | ('query' | 'q' )
243
242
* PrimaryItem ::= ('primaryitem'| '!')(String | '?')
244
243
*/
245
- protected function parseNodeTypeAttributes (NodeTypeTemplateInterface $ nodeType )
244
+ protected function parseNodeTypeAttributes (NodeTypeTemplateInterface $ nodeType ): void
246
245
{
247
246
while (true ) {
248
247
if ($ this ->checkTokenIn (Token::TK_IDENTIFIER , $ this ->ORDERABLE )) {
@@ -283,7 +282,7 @@ protected function parseNodeTypeAttributes(NodeTypeTemplateInterface $nodeType)
283
282
*
284
283
* {PropertyDef | ChildNodeDef}
285
284
*/
286
- protected function parseChildrenAndAttributes (NodeTypeTemplateInterface $ nodeType )
285
+ protected function parseChildrenAndAttributes (NodeTypeTemplateInterface $ nodeType ): void
287
286
{
288
287
while (true ) {
289
288
if ($ this ->checkToken (Token::TK_SYMBOL , '- ' )) {
@@ -309,7 +308,7 @@ protected function parseChildrenAndAttributes(NodeTypeTemplateInterface $nodeTyp
309
308
* [ValueConstraints]
310
309
* PropertyName ::= '-' String
311
310
*/
312
- protected function parsePropDef (NodeTypeTemplateInterface $ nodeType )
311
+ protected function parsePropDef (NodeTypeTemplateInterface $ nodeType ): void
313
312
{
314
313
$ this ->expectToken (Token::TK_SYMBOL , '- ' );
315
314
@@ -363,7 +362,7 @@ protected function parsePropDef(NodeTypeTemplateInterface $nodeType)
363
362
* 'DECIMAL' | 'URI' | 'UNDEFINED' | '*' |
364
363
* '?') ')'
365
364
*/
366
- protected function parsePropertyType (PropertyDefinitionTemplateInterface $ property )
365
+ protected function parsePropertyType (PropertyDefinitionTemplateInterface $ property ): void
367
366
{
368
367
$ types = ['STRING ' , 'BINARY ' , 'LONG ' , 'DOUBLE ' , 'BOOLEAN ' , 'DATE ' , 'NAME ' , 'PATH ' ,
369
368
'REFERENCE ' , 'WEAKREFERENCE ' , 'DECIMAL ' , 'URI ' , 'UNDEFINED ' , '* ' , '? ' , ];
@@ -387,7 +386,7 @@ protected function parsePropertyType(PropertyDefinitionTemplateInterface $proper
387
386
*
388
387
* DefaultValues ::= '=' (StringList | '?')
389
388
*/
390
- protected function parseDefaultValue (PropertyDefinitionTemplateInterface $ property )
389
+ protected function parseDefaultValue (PropertyDefinitionTemplateInterface $ property ): void
391
390
{
392
391
if ($ this ->checkAndExpectToken (Token::TK_SYMBOL , '? ' )) {
393
392
$ list = ['? ' ];
@@ -405,7 +404,7 @@ protected function parseDefaultValue(PropertyDefinitionTemplateInterface $proper
405
404
*
406
405
* ValueConstraints ::= '<' (StringList | '?')
407
406
*/
408
- protected function parseValueConstraints (PropertyDefinitionTemplateInterface $ property )
407
+ protected function parseValueConstraints (PropertyDefinitionTemplateInterface $ property ): void
409
408
{
410
409
$ this ->expectToken (Token::TK_SYMBOL , '< ' );
411
410
@@ -472,7 +471,7 @@ protected function parseValueConstraints(PropertyDefinitionTemplateInterface $pr
472
471
* NoFullText ::= ('nofulltext' | 'nof') ['?']
473
472
* NoQueryOrder ::= ('noqueryorder' | 'nqord') ['?']
474
473
*/
475
- protected function parsePropertyAttributes (NodeTypeTemplateInterface $ parentType , PropertyDefinitionTemplateInterface $ property )
474
+ protected function parsePropertyAttributes (NodeTypeTemplateInterface $ parentType , PropertyDefinitionTemplateInterface $ property ): void
476
475
{
477
476
$ opvSeen = false ;
478
477
while (true ) {
@@ -526,7 +525,7 @@ protected function parsePropertyAttributes(NodeTypeTemplateInterface $parentType
526
525
* RequiredTypes ::= '(' (StringList | '?') ')'
527
526
* DefaultType ::= '=' (String | '?')
528
527
*/
529
- protected function parseChildNodeDef (NodeTypeTemplateInterface $ nodeType )
528
+ protected function parseChildNodeDef (NodeTypeTemplateInterface $ nodeType ): void
530
529
{
531
530
$ this ->expectToken (Token::TK_SYMBOL , '+ ' );
532
531
$ childType = $ this ->ntm ->createNodeDefinitionTemplate ();
@@ -595,7 +594,7 @@ protected function parseChildNodeDef(NodeTypeTemplateInterface $nodeType)
595
594
protected function parseChildNodeAttributes (
596
595
NodeTypeTemplateInterface $ parentType ,
597
596
NodeDefinitionTemplateInterface $ childType
598
- ) {
597
+ ): void {
599
598
while (true ) {
600
599
if ($ this ->checkTokenIn (Token::TK_IDENTIFIER , $ this ->PRIMARY )) {
601
600
$ parentType ->setPrimaryItemName ($ childType ->getName ());
@@ -624,9 +623,9 @@ protected function parseChildNodeAttributes(
624
623
*
625
624
* StringList ::= String {',' String}
626
625
*
627
- * @return array
626
+ * @return string[]
628
627
*/
629
- protected function parseCndStringList ()
628
+ protected function parseCndStringList (): array
630
629
{
631
630
$ strings = [];
632
631
@@ -656,10 +655,8 @@ protected function parseCndStringList()
656
655
* Char ::= "\t" | "\r" | "\n" | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
657
656
*
658
657
* TODO: check \n, \r, \t are valid in CND strings!
659
- *
660
- * @return string
661
658
*/
662
- protected function parseCndString ()
659
+ protected function parseCndString (): string
663
660
{
664
661
$ string = '' ;
665
662
$ lastType = null ;
@@ -735,10 +732,8 @@ protected function parseQueryOpsAttribute()
735
732
736
733
/**
737
734
* Parse a query operator.
738
- *
739
- * @return bool|string
740
735
*/
741
- protected function parseQueryOperator ()
736
+ protected function parseQueryOperator (): bool | string
742
737
{
743
738
$ token = $ this ->tokenQueue ->peek ();
744
739
$ data = $ token ->getData ();
0 commit comments