Move to DB handler, test the local env to get a connection to database. Should add phinx migrations at some point.
This commit is contained in:
parent
8424a8c6ee
commit
7656012fa7
52
app/composer.lock
generated
52
app/composer.lock
generated
@ -2981,16 +2981,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/config",
|
"name": "symfony/config",
|
||||||
"version": "v7.1.6",
|
"version": "v7.1.7",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/symfony/config.git",
|
"url": "https://github.com/symfony/config.git",
|
||||||
"reference": "5c6152766251ff45a44b76affadd5287e253fb27"
|
"reference": "dc373a5cbd345354696f5dfd39c5c7a8ea23f4c8"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/symfony/config/zipball/5c6152766251ff45a44b76affadd5287e253fb27",
|
"url": "https://api.github.com/repos/symfony/config/zipball/dc373a5cbd345354696f5dfd39c5c7a8ea23f4c8",
|
||||||
"reference": "5c6152766251ff45a44b76affadd5287e253fb27",
|
"reference": "dc373a5cbd345354696f5dfd39c5c7a8ea23f4c8",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -3036,7 +3036,7 @@
|
|||||||
"description": "Helps you find, load, combine, autofill and validate configuration values of any kind",
|
"description": "Helps you find, load, combine, autofill and validate configuration values of any kind",
|
||||||
"homepage": "https://symfony.com",
|
"homepage": "https://symfony.com",
|
||||||
"support": {
|
"support": {
|
||||||
"source": "https://github.com/symfony/config/tree/v7.1.6"
|
"source": "https://github.com/symfony/config/tree/v7.1.7"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
@ -3052,20 +3052,20 @@
|
|||||||
"type": "tidelift"
|
"type": "tidelift"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2024-10-25T15:11:02+00:00"
|
"time": "2024-11-04T11:34:07+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/console",
|
"name": "symfony/console",
|
||||||
"version": "v7.1.6",
|
"version": "v7.1.7",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/symfony/console.git",
|
"url": "https://github.com/symfony/console.git",
|
||||||
"reference": "bb5192af6edc797cbab5c8e8ecfea2fe5f421e57"
|
"reference": "3284aafcac338b6e86fd955ee4d794cbe434151a"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/symfony/console/zipball/bb5192af6edc797cbab5c8e8ecfea2fe5f421e57",
|
"url": "https://api.github.com/repos/symfony/console/zipball/3284aafcac338b6e86fd955ee4d794cbe434151a",
|
||||||
"reference": "bb5192af6edc797cbab5c8e8ecfea2fe5f421e57",
|
"reference": "3284aafcac338b6e86fd955ee4d794cbe434151a",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -3129,7 +3129,7 @@
|
|||||||
"terminal"
|
"terminal"
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"source": "https://github.com/symfony/console/tree/v7.1.6"
|
"source": "https://github.com/symfony/console/tree/v7.1.7"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
@ -3145,7 +3145,7 @@
|
|||||||
"type": "tidelift"
|
"type": "tidelift"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2024-10-09T08:46:59+00:00"
|
"time": "2024-11-05T15:34:55+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/deprecation-contracts",
|
"name": "symfony/deprecation-contracts",
|
||||||
@ -3926,16 +3926,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "twig/twig",
|
"name": "twig/twig",
|
||||||
"version": "v3.14.0",
|
"version": "v3.14.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/twigphp/Twig.git",
|
"url": "https://github.com/twigphp/Twig.git",
|
||||||
"reference": "126b2c97818dbff0cdf3fbfc881aedb3d40aae72"
|
"reference": "f405356d20fb43603bcadc8b09bfb676cb04a379"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/twigphp/Twig/zipball/126b2c97818dbff0cdf3fbfc881aedb3d40aae72",
|
"url": "https://api.github.com/repos/twigphp/Twig/zipball/f405356d20fb43603bcadc8b09bfb676cb04a379",
|
||||||
"reference": "126b2c97818dbff0cdf3fbfc881aedb3d40aae72",
|
"reference": "f405356d20fb43603bcadc8b09bfb676cb04a379",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -3989,7 +3989,7 @@
|
|||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/twigphp/Twig/issues",
|
"issues": "https://github.com/twigphp/Twig/issues",
|
||||||
"source": "https://github.com/twigphp/Twig/tree/v3.14.0"
|
"source": "https://github.com/twigphp/Twig/tree/v3.14.1"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
@ -4001,7 +4001,7 @@
|
|||||||
"type": "tidelift"
|
"type": "tidelift"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2024-09-09T17:55:12+00:00"
|
"time": "2024-11-06T18:17:38+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "vlucas/phpdotenv",
|
"name": "vlucas/phpdotenv",
|
||||||
@ -4497,16 +4497,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpdocumentor/reflection-docblock",
|
"name": "phpdocumentor/reflection-docblock",
|
||||||
"version": "5.5.0",
|
"version": "5.5.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
|
"url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
|
||||||
"reference": "54e10d44fc1a84e2598d26f70d4f6f1f233e228a"
|
"reference": "0c70d2c566e899666f367ab7b80986beb3581e6f"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/54e10d44fc1a84e2598d26f70d4f6f1f233e228a",
|
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/0c70d2c566e899666f367ab7b80986beb3581e6f",
|
||||||
"reference": "54e10d44fc1a84e2598d26f70d4f6f1f233e228a",
|
"reference": "0c70d2c566e899666f367ab7b80986beb3581e6f",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -4555,9 +4555,9 @@
|
|||||||
"description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.",
|
"description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.",
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues",
|
"issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues",
|
||||||
"source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.5.0"
|
"source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.5.1"
|
||||||
},
|
},
|
||||||
"time": "2024-11-04T21:26:31+00:00"
|
"time": "2024-11-06T11:58:54+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpdocumentor/type-resolver",
|
"name": "phpdocumentor/type-resolver",
|
||||||
@ -6242,12 +6242,12 @@
|
|||||||
],
|
],
|
||||||
"aliases": [],
|
"aliases": [],
|
||||||
"minimum-stability": "stable",
|
"minimum-stability": "stable",
|
||||||
"stability-flags": {},
|
"stability-flags": [],
|
||||||
"prefer-stable": false,
|
"prefer-stable": false,
|
||||||
"prefer-lowest": false,
|
"prefer-lowest": false,
|
||||||
"platform": {
|
"platform": {
|
||||||
"ext-pdo": "*"
|
"ext-pdo": "*"
|
||||||
},
|
},
|
||||||
"platform-dev": {},
|
"platform-dev": [],
|
||||||
"plugin-api-version": "2.6.0"
|
"plugin-api-version": "2.6.0"
|
||||||
}
|
}
|
||||||
|
@ -26,19 +26,18 @@ use Psr\Log\LoggerInterface;
|
|||||||
use Slim\App;
|
use Slim\App;
|
||||||
use Slim\Factory\AppFactory;
|
use Slim\Factory\AppFactory;
|
||||||
use Slim\Psr7\Factory\ResponseFactory;
|
use Slim\Psr7\Factory\ResponseFactory;
|
||||||
|
|
||||||
use Slovocast\Domain\Repository\Channel\ChannelRepository;
|
|
||||||
use Slovocast\Domain\Repository\Channel\ChannelRepositoryInterface;
|
|
||||||
use Twig\Error\LoaderError;
|
use Twig\Error\LoaderError;
|
||||||
|
|
||||||
use Slovocast\Configuration\DatabaseConnectionSchema;
|
use Slovocast\Configuration\DatabaseConnectionSchema;
|
||||||
use Slovocast\Configuration\SessionSchema;
|
use Slovocast\Configuration\SessionSchema;
|
||||||
use Slovocast\Configuration\SiteInformationSchema;
|
use Slovocast\Configuration\SiteInformationSchema;
|
||||||
|
|
||||||
|
use Slovocast\Domain\Repository\Channel\ChannelRepository;
|
||||||
|
use Slovocast\Domain\Repository\Channel\ChannelRepositoryInterface;
|
||||||
use Slovocast\Domain\Repository\User\UserRepository;
|
use Slovocast\Domain\Repository\User\UserRepository;
|
||||||
use Slovocast\Domain\Repository\User\UserRepositoryInterface;
|
use Slovocast\Domain\Repository\User\UserRepositoryInterface;
|
||||||
|
|
||||||
use Slovocast\Infrastructure\Api\Database\DatabaseConnectionInterface;
|
use Slovocast\Infrastructure\Api\Database\DatabaseHandlerInterface;
|
||||||
use Slovocast\Infrastructure\Database\DatabaseConnection;
|
use Slovocast\Infrastructure\Database\DatabaseConnection;
|
||||||
use Slovocast\Infrastructure\Api\User\UserAuthorizationInterface;
|
use Slovocast\Infrastructure\Api\User\UserAuthorizationInterface;
|
||||||
use Slovocast\Infrastructure\User\BasicUserAuthorization;
|
use Slovocast\Infrastructure\User\BasicUserAuthorization;
|
||||||
@ -142,7 +141,7 @@ class Bootstrap
|
|||||||
/**
|
/**
|
||||||
* Database Connections
|
* Database Connections
|
||||||
*/
|
*/
|
||||||
DatabaseConnectionInterface::class => function (ContainerInterface $container) {
|
DatabaseHandlerInterface::class => function (ContainerInterface $container) {
|
||||||
$config = $container->get('config');
|
$config = $container->get('config');
|
||||||
return new DatabaseConnection(
|
return new DatabaseConnection(
|
||||||
$config->get('database.host'),
|
$config->get('database.host'),
|
||||||
@ -165,14 +164,14 @@ class Bootstrap
|
|||||||
*/
|
*/
|
||||||
UserRepositoryInterface::class => function (ContainerInterface $container) {
|
UserRepositoryInterface::class => function (ContainerInterface $container) {
|
||||||
return new UserRepository(
|
return new UserRepository(
|
||||||
$container->get(DatabaseConnectionInterface::class),
|
$container->get(DatabaseHandlerInterface::class),
|
||||||
$container->get(UserAuthorizationInterface::class)
|
$container->get(UserAuthorizationInterface::class)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
ChannelRepositoryInterface::class => function (ContainerInterface $container) {
|
ChannelRepositoryInterface::class => function (ContainerInterface $container) {
|
||||||
return new ChannelRepository(
|
return new ChannelRepository(
|
||||||
$container->get(DatabaseConnectionInterface::class)
|
$container->get(DatabaseHandlerInterface::class)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
@ -3,23 +3,23 @@
|
|||||||
namespace Slovocast\Controller;
|
namespace Slovocast\Controller;
|
||||||
|
|
||||||
use Slovocast\Controller\Controller;
|
use Slovocast\Controller\Controller;
|
||||||
use React\Mysql\MysqlClient;
|
use Slovocast\Infrastructure\Api\Database\DatabaseHandlerInterface;
|
||||||
use function React\Async\await;
|
|
||||||
use Psr\Http\Message\ResponseInterface as Response;
|
use Psr\Http\Message\ResponseInterface as Response;
|
||||||
|
|
||||||
class HealthCheck extends Controller
|
class HealthCheck extends Controller
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected MysqlClient $db
|
protected DatabaseHandlerInterface $database
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
public function handle(): Response
|
public function handle(): Response
|
||||||
{
|
{
|
||||||
$results = await($this->db->query("SELECT 1"));
|
$statement = $this->database->getConnection()->query('SELECT 1');
|
||||||
|
$results = $statement->fetchAll();
|
||||||
|
|
||||||
return $this->json([
|
return $this->json([
|
||||||
'http' => true,
|
'http' => true,
|
||||||
'database' => (bool) count($results->resultRows),
|
'database' => (bool) count($results),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ class LoginUserAction extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->auth->verify($credentials['password'], $user->getPassword())) {
|
if (!$this->auth->verify($credentials['password'], $user->getPassword())) {
|
||||||
$this->session->getFlash()->add('error', 'Unable to login.');
|
$this->session->getFlash()->add('error', "Unable to login.");
|
||||||
return $this->response->withStatus(400);
|
return $this->response->withStatus(400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,12 +10,12 @@ use Slovocast\Domain\Repository\Channel\ChannelRepositoryInterface;
|
|||||||
use Slovocast\Domain\Entity\Channel;
|
use Slovocast\Domain\Entity\Channel;
|
||||||
use Slovocast\Domain\Entity\User;
|
use Slovocast\Domain\Entity\User;
|
||||||
use Slovocast\Exception\EntityNotFoundException;
|
use Slovocast\Exception\EntityNotFoundException;
|
||||||
use Slovocast\Infrastructure\Api\Database\DatabaseConnectionInterface;
|
use Slovocast\Infrastructure\Api\Database\DatabaseHandlerInterface;
|
||||||
|
|
||||||
class ChannelRepository implements ChannelRepositoryInterface
|
class ChannelRepository implements ChannelRepositoryInterface
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected DatabaseConnectionInterface $db
|
protected DatabaseHandlerInterface $db
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,13 +4,13 @@ namespace Slovocast\Domain\Repository\User;
|
|||||||
|
|
||||||
use Slovocast\Domain\Entity\User;
|
use Slovocast\Domain\Entity\User;
|
||||||
use Slovocast\Exception\EntityNotFoundException;
|
use Slovocast\Exception\EntityNotFoundException;
|
||||||
use Slovocast\Infrastructure\Api\Database\DatabaseConnectionInterface;
|
|
||||||
use Slovocast\Infrastructure\Api\User\UserAuthorizationInterface;
|
use Slovocast\Infrastructure\Api\User\UserAuthorizationInterface;
|
||||||
|
use Slovocast\Infrastructure\Api\Database\DatabaseHandlerInterface;
|
||||||
|
|
||||||
class UserRepository implements UserRepositoryInterface
|
class UserRepository implements UserRepositoryInterface
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private DatabaseConnectionInterface $db,
|
private DatabaseHandlerInterface $db,
|
||||||
private UserAuthorizationInterface $userAuth
|
private UserAuthorizationInterface $userAuth
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
@ -4,8 +4,8 @@ namespace Slovocast\Infrastructure\Api\Database;
|
|||||||
|
|
||||||
use PDO;
|
use PDO;
|
||||||
|
|
||||||
interface DatabaseConnectionInterface
|
interface DatabaseHandlerInterface
|
||||||
{
|
{
|
||||||
public function getConnection(): PDO;
|
public function getConnection(): PDO;
|
||||||
public function setNewConnection(PDO $connection): void;
|
public function getDsn(): string;
|
||||||
}
|
}
|
@ -2,22 +2,21 @@
|
|||||||
|
|
||||||
namespace Slovocast\Infrastructure\Database;
|
namespace Slovocast\Infrastructure\Database;
|
||||||
|
|
||||||
use Slovocast\Infrastructure\Api\Database\DatabaseConnectionInterface;
|
use Slovocast\Infrastructure\Api\Database\DatabaseHandlerInterface;
|
||||||
use PDO;
|
use PDO;
|
||||||
|
|
||||||
class DatabaseConnection implements DatabaseConnectionInterface
|
class DatabaseConnection implements DatabaseHandlerInterface
|
||||||
{
|
{
|
||||||
private PDO $pdo;
|
private PDO $pdo;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
string $host,
|
private string $host,
|
||||||
string $username,
|
private string $username,
|
||||||
string $password,
|
private string $password,
|
||||||
string $database,
|
private string $database,
|
||||||
int $port = 3306
|
private int $port = 3306
|
||||||
) {
|
) {
|
||||||
$dsn = "mysql:dbname={$database};host={$host};port={$port}";
|
$this->pdo = new PDO($this->getDsn(), $username, $password);
|
||||||
$this->pdo = new PDO($dsn. $username, $password);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getConnection(): PDO
|
public function getConnection(): PDO
|
||||||
@ -25,8 +24,18 @@ class DatabaseConnection implements DatabaseConnectionInterface
|
|||||||
return $this->pdo;
|
return $this->pdo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setNewConnection(PDO $pdo): void
|
public function getDsn(): string
|
||||||
{
|
{
|
||||||
$this->pdo = $pdo;
|
return "mysql:dbname={$this->database};host={$this->host};port={$this->port}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHost(): string
|
||||||
|
{
|
||||||
|
return $this->host;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDatabase(): string
|
||||||
|
{
|
||||||
|
return $this->database;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,8 @@ services:
|
|||||||
- './app:/var/www/slovocast'
|
- './app:/var/www/slovocast'
|
||||||
depends_on:
|
depends_on:
|
||||||
- mariadb
|
- mariadb
|
||||||
|
links:
|
||||||
|
- mariadb
|
||||||
nginx:
|
nginx:
|
||||||
image: nginx:latest
|
image: nginx:latest
|
||||||
volumes:
|
volumes:
|
||||||
@ -19,11 +21,13 @@ services:
|
|||||||
mariadb:
|
mariadb:
|
||||||
image: mariadb:10.9
|
image: mariadb:10.9
|
||||||
environment:
|
environment:
|
||||||
MYSQL_ROOT_PASSWORD: "P4ssword!"
|
MARIADB_ROOT_PASSWORD: password
|
||||||
MYSQL_DATABASE: "slovocast"
|
MARIADB_DATABASE: slovocast
|
||||||
MYSQL_USER: "slovocast"
|
MARIADB_USER: slovocast
|
||||||
MYSQL_PASSWORD: "slovocast"
|
MARIADB_PASSWORD: password
|
||||||
volumes:
|
volumes:
|
||||||
- "slovocast_data:/var/lib/mysql"
|
- "slovocast_data:/var/lib/mysql"
|
||||||
|
ports:
|
||||||
|
- "3306:3306"
|
||||||
volumes:
|
volumes:
|
||||||
slovocast_data:
|
slovocast_data:
|
||||||
|
Loading…
Reference in New Issue
Block a user