|
13 | 13 | use PHPCR\Query\QOM\EquiJoinConditionInterface;
|
14 | 14 | use PHPCR\Query\QOM\FullTextSearchInterface;
|
15 | 15 | use PHPCR\Query\QOM\JoinConditionInterface;
|
16 |
| -use PHPCR\Query\QOM\LiteralInterface; |
| 16 | +use PHPCR\Query\QOM\JoinInterface; |
17 | 17 | use PHPCR\Query\QOM\NotInterface;
|
| 18 | +use PHPCR\Query\QOM\OrderingInterface; |
18 | 19 | use PHPCR\Query\QOM\PropertyExistenceInterface;
|
19 | 20 | use PHPCR\Query\QOM\PropertyValueInterface;
|
20 | 21 | use PHPCR\Query\QOM\QueryObjectModelConstantsInterface as Constants;
|
@@ -68,6 +69,7 @@ class Sql2ToQomQueryConverter
|
68 | 69 | * Instantiate a converter
|
69 | 70 | *
|
70 | 71 | * @param QueryObjectModelFactoryInterface $factory
|
| 72 | + * @param ValueConverter $valueConverter To override default converter. |
71 | 73 | */
|
72 | 74 | public function __construct(QueryObjectModelFactoryInterface $factory, ValueConverter $valueConverter = null)
|
73 | 75 | {
|
@@ -183,10 +185,11 @@ protected function parseName()
|
183 | 185 | * 6.7.6. Join type
|
184 | 186 | * Parse an SQL2 join source and return a QOM\Join
|
185 | 187 | *
|
186 |
| - * @param string $leftSelector the left selector as it has been read by parseSource |
187 |
| - * return \PHPCR\Query\QOM\JoinInterface |
| 188 | + * @param SourceInterface $leftSelector the left selector as it has been read by parseSource |
| 189 | + * |
| 190 | + * @return JoinInterface |
188 | 191 | */
|
189 |
| - protected function parseJoin($leftSelector) |
| 192 | + protected function parseJoin(SourceInterface $leftSelector) |
190 | 193 | {
|
191 | 194 | $joinType = $this->parseJoinType();
|
192 | 195 | $right = $this->parseSelector();
|
@@ -332,7 +335,12 @@ protected function parseDescendantNodeJoinCondition()
|
332 | 335 | * 6.7.13 And
|
333 | 336 | * 6.7.14 Or
|
334 | 337 | *
|
| 338 | + * @param ConstraintInterface $lhs Left hand side |
| 339 | + * @param int $minprec Precedence |
| 340 | + * |
335 | 341 | * @return ConstraintInterface
|
| 342 | + * |
| 343 | + * @throws \Exception |
336 | 344 | */
|
337 | 345 | protected function parseConstraint($lhs = null, $minprec = 0)
|
338 | 346 | {
|
@@ -728,52 +736,54 @@ protected function parsePropertyValue()
|
728 | 736 |
|
729 | 737 | protected function parseCastLiteral($token)
|
730 | 738 | {
|
731 |
| - if ($this->scanner->tokenIs($token, 'CAST')) { |
732 |
| - $this->scanner->expectToken('('); |
733 |
| - $token = $this->scanner->fetchNextToken(); |
| 739 | + if (!$this->scanner->tokenIs($token, 'CAST')) { |
| 740 | + throw new \LogicException('parseCastLiteral when not a CAST'); |
| 741 | + } |
734 | 742 |
|
735 |
| - $quoteString = false; |
736 |
| - if (substr($token, 0, 1) === '\'') { |
737 |
| - $quoteString = "'"; |
738 |
| - } elseif (substr($token, 0, 1) === '"') { |
739 |
| - $quoteString = '"'; |
740 |
| - } |
| 743 | + $this->scanner->expectToken('('); |
| 744 | + $token = $this->scanner->fetchNextToken(); |
741 | 745 |
|
742 |
| - if ($quoteString) { |
743 |
| - while (substr($token, -1) !== $quoteString) { |
744 |
| - $nextToken = $this->scanner->fetchNextToken(); |
745 |
| - if ('' === $nextToken) { |
746 |
| - break; |
747 |
| - } |
748 |
| - $token .= $nextToken; |
749 |
| - } |
| 746 | + $quoteString = false; |
| 747 | + if (substr($token, 0, 1) === '\'') { |
| 748 | + $quoteString = "'"; |
| 749 | + } elseif (substr($token, 0, 1) === '"') { |
| 750 | + $quoteString = '"'; |
| 751 | + } |
750 | 752 |
|
751 |
| - if (substr($token, -1) !== $quoteString) { |
752 |
| - throw new InvalidQueryException("Syntax error: unterminated quoted string '$token' in '{$this->sql2}'"); |
| 753 | + if ($quoteString) { |
| 754 | + while (substr($token, -1) !== $quoteString) { |
| 755 | + $nextToken = $this->scanner->fetchNextToken(); |
| 756 | + if ('' === $nextToken) { |
| 757 | + break; |
753 | 758 | }
|
754 |
| - $token = substr($token, 1, -1); |
755 |
| - $token = str_replace('\\'.$quoteString, $quoteString, $token); |
| 759 | + $token .= $nextToken; |
756 | 760 | }
|
757 | 761 |
|
758 |
| - $this->scanner->expectToken('AS'); |
759 |
| - |
760 |
| - $type = $this->scanner->fetchNextToken(); |
761 |
| - try { |
762 |
| - $typeValue = PropertyType::valueFromName($type); |
763 |
| - } catch (\InvalidArgumentException $e) { |
764 |
| - throw new InvalidQueryException("Syntax error: attempting to cast to an invalid type '$type'"); |
| 762 | + if (substr($token, -1) !== $quoteString) { |
| 763 | + throw new InvalidQueryException("Syntax error: unterminated quoted string '$token' in '{$this->sql2}'"); |
765 | 764 | }
|
| 765 | + $token = substr($token, 1, -1); |
| 766 | + $token = str_replace('\\'.$quoteString, $quoteString, $token); |
| 767 | + } |
766 | 768 |
|
767 |
| - $this->scanner->expectToken(')'); |
| 769 | + $this->scanner->expectToken('AS'); |
768 | 770 |
|
769 |
| - try { |
770 |
| - $token = $this->valueConverter->convertType($token, $typeValue, PropertyType::STRING); |
771 |
| - } catch (\Exception $e) { |
772 |
| - throw new InvalidQueryException("Syntax error: attempting to cast string '$token' to type '$type'"); |
773 |
| - } |
| 771 | + $type = $this->scanner->fetchNextToken(); |
| 772 | + try { |
| 773 | + $typeValue = PropertyType::valueFromName($type); |
| 774 | + } catch (\InvalidArgumentException $e) { |
| 775 | + throw new InvalidQueryException("Syntax error: attempting to cast to an invalid type '$type'"); |
| 776 | + } |
| 777 | + |
| 778 | + $this->scanner->expectToken(')'); |
774 | 779 |
|
775 |
| - return $token; |
| 780 | + try { |
| 781 | + $token = $this->valueConverter->convertType($token, $typeValue, PropertyType::STRING); |
| 782 | + } catch (\Exception $e) { |
| 783 | + throw new InvalidQueryException("Syntax error: attempting to cast string '$token' to type '$type'"); |
776 | 784 | }
|
| 785 | + |
| 786 | + return $token; |
777 | 787 | }
|
778 | 788 |
|
779 | 789 | /**
|
@@ -850,6 +860,8 @@ protected function parseOrderings()
|
850 | 860 |
|
851 | 861 | /**
|
852 | 862 | * 6.7.38 Order
|
| 863 | + * |
| 864 | + * @return OrderingInterface |
853 | 865 | */
|
854 | 866 | protected function parseOrdering()
|
855 | 867 | {
|
@@ -1044,9 +1056,11 @@ protected function scanColumn()
|
1044 | 1056 | /**
|
1045 | 1057 | * Build a single SQL2 column definition
|
1046 | 1058 | *
|
| 1059 | + * @param array $data with selector name, property name and column name. |
| 1060 | + * |
1047 | 1061 | * @return ColumnInterface
|
1048 | 1062 | */
|
1049 |
| - protected function buildColumn($data) |
| 1063 | + protected function buildColumn(array $data) |
1050 | 1064 | {
|
1051 | 1065 | list($selectorName, $propertyName, $columnName) = $data;
|
1052 | 1066 | $selectorName = $this->ensureSelectorName($selectorName);
|
|
0 commit comments