Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Database Configuration
# For SQLite: set DATABASE_PATH (takes priority if set)
# DATABASE_PATH=/path/to/externals_dev.db

# For MySQL: leave DATABASE_PATH unset and configure these:
DATABASE_NAME=externals
DATABASE_USER=root
DATABASE_PASSWORD=
Expand Down
55 changes: 40 additions & 15 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Doctrine\DBAL\DriverManager;
use Externals\Application\Database\CustomMySQLPlatform;
use Externals\Search\AlgoliaSearchIndex;
use Externals\Search\NullSearchIndex;
use Externals\Search\SearchIndex;
use League\OAuth2\Client\Provider\AbstractProvider;
use League\OAuth2\Client\Provider\Github;
Expand All @@ -40,19 +41,35 @@
'assetsBaseUrl' => 'https://externals.io',

Connection::class =>
fn(Container $c) => DriverManager::getConnection([
'dbname' => getenv('DATABASE_NAME'),
'user' => getenv('DATABASE_USER'),
'password' => getenv('DATABASE_PASSWORD'),
'host' => getenv('DATABASE_HOST'),
'port' => getenv('DATABASE_PORT'),
'driver' => 'pdo_mysql',
'charset' => 'utf8mb4',
'platform' => new CustomMySQLPlatform(),
'driverOptions' => [
PDO::ATTR_TIMEOUT => 5,
],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you preserve platform and driverOptions? These are needed in prod

]),
fn(Container $c) => DriverManager::getConnection(
(function() use ($c) {
// Use SQLite if DATABASE_PATH is set
$databasePath = getenv('DATABASE_PATH');
if (!empty($databasePath)) {
return [
'driver' => 'pdo_sqlite',
'path' => $databasePath,
];
}

// Otherwise use MySQL
$config = [
'driver' => 'pdo_mysql',
'host' => getenv('DATABASE_HOST') ?: 'localhost',
'dbname' => getenv('DATABASE_NAME') ?: 'externals',
'user' => getenv('DATABASE_USER') ?: 'root',
'password' => getenv('DATABASE_PASSWORD') ?: '',
'charset' => 'utf8mb4',
];

$dbPort = getenv('DATABASE_PORT');
if (!empty($dbPort)) {
$config['port'] = (int) $dbPort;
}

return $config;
})()
),

Environment::class => function (Container $c) {
$loader = new FilesystemLoader(__DIR__ . '/../views');
Expand Down Expand Up @@ -91,8 +108,16 @@
'algolia.index_prefix' => env('ALGOLIA_INDEX_PREFIX', 'dev_'),
\AlgoliaSearch\Client::class => create()
->constructor(env('ALGOLIA_APP_ID'), env('ALGOLIA_API_KEY')),
SearchIndex::class => autowire(AlgoliaSearchIndex::class)
->constructorParameter('indexPrefix', get('algolia.index_prefix')),
SearchIndex::class => function (Container $c) {
$algoliaAppId = getenv('ALGOLIA_APP_ID');
if (empty($algoliaAppId)) {
return new NullSearchIndex();
}
return new AlgoliaSearchIndex(
$c->get(\AlgoliaSearch\Client::class),
$c->get('algolia.index_prefix')
);
},

'session.secret_key' => env('SESSION_SECRET_KEY'),
SessionMiddleware::class =>
Expand Down
13 changes: 13 additions & 0 deletions src/Search/NullSearchIndex.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php declare(strict_types=1);

namespace Externals\Search;

use Externals\Email\Email;

class NullSearchIndex implements SearchIndex
{
public function indexEmail(Email $email): void
{
// No-op implementation for development
}
}