33namespace PHPCR \Util \CND \Parser ;
44
55use PHPCR \NodeType \NodeDefinitionTemplateInterface ;
6+ use PHPCR \NodeType \NodeTypeDefinitionInterface ;
67use PHPCR \NodeType \NodeTypeManagerInterface ;
78use PHPCR \NodeType \NodeTypeTemplateInterface ;
89use PHPCR \NodeType \PropertyDefinitionTemplateInterface ;
3233 * @author Daniel Barsotti <daniel.barsotti@liip.ch>
3334 * @author David Buchmann <mail@davidbu.ch>
3435 */
35- class CndParser extends AbstractParser
36+ final class CndParser extends AbstractParser
3637{
3738 // 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);
4445
4546 // 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 ' ];
5152
5253 // 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),
5758
5859 // child node attributes
5960 // multiple is actually a jackrabbit specific synonym for sns
6061 // 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),
6263
63- /**
64- * @var NodeTypeManagerInterface
65- */
66- private $ ntm ;
64+ private NodeTypeManagerInterface $ ntm ;
6765
6866 /**
69- * @var array
67+ * @var string[]
7068 */
71- protected $ namespaces = [];
69+ protected array $ namespaces = [];
7270
7371 /**
74- * @var array
72+ * @var string[]
7573 */
76- protected $ nodeTypes = [];
74+ protected array $ nodeTypes = [];
7775
7876 public function __construct (NodeTypeManagerInterface $ ntm )
7977 {
@@ -85,10 +83,9 @@ public function __construct(NodeTypeManagerInterface $ntm)
8583 *
8684 * @param string $filename absolute path to the CND file to read
8785 *
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>}
9087 */
91- public function parseFile ($ filename )
88+ public function parseFile (string $ filename ): array
9289 {
9390 $ reader = new FileReader ($ filename );
9491
@@ -100,17 +97,19 @@ public function parseFile($filename)
10097 *
10198 * @param string $cnd string with CND content
10299 *
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>}
105101 */
106- public function parseString ($ cnd )
102+ public function parseString (string $ cnd ): array
107103 {
108104 $ reader = new BufferReader ($ cnd );
109105
110106 return $ this ->parse ($ reader );
111107 }
112108
113- private function parse (ReaderInterface $ reader )
109+ /**
110+ * @return array{namespaces: string[], nodeTypes: array<string, NodeTypeDefinitionInterface>}
111+ */
112+ private function parse (ReaderInterface $ reader ): array
114113 {
115114 $ scanner = new GenericScanner (new DefaultScannerContextWithoutSpacesAndComments ());
116115 $ this ->tokenQueue = $ scanner ->scan ($ reader );
@@ -141,7 +140,7 @@ private function parse(ReaderInterface $reader)
141140 * Prefix ::= String
142141 * Uri ::= String
143142 */
144- protected function parseNamespaceMapping ()
143+ protected function parseNamespaceMapping (): void
145144 {
146145 $ this ->expectToken (Token::TK_SYMBOL , '< ' );
147146 $ prefix = $ this ->parseCndString ();
@@ -161,7 +160,7 @@ protected function parseNamespaceMapping()
161160 * [NodeTypeAttribute {NodeTypeAttribute}]
162161 * {PropertyDef | ChildNodeDef}
163162 */
164- protected function parseNodeType ()
163+ protected function parseNodeType (): void
165164 {
166165 $ nodeType = $ this ->ntm ->createNodeTypeTemplate ();
167166 $ this ->parseNodeTypeName ($ nodeType );
@@ -182,7 +181,7 @@ protected function parseNodeType()
182181 *
183182 * NodeTypeName ::= '[' String ']'
184183 */
185- protected function parseNodeTypeName (NodeTypeTemplateInterface $ nodeType )
184+ protected function parseNodeTypeName (NodeTypeTemplateInterface $ nodeType ): void
186185 {
187186 $ this ->expectToken (Token::TK_SYMBOL , '[ ' );
188187 $ name = $ this ->parseCndString ();
@@ -199,7 +198,7 @@ protected function parseNodeTypeName(NodeTypeTemplateInterface $nodeType)
199198 *
200199 * Supertypes ::= '>' (StringList | '?')
201200 */
202- protected function parseSupertypes (NodeTypeTemplateInterface $ nodeType )
201+ protected function parseSupertypes (NodeTypeTemplateInterface $ nodeType ): void
203202 {
204203 $ this ->expectToken (Token::TK_SYMBOL , '> ' );
205204
@@ -242,7 +241,7 @@ protected function parseSupertypes(NodeTypeTemplateInterface $nodeType)
242241 * Query ::= ('noquery' | 'nq') | ('query' | 'q' )
243242 * PrimaryItem ::= ('primaryitem'| '!')(String | '?')
244243 */
245- protected function parseNodeTypeAttributes (NodeTypeTemplateInterface $ nodeType )
244+ protected function parseNodeTypeAttributes (NodeTypeTemplateInterface $ nodeType ): void
246245 {
247246 while (true ) {
248247 if ($ this ->checkTokenIn (Token::TK_IDENTIFIER , $ this ->ORDERABLE )) {
@@ -283,7 +282,7 @@ protected function parseNodeTypeAttributes(NodeTypeTemplateInterface $nodeType)
283282 *
284283 * {PropertyDef | ChildNodeDef}
285284 */
286- protected function parseChildrenAndAttributes (NodeTypeTemplateInterface $ nodeType )
285+ protected function parseChildrenAndAttributes (NodeTypeTemplateInterface $ nodeType ): void
287286 {
288287 while (true ) {
289288 if ($ this ->checkToken (Token::TK_SYMBOL , '- ' )) {
@@ -309,7 +308,7 @@ protected function parseChildrenAndAttributes(NodeTypeTemplateInterface $nodeTyp
309308 * [ValueConstraints]
310309 * PropertyName ::= '-' String
311310 */
312- protected function parsePropDef (NodeTypeTemplateInterface $ nodeType )
311+ protected function parsePropDef (NodeTypeTemplateInterface $ nodeType ): void
313312 {
314313 $ this ->expectToken (Token::TK_SYMBOL , '- ' );
315314
@@ -363,7 +362,7 @@ protected function parsePropDef(NodeTypeTemplateInterface $nodeType)
363362 * 'DECIMAL' | 'URI' | 'UNDEFINED' | '*' |
364363 * '?') ')'
365364 */
366- protected function parsePropertyType (PropertyDefinitionTemplateInterface $ property )
365+ protected function parsePropertyType (PropertyDefinitionTemplateInterface $ property ): void
367366 {
368367 $ types = ['STRING ' , 'BINARY ' , 'LONG ' , 'DOUBLE ' , 'BOOLEAN ' , 'DATE ' , 'NAME ' , 'PATH ' ,
369368 'REFERENCE ' , 'WEAKREFERENCE ' , 'DECIMAL ' , 'URI ' , 'UNDEFINED ' , '* ' , '? ' , ];
@@ -387,7 +386,7 @@ protected function parsePropertyType(PropertyDefinitionTemplateInterface $proper
387386 *
388387 * DefaultValues ::= '=' (StringList | '?')
389388 */
390- protected function parseDefaultValue (PropertyDefinitionTemplateInterface $ property )
389+ protected function parseDefaultValue (PropertyDefinitionTemplateInterface $ property ): void
391390 {
392391 if ($ this ->checkAndExpectToken (Token::TK_SYMBOL , '? ' )) {
393392 $ list = ['? ' ];
@@ -405,7 +404,7 @@ protected function parseDefaultValue(PropertyDefinitionTemplateInterface $proper
405404 *
406405 * ValueConstraints ::= '<' (StringList | '?')
407406 */
408- protected function parseValueConstraints (PropertyDefinitionTemplateInterface $ property )
407+ protected function parseValueConstraints (PropertyDefinitionTemplateInterface $ property ): void
409408 {
410409 $ this ->expectToken (Token::TK_SYMBOL , '< ' );
411410
@@ -472,7 +471,7 @@ protected function parseValueConstraints(PropertyDefinitionTemplateInterface $pr
472471 * NoFullText ::= ('nofulltext' | 'nof') ['?']
473472 * NoQueryOrder ::= ('noqueryorder' | 'nqord') ['?']
474473 */
475- protected function parsePropertyAttributes (NodeTypeTemplateInterface $ parentType , PropertyDefinitionTemplateInterface $ property )
474+ protected function parsePropertyAttributes (NodeTypeTemplateInterface $ parentType , PropertyDefinitionTemplateInterface $ property ): void
476475 {
477476 $ opvSeen = false ;
478477 while (true ) {
@@ -526,7 +525,7 @@ protected function parsePropertyAttributes(NodeTypeTemplateInterface $parentType
526525 * RequiredTypes ::= '(' (StringList | '?') ')'
527526 * DefaultType ::= '=' (String | '?')
528527 */
529- protected function parseChildNodeDef (NodeTypeTemplateInterface $ nodeType )
528+ protected function parseChildNodeDef (NodeTypeTemplateInterface $ nodeType ): void
530529 {
531530 $ this ->expectToken (Token::TK_SYMBOL , '+ ' );
532531 $ childType = $ this ->ntm ->createNodeDefinitionTemplate ();
@@ -595,7 +594,7 @@ protected function parseChildNodeDef(NodeTypeTemplateInterface $nodeType)
595594 protected function parseChildNodeAttributes (
596595 NodeTypeTemplateInterface $ parentType ,
597596 NodeDefinitionTemplateInterface $ childType
598- ) {
597+ ): void {
599598 while (true ) {
600599 if ($ this ->checkTokenIn (Token::TK_IDENTIFIER , $ this ->PRIMARY )) {
601600 $ parentType ->setPrimaryItemName ($ childType ->getName ());
@@ -624,9 +623,9 @@ protected function parseChildNodeAttributes(
624623 *
625624 * StringList ::= String {',' String}
626625 *
627- * @return array
626+ * @return string[]
628627 */
629- protected function parseCndStringList ()
628+ protected function parseCndStringList (): array
630629 {
631630 $ strings = [];
632631
@@ -656,10 +655,8 @@ protected function parseCndStringList()
656655 * Char ::= "\t" | "\r" | "\n" | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
657656 *
658657 * TODO: check \n, \r, \t are valid in CND strings!
659- *
660- * @return string
661658 */
662- protected function parseCndString ()
659+ protected function parseCndString (): string
663660 {
664661 $ string = '' ;
665662 $ lastType = null ;
@@ -735,10 +732,8 @@ protected function parseQueryOpsAttribute()
735732
736733 /**
737734 * Parse a query operator.
738- *
739- * @return bool|string
740735 */
741- protected function parseQueryOperator ()
736+ protected function parseQueryOperator (): bool | string
742737 {
743738 $ token = $ this ->tokenQueue ->peek ();
744739 $ data = $ token ->getData ();
0 commit comments