diff --git a/src/QueryBuilder/LinkQuery/Building/LinkQuery_Step1.php b/src/QueryBuilder/LinkQuery/Building/LinkQuery_Step1.php new file mode 100644 index 0000000..f333268 --- /dev/null +++ b/src/QueryBuilder/LinkQuery/Building/LinkQuery_Step1.php @@ -0,0 +1,20 @@ +QuerySoFar = $querySoFar; + } + + public function To(string $relativePath): LinkQuery_Step3 + { + self::ValidateDeegraphPath(target: $relativePath); + return new LinkQuery_Step3($this->QuerySoFar . " TO " . $relativePath); + } + + public function Of(string $relativePath): LinkQuery_Step3 + { + self::ValidateDeegraphPath(target: $relativePath); + return new LinkQuery_Step3($this->QuerySoFar . " OF " . $relativePath); + } +} \ No newline at end of file diff --git a/src/QueryBuilder/LinkQuery/Building/LinkQuery_Step3.php b/src/QueryBuilder/LinkQuery/Building/LinkQuery_Step3.php new file mode 100644 index 0000000..a04a847 --- /dev/null +++ b/src/QueryBuilder/LinkQuery/Building/LinkQuery_Step3.php @@ -0,0 +1,26 @@ +QuerySoFar = $querySoFar; + } + + public function As(string $asPropertyName): LinkQuery_Step4 + { + self::ValidateDeegraphPath(target: $asPropertyName); + return new LinkQuery_Step4($this->QuerySoFar . " AS " . $asPropertyName); + } +} diff --git a/src/QueryBuilder/LinkQuery/Building/LinkQuery_Step4.php b/src/QueryBuilder/LinkQuery/Building/LinkQuery_Step4.php new file mode 100644 index 0000000..a9d0b14 --- /dev/null +++ b/src/QueryBuilder/LinkQuery/Building/LinkQuery_Step4.php @@ -0,0 +1,40 @@ +QuerySoFar = $querySoFar; + } + + public function Overwrite(): LinkQuery_Step9 + { + return new LinkQuery_Step9($this->QuerySoFar . " OVERWRITE"); + } + + public function Replace(): LinkQuery_Step9 + { + return new LinkQuery_Step9($this->QuerySoFar . " REPLACE"); + } + + public function Force(): LinkQuery_Step9 + { + return new LinkQuery_Step9($this->QuerySoFar . " FORCE"); + } + + public function Build(): LinkQuery + { + return new LinkQuery($this->QuerySoFar); + } +} diff --git a/src/QueryBuilder/LinkQuery/Building/LinkQuery_Step9.php b/src/QueryBuilder/LinkQuery/Building/LinkQuery_Step9.php new file mode 100644 index 0000000..83f002d --- /dev/null +++ b/src/QueryBuilder/LinkQuery/Building/LinkQuery_Step9.php @@ -0,0 +1,25 @@ +QuerySoFar = $querySoFar; + } + + public function Build() + { + return new LinkQuery($this->QuerySoFar); + } +} diff --git a/src/QueryBuilder/LinkQuery/LinkQueryBuilder.php b/src/QueryBuilder/LinkQuery/LinkQueryBuilder.php deleted file mode 100644 index 6301493..0000000 --- a/src/QueryBuilder/LinkQuery/LinkQueryBuilder.php +++ /dev/null @@ -1,106 +0,0 @@ -RelativePath1 = $relativePath; - return $this; - } - public function LinkTo(string $relativePath): LinkQueryBuilder - { - self::EnsureNotSet($this->RelativePath2); - self::ValidateDeegraphPath(target: $relativePath); - $this->RelativePath2 = $relativePath; - $this->ToOrOf = "TO"; - return $this; - } - public function LinkOf(string $relativePath): LinkQueryBuilder - { - self::EnsureNotSet($this->RelativePath2); - self::ValidateDeegraphPath(target: $relativePath); - $this->RelativePath2 = $relativePath; - $this->ToOrOf = "OF"; - return $this; - } - - - - public function PropertyName(string $propertyName): LinkQueryBuilder - { - $this->PropertyName = $propertyName; - return $this; - } - - - - public function Overwrite(): LinkQueryBuilder - { - self::EnsureNotSet($this->Mode); - $this->Mode = "OVERWRITE"; - return $this; - } - public function Replace(): LinkQueryBuilder - { - self::EnsureNotSet($this->Mode); - $this->Mode = "REPLACE"; - return $this; - } - public function Force(): LinkQueryBuilder - { - self::EnsureNotSet($this->Mode); - $this->Mode = "FORCE"; - return $this; - } - - - - public function Build(): LinkQuery - { - self::ValidateValues(target: $this); - - $builder = "LINK " - . $this->RelativePath1 - . " " - . $this->ToOrOf - . " " - . $this->RelativePath2 - . " AS " - . $this->PropertyName; - - if($this->Mode != "") $builder .= " " . $this->Mode; - - return new LinkQuery(queryString: $builder); - } -} - diff --git a/src/QueryBuilder/QueryBuilder.php b/src/QueryBuilder/QueryBuilder.php index 2fbbdf4..e268f64 100755 --- a/src/QueryBuilder/QueryBuilder.php +++ b/src/QueryBuilder/QueryBuilder.php @@ -5,6 +5,7 @@ namespace Darksparrow\DeegraphInteractions\QueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\DeleteQuery\DeleteQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\DirectoryQuery\DirectoryQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\InsertQuery\InsertQuery; +use Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery\Building\LinkQuery_Step1; use Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery\LinkQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\PermissionsQuery\PermissionQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\PutQuery\PutQueryBuilder; @@ -38,9 +39,9 @@ final class QueryBuilder { return new ReferencesQueryBuilder(); } - public static function Link(): LinkQueryBuilder + public static function Link(): LinkQuery_Step1 { - return new LinkQueryBuilder(); + return new LinkQuery_Step1(); } public static function Unlink(): UnlinkQueryBuilder { diff --git a/src/QueryBuilder/QueryBuilderTrait.php b/src/QueryBuilder/QueryBuilderTrait.php index afd18e2..3c3c283 100755 --- a/src/QueryBuilder/QueryBuilderTrait.php +++ b/src/QueryBuilder/QueryBuilderTrait.php @@ -42,7 +42,7 @@ trait QueryBuilderTrait } - public function ValidateValues( + protected function ValidateValues( DeleteQueryBuilder |DirectoryQueryBuilder |InsertQueryBuilder diff --git a/tests/QueryBuilderLinkTest.php b/tests/QueryBuilderLinkTest.php index 09f74c5..e841357 100644 --- a/tests/QueryBuilderLinkTest.php +++ b/tests/QueryBuilderLinkTest.php @@ -14,9 +14,9 @@ final class QueryBuilderLinkTest extends TestCase self::assertEquals( expected: "LINK {$this->TestUUID} TO {$this->TestUUID} AS test", actual: QueryBuilder::Link() - ->LinkWhat($this->TestUUID) - ->LinkTo($this->TestUUID) - ->PropertyName("test") + ->RelativePath($this->TestUUID) + ->To($this->TestUUID) + ->As("test") ->Build() ); } @@ -25,9 +25,9 @@ final class QueryBuilderLinkTest extends TestCase self::assertEquals( expected: "LINK {$this->TestUUID} TO {$this->TestUUID} AS test OVERWRITE", actual: QueryBuilder::Link() - ->LinkWhat($this->TestUUID) - ->LinkTo($this->TestUUID) - ->PropertyName("test") + ->RelativePath($this->TestUUID) + ->To($this->TestUUID) + ->As("test") ->Overwrite() ->Build() ); @@ -37,9 +37,9 @@ final class QueryBuilderLinkTest extends TestCase self::assertEquals( expected: "LINK {$this->TestUUID} TO {$this->TestUUID} AS test REPLACE", actual: QueryBuilder::Link() - ->LinkWhat($this->TestUUID) - ->LinkTo($this->TestUUID) - ->PropertyName("test") + ->RelativePath($this->TestUUID) + ->To($this->TestUUID) + ->As("test") ->Replace() ->Build() ); @@ -49,9 +49,9 @@ final class QueryBuilderLinkTest extends TestCase self::assertEquals( expected: "LINK {$this->TestUUID} TO {$this->TestUUID} AS test FORCE", actual: QueryBuilder::Link() - ->LinkWhat($this->TestUUID) - ->LinkTo($this->TestUUID) - ->PropertyName("test") + ->RelativePath($this->TestUUID) + ->To($this->TestUUID) + ->As("test") ->Force() ->Build() ); @@ -61,25 +61,23 @@ final class QueryBuilderLinkTest extends TestCase self::assertEquals( expected: "LINK {$this->TestUUID} OF {$this->TestUUID} AS test", actual: QueryBuilder::Link() - ->LinkWhat($this->TestUUID) - ->LinkOf($this->TestUUID) - ->PropertyName("test") + ->RelativePath($this->TestUUID) + ->Of($this->TestUUID) + ->As("test") ->Build() ); } + /* public function test5() { self::expectException(QueryBuilderConflictingFieldAlreadyExistsException::class); self::assertEquals( expected: "LINK {$this->TestUUID} OF {$this->TestUUID} AS test", actual: QueryBuilder::Link() - ->LinkWhat($this->TestUUID) - ->LinkOf($this->TestUUID) - ->PropertyName("test") - ->Overwrite() - ->Replace() - ->Force() - ->Build() + ->RelativePath($this->TestUUID) + ->Of($this->TestUUID) + ->As("test") ); } + */ }