Skip to content

Commit f8b88f7

Browse files
authored
Merge pull request #68 from dotkernel/issue-67
Issue #67: Implement MariaDB/PostgreSQL connection
2 parents 47ccbfa + e3b62ae commit f8b88f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1042
-63
lines changed

.github/workflows/codecov.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121

2222
steps:
2323
- name: Checkout
24-
uses: actions/checkout@v4
24+
uses: actions/checkout@v6
2525

2626
- name: Install PHP
2727
uses: shivammathur/setup-php@v2
@@ -36,7 +36,7 @@ jobs:
3636
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV
3737

3838
- name: Cache dependencies installed with composer
39-
uses: actions/cache@v4
39+
uses: actions/cache@v5
4040
with:
4141
path: ${{ env.COMPOSER_CACHE_DIR }}
4242
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}

.github/workflows/qodana_code_quality.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ jobs:
1515
checks: write
1616
strategy:
1717
matrix:
18-
php-versions: [ '8.2', '8.3', '8.4']
18+
php-versions: [ '8.2', '8.3', '8.4' ]
1919
steps:
20-
- uses: actions/checkout@v4
20+
- uses: actions/checkout@v6
2121
with:
2222
ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit
2323
fetch-depth: 0 # a full history is required for pull request analysis
@@ -33,7 +33,7 @@ jobs:
3333
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV
3434

3535
- name: Cache dependencies installed with composer
36-
uses: actions/cache@v4
36+
uses: actions/cache@v5
3737
with:
3838
path: ${{ env.COMPOSER_CACHE_DIR }}
3939
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}

.github/workflows/static-analysis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121

2222
steps:
2323
- name: Checkout
24-
uses: actions/checkout@v4
24+
uses: actions/checkout@v6
2525

2626
- name: Install PHP
2727
uses: shivammathur/setup-php@v2
@@ -35,7 +35,7 @@ jobs:
3535
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV
3636

3737
- name: Cache dependencies installed with composer
38-
uses: actions/cache@v4
38+
uses: actions/cache@v5
3939
with:
4040
path: ${{ env.COMPOSER_CACHE_DIR }}
4141
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/.phpunit.cache
33
/clover.xml
44
/coveralls-upload.json
5-
/phpunit.xml
65
/vendor/
76
.idea
87
composer.lock
8+
.phpunit.result.cache
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
require_once 'vendor/autoload.php';
6+
7+
const ENVIRONMENT_DEVELOPMENT = 'development';
8+
const ENVIRONMENT_PRODUCTION = 'production';
9+
10+
// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
11+
12+
/**
13+
* @param array{source: string, destination: string, environment: array<string>} $file
14+
*/
15+
function copyFile(array $file): void
16+
{
17+
if (! in_array(getEnvironment(), $file['environment'])) {
18+
echo "Skipping the copy of {$file['source']} due to environment settings." . PHP_EOL;
19+
return;
20+
}
21+
22+
if (is_readable($file['destination'])) {
23+
echo "File {$file['destination']} already exists. Skipping..." . PHP_EOL;
24+
return;
25+
}
26+
27+
if (! copy($file['source'], $file['destination'])) {
28+
echo "Cannot copy {$file['source']} file to {$file['destination']}" . PHP_EOL;
29+
} else {
30+
echo "File {$file['source']} copied successfully to {$file['destination']}." . PHP_EOL;
31+
}
32+
}
33+
34+
function getEnvironment(): string
35+
{
36+
return getenv('COMPOSER_DEV_MODE') === '1' ? ENVIRONMENT_DEVELOPMENT : ENVIRONMENT_PRODUCTION;
37+
}
38+
39+
/**
40+
* When adding files to the below array:
41+
* - `source` and `destination` paths must be relative to the project root folder
42+
* - `environment` key will indicate on what environments the file will be copied
43+
*/
44+
$files = [
45+
[
46+
'source' => 'config/autoload/local.php.dist',
47+
'destination' => 'config/autoload/local.php',
48+
'environment' => [ENVIRONMENT_DEVELOPMENT, ENVIRONMENT_PRODUCTION],
49+
],
50+
[
51+
'source' => 'config/autoload/log.local.php.dist',
52+
'destination' => 'config/autoload/log.local.php',
53+
'environment' => [ENVIRONMENT_DEVELOPMENT, ENVIRONMENT_PRODUCTION],
54+
],
55+
[
56+
'source' => 'config/autoload/messenger.local.php.dist',
57+
'destination' => 'config/autoload/messenger.local.php',
58+
'environment' => [ENVIRONMENT_DEVELOPMENT, ENVIRONMENT_PRODUCTION],
59+
],
60+
[
61+
'source' => 'config/autoload/swoole.local.php.dist',
62+
'destination' => 'config/autoload/swoole.local.php',
63+
'environment' => [ENVIRONMENT_DEVELOPMENT, ENVIRONMENT_PRODUCTION],
64+
],
65+
];
66+
67+
echo "Using environment setting: " . getEnvironment() . PHP_EOL;
68+
69+
array_walk($files, 'copyFile');

bin/doctrine

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
declare(strict_types=1);
5+
6+
use Core\App\Event\TablePrefixEventListener;
7+
use Doctrine\ORM\EntityManager;
8+
use Doctrine\ORM\Events;
9+
use Doctrine\ORM\Tools\Console\ConsoleRunner;
10+
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
11+
use Dot\DataFixtures\Command\ExecuteFixturesCommand;
12+
use Dot\DataFixtures\Command\ListFixturesCommand;
13+
14+
require_once 'vendor/autoload.php';
15+
16+
$container = require 'config/container.php';
17+
18+
$entityManager = $container->get(EntityManager::class);
19+
$entityManager->getEventManager()
20+
->addEventListener(Events::loadClassMetadata, $container->get(TablePrefixEventListener::class));
21+
22+
$commands = [
23+
$container->get(ExecuteFixturesCommand::class),
24+
$container->get(ListFixturesCommand::class),
25+
];
26+
27+
ConsoleRunner::run(new SingleManagerProvider($entityManager), $commands);

composer.json

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,37 @@
4444
},
4545
"require": {
4646
"php": "~8.2.0 || ~8.3.0 || ~8.4.0",
47-
"dotkernel/dot-cli": "^3.9",
48-
"dotkernel/dot-dependency-injection": "^1.2",
49-
"dotkernel/dot-errorhandler": "4.2.1",
50-
"laminas/laminas-component-installer": "^3.5",
51-
"laminas/laminas-config-aggregator": "^1.18",
52-
"mezzio/mezzio": "^3.20",
53-
"netglue/laminas-messenger": "^2.3.0",
54-
"symfony/redis-messenger": "^v7.2.3"
47+
"ext-redis": "*",
48+
"dotkernel/dot-cache": "^4.4",
49+
"dotkernel/dot-cli": "^3.10",
50+
"dotkernel/dot-data-fixtures": "^1.5",
51+
"dotkernel/dot-dependency-injection": "^1.3",
52+
"dotkernel/dot-errorhandler": "4.4.0",
53+
"laminas/laminas-component-installer": "^3.7",
54+
"laminas/laminas-config-aggregator": "^1.19",
55+
"mezzio/mezzio": "^3.27.0",
56+
"netglue/laminas-messenger": "^2.5.0",
57+
"ramsey/uuid": "^4.9.2",
58+
"ramsey/uuid-doctrine": "^2.1",
59+
"roave/psr-container-doctrine": "^5.2.2 || ^6.1.0",
60+
"symfony/polyfill-php83": "^1.33",
61+
"symfony/redis-messenger": "^7.4.6"
5562
},
5663
"require-dev": {
57-
"laminas/laminas-coding-standard": "^3.0",
58-
"phpstan/phpstan": "^2.0",
59-
"phpstan/phpstan-doctrine": "^2.0",
60-
"phpstan/phpstan-phpunit": "^2.0",
61-
"phpunit/phpunit": "^10.5.45",
64+
"laminas/laminas-coding-standard": "^3.1",
65+
"laminas/laminas-development-mode": "^3.15",
66+
"phpstan/phpstan": "^2.1.40",
67+
"phpstan/phpstan-doctrine": "^2.0.18",
68+
"phpstan/phpstan-phpunit": "^2.0.16",
69+
"phpunit/phpunit": "^10.5.63",
6270
"roave/security-advisories": "dev-master",
63-
"swoole/ide-helper": "~5.0.0"
71+
"swoole/ide-helper": "~5.0.3"
6472
},
6573
"autoload": {
6674
"psr-4": {
67-
"Queue\\": "src/"
75+
"Core\\App\\": "src/Core/src/App/src/",
76+
"Queue\\App\\": "src/App/src/",
77+
"Queue\\Swoole\\": "src/Swoole/src/"
6878
}
6979
},
7080
"autoload-dev": {
@@ -81,8 +91,13 @@
8191
],
8292
"cs-check": "phpcs",
8393
"cs-fix": "phpcbf",
84-
"test": "phpunit --colors=always",
85-
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
86-
"static-analysis": "phpstan analyse --memory-limit 1G"
94+
"development-disable": "laminas-development-mode disable",
95+
"development-enable": "laminas-development-mode enable",
96+
"development-status": "laminas-development-mode status",
97+
"post-update-cmd": [
98+
"php ./bin/composer-post-install-script.php"
99+
],
100+
"static-analysis": "phpstan analyse --memory-limit 1G",
101+
"test": "phpunit --colors=always"
87102
}
88103
}

config/autoload/cli.global.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
'version' => '1.0.0',
1717
'name' => 'DotKernel CLI',
1818
'commands' => [
19-
"swoole:start" => StartCommand::class,
20-
"swoole:stop" => StopCommand::class,
21-
"messenger:start" => ConsumeMessagesCommand::class,
22-
"messenger:debug" => DebugCommand::class,
23-
"processed" => GetProcessedMessagesCommand::class,
24-
"failed" => GetFailedMessagesCommand::class,
25-
"inventory" => GetQueuedMessagesCommand::class,
19+
'swoole:start' => StartCommand::class,
20+
'swoole:stop' => StopCommand::class,
21+
'messenger:start' => ConsumeMessagesCommand::class,
22+
'messenger:debug' => DebugCommand::class,
23+
'processed' => GetProcessedMessagesCommand::class,
24+
'failed' => GetFailedMessagesCommand::class,
25+
'inventory' => GetQueuedMessagesCommand::class,
2626
],
2727
],
2828
FileLockerInterface::class => [

config/autoload/dependencies.global.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,26 @@
22

33
declare(strict_types=1);
44

5+
use Doctrine\Migrations\Tools\Console\Command\ExecuteCommand;
6+
use Roave\PsrContainerDoctrine\Migrations\CommandFactory;
7+
58
return [
69
// Provides application-wide services.
7-
// We recommend using fully-qualified class names whenever possible as
8-
// service names.
10+
// We recommend using fully qualified class names whenever possible as service names.
911
'dependencies' => [
10-
// Use 'aliases' to alias a service name to another service. The
11-
// key is the alias name, the value is the service to which it points.
12+
// Use 'aliases' to alias a service name to another service.
13+
// The key is the alias name, the value is the service to which it points.
1214
'aliases' => [
1315
// Fully\Qualified\ClassOrInterfaceName::class => Fully\Qualified\ClassName::class,
1416
],
15-
// Use 'invokables' for constructor-less services, or services that do
16-
// not require arguments to the constructor. Map a service name to the
17-
// class name.
17+
// Use 'invokables' for constructorless services, or services that do not require arguments to the constructor.
18+
// Map a service name to the class name.
1819
'invokables' => [
1920
// Fully\Qualified\InterfaceName::class => Fully\Qualified\ClassName::class,
2021
],
2122
// Use 'factories' for services provided by callbacks/factory classes.
2223
'factories' => [
23-
// Fully\Qualified\ClassName::class => Fully\Qualified\FactoryName::class,
24+
ExecuteCommand::class => CommandFactory::class,
2425
],
2526
],
2627
];

config/autoload/local.php.dist

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,45 @@ declare(strict_types=1);
1212
$baseUrl = 'https://queue.dotkernel.net';
1313

1414
$databases = [
15-
'default' => [
16-
'host' => '',
17-
'dbname' => '',
18-
'user' => '',
19-
'password' => '',
20-
'port' => 3306,
21-
'driver' => 'pdo_mysql',
22-
'charset' => 'utf8mb4',
23-
'collate' => 'utf8mb4_general_ci',
15+
/**
16+
* You can add more database connections to this array.
17+
* Only one active connection is allowed at a time.
18+
* By default, the application uses the 'mariadb' connection.
19+
* You can switch to another connection by activating it under doctrine->connection->orm_default-->params.
20+
*/
21+
'mariadb' => [
22+
'host' => 'localhost',
23+
'dbname' => 'dotkernel',
24+
'user' => '',
25+
'password' => '',
26+
'port' => 3306,
27+
'driver' => 'pdo_mysql',
28+
'collation' => 'utf8mb4_general_ci',
29+
'table_prefix' => '',
30+
],
31+
'postgresql' => [
32+
'host' => 'localhost',
33+
'dbname' => 'dotkernel',
34+
'user' => '',
35+
'password' => '',
36+
'port' => 5432,
37+
'driver' => 'pdo_pgsql',
38+
'collation' => 'utf8mb4_general_ci',
39+
'table_prefix' => '',
2440
],
25-
// you can add more database connections into this array
2641
];
2742

2843
return [
2944
'application' => [
30-
'name' => $app['name'] ?? '',
45+
'name' => 'Dotkernel Queue',
3146
'url' => $baseUrl,
3247
],
3348
'databases' => $databases,
3449
'doctrine' => [
3550
'connection' => [
3651
'orm_default' => [
37-
'params' => $databases['default'],
52+
'params' => $databases['mariadb'],
53+
// 'params' => $databases['postgresql'],
3854
],
3955
],
4056
],

0 commit comments

Comments
 (0)