diff --git a/composer.json b/composer.json index 581ace6..5922a59 100755 --- a/composer.json +++ b/composer.json @@ -22,10 +22,10 @@ }, "require": { "php": ">=8.1", - "ext-curl": "*", - "phpunit/phpunit": "^9.5" + "ext-curl": "*" }, "require-dev": { + "phpunit/phpunit": "^9.5" }, "scripts": { "test": "phpunit" diff --git a/src/Core/DeegraphServer.php b/src/Core/DeegraphServer.php index e55c74c..cb75549 100644 --- a/src/Core/DeegraphServer.php +++ b/src/Core/DeegraphServer.php @@ -1,6 +1,6 @@ ServerDomain = $server; - $this->Port = $port; $this->Token = $token; $this->Actor = $actor; + + $this->ServerDomain = $server; + $this->Port = $port; $this->AllowSelfSignedCerts = $allowSelfSignedCerts; } @@ -65,8 +68,14 @@ class DeegraphServer } } - $result = curl_exec($ch); + + if(curl_error($ch) == "SSL certificate problem: unable to get local issuer certificate") + { + throw new \Exception(); + die(); + } + curl_close($ch); return $result; diff --git a/src/DataStructures/KeyValuePair.php b/src/DataStructures/KeyValuePair.php new file mode 100644 index 0000000..5eceb66 --- /dev/null +++ b/src/DataStructures/KeyValuePair.php @@ -0,0 +1,32 @@ +Key = $key; + $this->Value = $value; + } + + public function __toString(): string + { + if(isset($this->Key) && isset($this->Value)) + return "{$this->Key} => \"{$this->Value}\""; + + if(!isset($this->Key) && isset($this->Value)) + return "NULL => \"{$this->Value}\""; + + if(isset($this->Key) && !isset($this->Value)) + return "{$this->Key} => NULL"; + + if(isset($this->Key) && isset($this->Value)) + return "NULL => NULL"; + + return "FAIL"; + } +} \ No newline at end of file diff --git a/src/DataStructures/QueryResponseRow.php b/src/DataStructures/QueryResponseRow.php new file mode 100644 index 0000000..80c3e8b --- /dev/null +++ b/src/DataStructures/QueryResponseRow.php @@ -0,0 +1,28 @@ +Search = key(array: $array); + foreach($array["{$builder->Search}"] as $key=>$value) + { + $builder->Results[] = new KeyValuePair(key: $key, value: $value); + } + + return $builder; + } + + public function __toString(): string + { + return json_encode($this, JSON_PRETTY_PRINT); + } + +} \ No newline at end of file diff --git a/src/DataStructures/QueryResponseWrapper.php b/src/DataStructures/QueryResponseWrapper.php index 4695621..c9797c4 100644 --- a/src/DataStructures/QueryResponseWrapper.php +++ b/src/DataStructures/QueryResponseWrapper.php @@ -13,9 +13,24 @@ class QueryResponseWrapper $builder = new QueryResponseWrapper(); - $builder->Rows = $temp["@rows"]; + foreach($temp["@rows"] as $row) $builder->Rows[] = QueryResponseRow::FromArray(array: $row); $builder->RowFormat = $temp["@row_format"]; return $builder; } + + public function Flatten(): array + { + $builder = []; + + foreach($this->Rows as $row) + { + foreach($row->Results as $result) + { + $builder[] = $result; + } + } + + return $builder; + } } diff --git a/src/QueryBuilder/QueryBuilder.php b/src/QueryBuilder/QueryBuilder.php index e9c9ee0..07828e3 100755 --- a/src/QueryBuilder/QueryBuilder.php +++ b/src/QueryBuilder/QueryBuilder.php @@ -6,9 +6,8 @@ use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders\InsertQuery; use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders\PutQuery; use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders\SelectQuery; -class QueryBuilder +final class QueryBuilder { - public static function Insert(): InsertQuery { return new InsertQuery(); diff --git a/src/QueryBuilder/QueryBuilders/SelectQuery.php b/src/QueryBuilder/QueryBuilders/SelectQuery.php index e8cb8a2..e076544 100755 --- a/src/QueryBuilder/QueryBuilders/SelectQuery.php +++ b/src/QueryBuilder/QueryBuilders/SelectQuery.php @@ -38,6 +38,11 @@ final class SelectQuery return $builder; } + public function RelativePath(string $relativePath): SelectQuery + { + $this->RelativePaths = [$relativePath]; + return $this; + } public function RelativePaths(array $relativePaths): SelectQuery { $this->RelativePaths = $relativePaths;