Replace Jison implementation for PathTemplates#203
Replace Jison implementation for PathTemplates#203michaelbausor merged 13 commits intogoogleapis:masterfrom
Conversation
Remove PathTemplate
- Restore PathTemplate - Add Parser - Add better test coverage
Codecov Report
@@ Coverage Diff @@
## master #203 +/- ##
=========================================
+ Coverage 84.14% 84.7% +0.55%
=========================================
Files 63 63
Lines 2826 2353 -473
=========================================
- Hits 2378 1993 -385
+ Misses 448 360 -88
Continue to review full report at Codecov.
|
| @@ -0,0 +1,143 @@ | |||
| <?php | |||
| /* | |||
| * Copyright 2018, Google Inc. | |||
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| public function __toString() | ||
| { | ||
| if ($this->hasValue()) { | ||
| return $this->value; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/ApiCore/ValidationException.php
Outdated
| * ValidationException represents a local error (i.e. not during an RPC call). | ||
| */ | ||
| class ValidationException extends Exception | ||
| class ValidationException extends RuntimeException |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
|
||
| public static function isValidBinding($literal) | ||
| { | ||
| return preg_match("-^[^/=\\{\\}\\\\]+$-", $literal) === 1; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
Cloud Firestore supports special characters in paths which are not allowed by the jison parser or by this new parser. I added a workaround (googleapis/google-cloud-php#1122) for this a couple of months ago. When I made that change, we had been hoping it would be a temporary workaround pending this work we knew you had on your agenda. Would it be possible to add support for optional special characters in paths? See also #197. |
|
@jdpedrie Yes, I think we can add such support. Are there any more detailed requirements? E.g., are there restrictions on the first character of the file name? If so, we would like to enforce them by not allowing the special characters. |
|
@michaelbausor I think the only constraints for Firestore are listed under "Constraints on document IDs" found here. My tests confirm that special characters are, for instance, allowed as the first character of an ID. |
|
Updated, PTAL |
jdpedrie
left a comment
There was a problem hiding this comment.
looks good! nice work with the comprehensive tests. :)
| @@ -32,10 +32,11 @@ | |||
| namespace Google\ApiCore; | |||
|
|
|||
| use Exception; | |||
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
Running through a review today :). Really happy to see this! |
dwsupplee
left a comment
There was a problem hiding this comment.
This is a really solid refactor. Nice work :)
| /** | ||
| * Parses a path into an array of segments. | ||
| * | ||
| * @param $path |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| private static function parse($segmentString) | ||
| { | ||
| if ($segmentString === '*') { | ||
| return new Segment(Segment::WILDCARD_SEGMENT, null, null); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| */ | ||
| private static function parseLiteralFromPath($literal, $path, &$index) | ||
| { | ||
| if (strlen($path) < ($index + strlen($literal))) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * @param string $literal | ||
| * @return bool | ||
| */ | ||
| public static function isValidLiteral($literal) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * @param $binding | ||
| * @return bool | ||
| */ | ||
| public static function isValidBinding($binding) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * @param Segment[] $segments | ||
| * @return int | ||
| */ | ||
| private static function countDoubleWildcards($segments) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| foreach ($nestedKeySegmentTuples as list($nestedKey, $nestedSegment)) { | ||
| /** @var Segment $nestedSegment */ | ||
| // Nested variables are not allowed | ||
| assert($nestedSegment->getSegmentType() !== Segment::VARIABLE_SEGMENT); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| // match by examining the difference in count between the template segments and the | ||
| // path pieces. | ||
|
|
||
| if (count($pathPieces) < count($flattenedKeySegmentTuples)) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| /** @var RelativeResourceTemplate|null */ | ||
| private $template; | ||
|
|
||
| public function __construct($segmentType, $key, $value, RelativeResourceTemplate $template = null) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| /** | ||
| * @expectedException \Google\ApiCore\ValidationException | ||
| */ | ||
| public function testMatchWildcardWithColonInMiddle() |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Important changes in this PR:
countmethod and no longer implementscountableinterface$pathparsed (previously this was dropped)*no longer changed to{$0=*}When reviewing, please pay close attention to
PathTemplateTest, to make sure that there are no regressions inPathTemplatebehaviour, other than the expected ones.