Cleanup
This commit is contained in:
parent
85d20e034a
commit
1bff7f46d7
@ -16,7 +16,7 @@ use Pecee\SimpleRouter\Handlers\EventHandler;
|
||||
use Pecee\SimpleRouter\Event\EventArgument;
|
||||
use Pecee\SimpleRouter\Route\ILoadableRoute;
|
||||
use Pecee\SimpleRouter\Route\IGroupRoute;
|
||||
use Config\Config;
|
||||
use Khofmann\Config\Config;
|
||||
// Router base path
|
||||
$basePath = Config::getBasePath() . "api";
|
||||
// Router event handler for prepending base path
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Config;
|
||||
namespace Khofmann\Config;
|
||||
|
||||
use Exception;
|
||||
|
||||
@ -11,17 +11,18 @@ class Config
|
||||
private array $app;
|
||||
private array $database;
|
||||
|
||||
protected function __construct()
|
||||
private function __construct()
|
||||
{
|
||||
$this->app = require_once __DIR__ . "/app.php";
|
||||
$this->database = require_once __DIR__ . "/database.php";
|
||||
$this->app = require_once __DIR__ . "/../../config/app.php";
|
||||
$this->database = require_once __DIR__ . "/../../config/database.php";
|
||||
}
|
||||
|
||||
protected function __clone()
|
||||
private function __clone()
|
||||
{
|
||||
throw new Exception("Cannot clone a singleton.");
|
||||
}
|
||||
|
||||
public function __wakeup()
|
||||
private function __wakeup()
|
||||
{
|
||||
throw new Exception("Cannot unserialize a singleton.");
|
||||
}
|
||||
@ -3,17 +3,28 @@
|
||||
namespace Khofmann\Database;
|
||||
|
||||
use PDO;
|
||||
use Config\Config;
|
||||
use Khofmann\Config\Config;
|
||||
use Exception;
|
||||
|
||||
class Database extends PDO
|
||||
{
|
||||
private static array $instances = [];
|
||||
|
||||
protected function __construct(string $dsn, string $username = null, string $password = null, array $options = null)
|
||||
private function __construct(string $dsn, string $username = null, string $password = null, array $options = null)
|
||||
{
|
||||
parent::__construct($dsn, $username, $password, $options);
|
||||
}
|
||||
|
||||
private function __clone()
|
||||
{
|
||||
throw new Exception("Cannot clone a singleton.");
|
||||
}
|
||||
|
||||
private function __wakeup()
|
||||
{
|
||||
throw new Exception("Cannot unserialize a singleton.");
|
||||
}
|
||||
|
||||
public static function getInstance(): Database
|
||||
{
|
||||
$cls = static::class;
|
||||
|
||||
@ -4,6 +4,10 @@ namespace Khofmann\GUID;
|
||||
|
||||
class GUID
|
||||
{
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public static function v4($data = null): string
|
||||
{
|
||||
// Generate 16 bytes (128 bits) of random data or use the data passed into the function.
|
||||
|
||||
@ -6,6 +6,10 @@ use Khofmann\Request\Request;
|
||||
|
||||
class Input
|
||||
{
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public static function post(string $index, $defaultValue = null)
|
||||
{
|
||||
$value = Request::request()->getInputHandler()->post($index, $defaultValue);
|
||||
|
||||
@ -21,7 +21,7 @@ class Post implements JsonSerializable
|
||||
private string $content;
|
||||
private DateTime $postedAt;
|
||||
|
||||
public function __construct(int $id, ?User $user, ?string $name, string $content, string $postedAt)
|
||||
private function __construct(int $id, ?User $user, ?string $name, string $content, string $postedAt)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->user = $user;
|
||||
|
||||
@ -6,7 +6,7 @@ use Exception;
|
||||
use PDO;
|
||||
use DateTime;
|
||||
use Khofmann\Database\Database;
|
||||
use Config\Config;
|
||||
use Khofmann\Config\Config;
|
||||
use JsonSerializable;
|
||||
use Khofmann\ApiError\ApiError;
|
||||
use Khofmann\GUID\GUID;
|
||||
@ -23,7 +23,7 @@ class User implements JsonSerializable
|
||||
private DateTime $memberSince;
|
||||
private int $postCount;
|
||||
|
||||
protected function __construct(int $id, string $username, int $status, string $email, string $timestamp, ?string $image, bool $isAdmin, int $postCount)
|
||||
private function __construct(int $id, string $username, int $status, string $email, string $timestamp, ?string $image, bool $isAdmin, int $postCount)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->username = $username;
|
||||
|
||||
@ -7,6 +7,10 @@ use Pecee\SimpleRouter\SimpleRouter;
|
||||
|
||||
class Request
|
||||
{
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public static function request(): PRequest
|
||||
{
|
||||
return SimpleRouter::request();
|
||||
|
||||
@ -7,6 +7,10 @@ use Pecee\Http\Response as PResponse;
|
||||
|
||||
class Response
|
||||
{
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public static function response(): PResponse
|
||||
{
|
||||
return SimpleRouter::response();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user