Browse Source

LINK query builder now works more like a wizard

dev
Cerys 3 weeks ago
parent
commit
934e59519b
  1. 20
      src/QueryBuilder/LinkQuery/Building/LinkQuery_Step1.php
  2. 31
      src/QueryBuilder/LinkQuery/Building/LinkQuery_Step2.php
  3. 26
      src/QueryBuilder/LinkQuery/Building/LinkQuery_Step3.php
  4. 40
      src/QueryBuilder/LinkQuery/Building/LinkQuery_Step4.php
  5. 25
      src/QueryBuilder/LinkQuery/Building/LinkQuery_Step9.php
  6. 106
      src/QueryBuilder/LinkQuery/LinkQueryBuilder.php
  7. 5
      src/QueryBuilder/QueryBuilder.php
  8. 2
      src/QueryBuilder/QueryBuilderTrait.php
  9. 42
      tests/QueryBuilderLinkTest.php

20
src/QueryBuilder/LinkQuery/Building/LinkQuery_Step1.php

@ -0,0 +1,20 @@
<?php
namespace Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery\Building;
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderQuery;
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderRequiredField;
use Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery\LinkQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilderTrait;
#[QueryBuilderQuery]
class LinkQuery_Step1
{
use QueryBuilderTrait;
public function RelativePath(string $relativePath): LinkQuery_Step2
{
self::ValidateDeegraphPath(target: $relativePath);
return new LinkQuery_Step2(querySoFar: "LINK " . $relativePath);
}
}

31
src/QueryBuilder/LinkQuery/Building/LinkQuery_Step2.php

@ -0,0 +1,31 @@
<?php
namespace Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery\Building;
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderQuery;
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderRequiredField;
use Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery\LinkQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilderTrait;
#[QueryBuilderQuery]
class LinkQuery_Step2
{
use QueryBuilderTrait;
private string $QuerySoFar = "";
public function __construct(string $querySoFar)
{
$this->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);
}
}

26
src/QueryBuilder/LinkQuery/Building/LinkQuery_Step3.php

@ -0,0 +1,26 @@
<?php
namespace Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery\Building;
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderQuery;
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderRequiredField;
use Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery\LinkQuery;
use Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery\LinkQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilderTrait;
#[QueryBuilderQuery]
class LinkQuery_Step3
{
use QueryBuilderTrait;
private string $QuerySoFar = "";
public function __construct(string $querySoFar)
{
$this->QuerySoFar = $querySoFar;
}
public function As(string $asPropertyName): LinkQuery_Step4
{
self::ValidateDeegraphPath(target: $asPropertyName);
return new LinkQuery_Step4($this->QuerySoFar . " AS " . $asPropertyName);
}
}

40
src/QueryBuilder/LinkQuery/Building/LinkQuery_Step4.php

@ -0,0 +1,40 @@
<?php
namespace Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery\Building;
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderQuery;
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderRequiredField;
use Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery\LinkQuery;
use Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery\LinkQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilderTrait;
#[QueryBuilderQuery]
class LinkQuery_Step4
{
use QueryBuilderTrait;
private string $QuerySoFar = "";
public function __construct(string $querySoFar)
{
$this->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);
}
}

25
src/QueryBuilder/LinkQuery/Building/LinkQuery_Step9.php

@ -0,0 +1,25 @@
<?php
namespace Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery\Building;
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderQuery;
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderRequiredField;
use Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery\LinkQuery;
use Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery\LinkQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilderTrait;
#[QueryBuilderQuery]
class LinkQuery_Step9
{
use QueryBuilderTrait;
private string $QuerySoFar = "";
public function __construct(string $querySoFar)
{
$this->QuerySoFar = $querySoFar;
}
public function Build()
{
return new LinkQuery($this->QuerySoFar);
}
}

106
src/QueryBuilder/LinkQuery/LinkQueryBuilder.php

@ -1,106 +0,0 @@
<?php
namespace Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery;
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderQuery;
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderRequiredField;
use Darksparrow\DeegraphInteractions\QueryBuilder\DirectoryQuery\DirectoryQuery;
use Darksparrow\DeegraphInteractions\QueryBuilder\DirectoryQuery\DirectoryQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilderTrait;
#[QueryBuilderQuery]
class LinkQueryBuilder
{
use QueryBuilderTrait;
#[QueryBuilderRequiredField]
protected string $RelativePath1 = "";
#[QueryBuilderRequiredField]
protected string $ToOrOf = "";
#[QueryBuilderRequiredField]
protected string $RelativePath2 = "";
#[QueryBuilderRequiredField]
protected string $PropertyName = "";
protected string $Mode = "";
public function LinkWhat(string $relativePath): LinkQueryBuilder
{
self::ValidateDeegraphPath(target: $relativePath);
$this->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);
}
}

5
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
{

2
src/QueryBuilder/QueryBuilderTrait.php

@ -42,7 +42,7 @@ trait QueryBuilderTrait
}
public function ValidateValues(
protected function ValidateValues(
DeleteQueryBuilder
|DirectoryQueryBuilder
|InsertQueryBuilder

42
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")
);
}
*/
}

Loading…
Cancel
Save