Cerys Lewis
5 months ago
22 changed files with 343 additions and 111 deletions
@ -0,0 +1,14 @@ |
|||
<?php |
|||
|
|||
namespace Darksparrow\DeegraphInteractions\Interfaces; |
|||
|
|||
use Darksparrow\DeegraphInteractions\QueryInstance\GrantQuery; |
|||
use Darksparrow\DeegraphInteractions\QueryInstance\InsertQuery; |
|||
use Darksparrow\DeegraphInteractions\QueryInstance\PutQuery; |
|||
use Darksparrow\DeegraphInteractions\QueryInstance\SelectQuery; |
|||
|
|||
interface QueryBuilderInterface |
|||
{ |
|||
// public function __construct(); |
|||
public function Build(): GrantQuery|InsertQuery|PutQuery|SelectQuery; |
|||
} |
@ -0,0 +1,16 @@ |
|||
<?php |
|||
|
|||
namespace Darksparrow\DeegraphInteractions\Interfaces; |
|||
|
|||
use Darksparrow\DeegraphInteractions\Core\DeegraphServer; |
|||
|
|||
interface QueryInstanceInterface |
|||
{ |
|||
/** |
|||
* Runs the Query Instance on a DeegraphServer Instance. |
|||
* |
|||
* @param DeegraphServer $deegraphServer |
|||
* @return mixed |
|||
*/ |
|||
public function RunQuery(DeegraphServer $deegraphServer); |
|||
} |
@ -0,0 +1,8 @@ |
|||
<?php |
|||
|
|||
namespace Darksparrow\DeegraphInteractions\Interfaces; |
|||
|
|||
interface QueryResponseInterface |
|||
{ |
|||
public function __construct(string $response); |
|||
} |
@ -0,0 +1,21 @@ |
|||
<?php |
|||
|
|||
namespace Darksparrow\DeegraphInteractions\QueryInstance; |
|||
|
|||
use Darksparrow\DeegraphInteractions\Core\DeegraphServer; |
|||
use Darksparrow\DeegraphInteractions\Interfaces\QueryInstanceInterface; |
|||
use Darksparrow\DeegraphInteractions\QueryResponse\GrantQueryResponse; |
|||
use Darksparrow\DeegraphInteractions\Superclasses\QueryInstanceSuperclass; |
|||
|
|||
final class GrantQuery extends QueryInstanceSuperclass implements QueryInstanceInterface |
|||
{ |
|||
public function RunQuery(DeegraphServer $deegraphServer) |
|||
{ |
|||
$response = $deegraphServer->RunRawRequest( |
|||
endpoint: "/api/v1/@query", |
|||
method: "POST", |
|||
body: $this->QueryString |
|||
); |
|||
return GrantQueryResponse::FromAPIResponse(response: $response); |
|||
} |
|||
} |
@ -0,0 +1,20 @@ |
|||
<?php |
|||
|
|||
namespace Darksparrow\DeegraphInteractions\QueryInstance; |
|||
|
|||
use Darksparrow\DeegraphInteractions\Core\DeegraphServer; |
|||
use Darksparrow\DeegraphInteractions\QueryResponse\InsertQueryResponse; |
|||
use Darksparrow\DeegraphInteractions\Superclasses\QueryInstanceSuperclass; |
|||
|
|||
final class InsertQuery extends QueryInstanceSuperclass implements QueryInstanceInterface |
|||
{ |
|||
public function RunQuery(DeegraphServer $deegraphServer) |
|||
{ |
|||
$response = $deegraphServer->RunRawRequest( |
|||
endpoint: "/api/v1/@query", |
|||
method: "POST", |
|||
body: $this->QueryString |
|||
); |
|||
return InsertQueryResponse::FromAPIResponse(response: $response); |
|||
} |
|||
} |
@ -0,0 +1,21 @@ |
|||
<?php |
|||
|
|||
namespace Darksparrow\DeegraphInteractions\QueryInstance; |
|||
|
|||
use Darksparrow\DeegraphInteractions\Core\DeegraphServer; |
|||
use Darksparrow\DeegraphInteractions\Interfaces\QueryResponseInterface; |
|||
use Darksparrow\DeegraphInteractions\QueryResponse\PutQueryResponse; |
|||
use Darksparrow\DeegraphInteractions\Superclasses\QueryInstanceSuperclass; |
|||
|
|||
final class PutQuery extends QueryInstanceSuperclass implements QueryResponseInterface |
|||
{ |
|||
public function RunQuery(DeegraphServer $deegraphServer) |
|||
{ |
|||
$response = $deegraphServer->RunRawRequest( |
|||
endpoint: "/api/v1/@query", |
|||
method: "POST", |
|||
body: $this->QueryString |
|||
); |
|||
return PutQueryResponse::FromAPIResponse(response: $response); |
|||
} |
|||
} |
@ -0,0 +1,21 @@ |
|||
<?php |
|||
|
|||
namespace Darksparrow\DeegraphInteractions\QueryInstance; |
|||
|
|||
use Darksparrow\DeegraphInteractions\Core\DeegraphServer; |
|||
use Darksparrow\DeegraphInteractions\Interfaces\QueryInstanceInterface; |
|||
use Darksparrow\DeegraphInteractions\QueryResponse\SelectQueryResponse; |
|||
use Darksparrow\DeegraphInteractions\Superclasses\QueryInstanceSuperclass; |
|||
|
|||
final class SelectQuery extends QueryInstanceSuperclass implements QueryInstanceInterface |
|||
{ |
|||
public function RunQuery(DeegraphServer $deegraphServer) |
|||
{ |
|||
$response = $deegraphServer->RunRawRequest( |
|||
endpoint: "/api/v1/@query", |
|||
method: "POST", |
|||
body: $this->QueryString |
|||
); |
|||
return new SelectQueryResponse(response: $response); |
|||
} |
|||
} |
@ -0,0 +1,17 @@ |
|||
<?php |
|||
|
|||
namespace Darksparrow\DeegraphInteractions\QueryResponse; |
|||
|
|||
use Darksparrow\DeegraphInteractions\Interfaces\QueryResponseInterface; |
|||
|
|||
final class GrantQueryResponse implements QueryResponseInterface |
|||
{ |
|||
protected string $RuleID; |
|||
|
|||
public function __construct(string $response) |
|||
{ |
|||
$response = json_decode($response, true); |
|||
|
|||
$this->RuleID = $response["@rule_id"]; |
|||
} |
|||
} |
@ -0,0 +1,13 @@ |
|||
<?php |
|||
|
|||
namespace Darksparrow\DeegraphInteractions\QueryResponse; |
|||
|
|||
use Darksparrow\DeegraphInteractions\Interfaces\QueryResponseInterface; |
|||
|
|||
final class InsertQueryResponse implements QueryResponseInterface |
|||
{ |
|||
public function __construct(string $response) |
|||
{ |
|||
$response = json_decode($response, true); |
|||
} |
|||
} |
@ -0,0 +1,14 @@ |
|||
<?php |
|||
|
|||
namespace Darksparrow\DeegraphInteractions\QueryResponse; |
|||
|
|||
use Darksparrow\DeegraphInteractions\Interfaces\QueryResponseInterface; |
|||
|
|||
final class PutQueryResponse implements QueryResponseInterface |
|||
{ |
|||
|
|||
public function __construct(string $response) |
|||
{ |
|||
$response = json_decode($response, true); |
|||
} |
|||
} |
@ -0,0 +1,43 @@ |
|||
<?php |
|||
|
|||
namespace Darksparrow\DeegraphInteractions\QueryResponse; |
|||
|
|||
use Darksparrow\DeegraphInteractions\Interfaces\QueryResponseInterface; |
|||
|
|||
final class SelectQueryResponse implements QueryResponseInterface |
|||
{ |
|||
public array $Rows; |
|||
public string $RowFormat; |
|||
|
|||
public function __construct(string $response) |
|||
{ |
|||
$response = json_decode($response, true); |
|||
|
|||
echo "\n\n\n"; |
|||
var_dump($response); |
|||
echo "\n\n\n"; |
|||
|
|||
if(array_key_exists(key: "@rows", array: $response)) |
|||
{ |
|||
$this->Rows = []; |
|||
foreach($response["@rows"] as $row) |
|||
$this->Rows[] = QueryResponseRow::FromArray(array: $row); |
|||
$this->RowFormat = $response["@row_format"]; |
|||
} |
|||
} |
|||
|
|||
public function FlattenRows(): array |
|||
{ |
|||
$builder = []; |
|||
|
|||
foreach($this->Rows as $row) |
|||
{ |
|||
foreach($row->Results as $result) |
|||
{ |
|||
$builder[] = $result; |
|||
} |
|||
} |
|||
|
|||
return $builder; |
|||
} |
|||
} |
@ -0,0 +1,28 @@ |
|||
<?php |
|||
|
|||
namespace Darksparrow\DeegraphInteractions\Superclasses; |
|||
|
|||
class QueryInstanceSuperclass |
|||
{ |
|||
protected string $QueryString; |
|||
|
|||
/** |
|||
* Build a new Query Instance from a Query String. |
|||
* |
|||
* @param string $queryString |
|||
*/ |
|||
public function __construct(string $queryString) |
|||
{ |
|||
$this->QueryString = $queryString; |
|||
} |
|||
|
|||
/** |
|||
* Returns back the Query Instance as a string object. |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function __toString(): string |
|||
{ |
|||
return $this->QueryString; |
|||
} |
|||
} |
@ -1,6 +1,6 @@ |
|||
<?php |
|||
|
|||
namespace Darksparrow\DeegraphInteractions\QueryBuilder; |
|||
namespace Darksparrow\DeegraphInteractions\Traits; |
|||
|
|||
use Darksparrow\DeegraphInteractions\Exceptions\QueryBuilderConflictingFieldAlreadyExistsException; |
|||
use Darksparrow\DeegraphInteractions\Exceptions\QueryBuilderInvalidInputException; |
Loading…
Reference in new issue