Skip to content

Commit cb4e41e

Browse files
committed
cnd parser: mess between primary and primaryitem. allow lowercase property type names
1 parent eb3b2e2 commit cb4e41e

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/PHPCR/Util/CND/Parser/AbstractParser.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ abstract class AbstractParser
3232
*
3333
* @param int $type The expected token type
3434
* @param null|string $data The expected data or null
35+
* @param bool $ignoreCase whether to do string comparisons case insensitive or sensitive
3536
*
3637
* @return bool
3738
*/
38-
protected function checkToken($type, $data = null)
39+
protected function checkToken($type, $data = null, $ignoreCase = false)
3940
{
4041
if ($this->tokenQueue->isEof()) {
4142
return false;
@@ -48,6 +49,10 @@ protected function checkToken($type, $data = null)
4849
}
4950

5051
if ($data && $token->getData() !== $data) {
52+
if ($ignoreCase && is_string($data) && is_string($token->getData())) {
53+
return strcasecmp($data, $token->getData());
54+
}
55+
5156
return false;
5257
}
5358

@@ -62,10 +67,10 @@ protected function checkToken($type, $data = null)
6267
*
6368
* @return bool
6469
*/
65-
protected function checkTokenIn($type, array $data)
70+
protected function checkTokenIn($type, array $data, $ignoreCase = false)
6671
{
6772
foreach ($data as $d) {
68-
if ($this->checkToken($type, $d)) {
73+
if ($this->checkToken($type, $d, $ignoreCase)) {
6974
return true;
7075
}
7176
}

src/PHPCR/Util/CND/Parser/CndParser.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class CndParser extends AbstractParser
4141
private $PRIMARYITEM = array('primaryitem', '!');//, 'variant' => false);
4242

4343
// common for properties and child definitions
44+
private $PRIMARY = array('!', 'pri', 'primary'); //, 'variant' => true),
4445
private $AUTOCREATED = array('a', 'aut', 'autocreated'); //, 'variant' => true),
4546
private $MANDATORY = array('m', 'man', 'mandatory'); //, 'variant' => true),
4647
private $PROTECTED = array('p', 'pro', 'protected'); //, 'variant' => true),
@@ -343,7 +344,7 @@ protected function parsePropDef(NodeTypeTemplateInterface $nodeType)
343344
$this->parseDefaultValue($property);
344345
}
345346

346-
$this->parsePropertyAttributes($property);
347+
$this->parsePropertyAttributes($nodeType, $property);
347348

348349
// Check if there is a constraint (and not another namespace def)
349350
// Next token is '<' and two token later it's not '=', i.e. not '<ident='
@@ -370,7 +371,7 @@ protected function parsePropertyType(PropertyDefinitionTemplateInterface $proper
370371
$types = array("STRING", "BINARY", "LONG", "DOUBLE", "BOOLEAN", "DATE", "NAME", "PATH",
371372
"REFERENCE", "WEAKREFERENCE", "DECIMAL", "URI", "UNDEFINED", "*", "?");
372373

373-
if (! $this->checkTokenIn(Token::TK_IDENTIFIER, $types)) {
374+
if (! $this->checkTokenIn(Token::TK_IDENTIFIER, $types, true)) {
374375
throw new ParserException($this->tokenQueue, sprintf("Invalid property type: %s", $this->tokenQueue->get()->getData()));
375376
}
376377

@@ -474,11 +475,13 @@ protected function parseValueConstraints(PropertyDefinitionTemplateInterface $pr
474475
* NoFullText ::= ('nofulltext' | 'nof') ['?']
475476
* NoQueryOrder ::= ('noqueryorder' | 'nqord') ['?']
476477
*/
477-
protected function parsePropertyAttributes(PropertyDefinitionTemplateInterface $property)
478+
protected function parsePropertyAttributes(NodeTypeTemplateInterface $parentType, PropertyDefinitionTemplateInterface $property)
478479
{
479480
$opvSeen = false;
480481
while (true) {
481-
if ($this->checkTokenIn(Token::TK_IDENTIFIER, $this->AUTOCREATED)) {
482+
if ($this->checkTokenIn(Token::TK_IDENTIFIER, $this->PRIMARY)) {
483+
$parentType->setPrimaryItemName($property->getName());
484+
} else if ($this->checkTokenIn(Token::TK_IDENTIFIER, $this->AUTOCREATED)) {
482485
$property->setAutoCreated(true);
483486
} else if ($this->checkTokenIn(Token::TK_IDENTIFIER, $this->MANDATORY)) {
484487
$property->setMandatory(true);
@@ -597,7 +600,7 @@ protected function parseChildNodeAttributes(
597600
NodeDefinitionTemplateInterface $childType
598601
) {
599602
while(true) {
600-
if ($this->checkTokenIn(Token::TK_IDENTIFIER, $this->PRIMARYITEM)) {
603+
if ($this->checkTokenIn(Token::TK_IDENTIFIER, $this->PRIMARY)) {
601604
$parentType->setPrimaryItemName($childType->getName());
602605
} else if ($this->checkTokenIn(Token::TK_IDENTIFIER, $this->AUTOCREATED)) {
603606
$childType->setAutoCreated(true);

0 commit comments

Comments
 (0)