Skip to content

Commit

Permalink
chore: adding flat db connector
Browse files Browse the repository at this point in the history
  • Loading branch information
darkterminal committed Apr 26, 2023
1 parent 05a3e28 commit ef21c6b
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 7 deletions.
1 change: 0 additions & 1 deletion .devcontainer/devcontainer.json

This file was deleted.

5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
"slim/slim": "4.*",
"slim/psr7": "^1.5",
"php-di/php-di": "^6.4",
"justinrainbow/json-schema": "^5.2"
"justinrainbow/json-schema": "^5.2",
"rakibtg/sleekdb": "^2.15"
},
"require-dev": {
"symfony/dotenv": "^6.1"
}
}
}
59 changes: 58 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ class AuthController extends Controller
{
public function login(Request $request, Response $response)
{
$article = [
"title" => "Google Pixel XL",
"about" => "Google announced a new Pixel!",
"author" => [
"avatar" => "profile-12.jpg",
"name" => "Foo Bar"
]
];
$this->store('news')->insert($article);
$parsedBody = $request->getParsedBody();
$payload = json_encode($parsedBody);
$response->getBody()->write($payload);
Expand Down
8 changes: 5 additions & 3 deletions src/controllers/Controller.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php
namespace SleekwaredbApi\controllers;

class Controller
use SleekwaredbApi\core\Connector;

class Controller extends Connector
{
protected $container;

public function __construct($container)
{
$this->container = $container;
Expand All @@ -16,4 +18,4 @@ public function __get($property)
return $this->container->{$property};
}
}
}
}
21 changes: 21 additions & 0 deletions src/core/Connector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
namespace SleekwaredbApi\core;

use SleekDB\Store;

final class Connector
{
protected $databaseDirectory;

public function __construct()
{
$this->databaseDirectory = __DIR__ . "/src/core/db";
}

public function store($name)
{
$store = new Store($name, $this->databaseDirectory);
return $store;
}
}

3 changes: 3 additions & 0 deletions src/core/db/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!index.html
!.gitignore
1 change: 1 addition & 0 deletions src/core/db/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- Silence is golden -->

0 comments on commit ef21c6b

Please sign in to comment.