Extract helpers and other requires

This commit is contained in:
myrmidex 2025-06-28 11:46:29 +02:00
parent 79aaa21040
commit 0f28f951a3
3 changed files with 60 additions and 11 deletions

View file

@ -1,15 +1,7 @@
#!/usr/bin/env php #!/usr/bin/env php
<?php <?php
require __DIR__ . '/../vendor/autoload.php'; require __DIR__ . '/../bootstrap/autoload.php';
// Ensure database file exists
$dbPath = __DIR__ . '/../storage/database.sqlite';
if (!file_exists($dbPath)) {
touch($dbPath);
}
require __DIR__ . '/../bootstrap/database.php';
use Illuminate\Filesystem\Filesystem; use Illuminate\Filesystem\Filesystem;
use Illuminate\Database\Migrations\DatabaseMigrationRepository; use Illuminate\Database\Migrations\DatabaseMigrationRepository;
@ -20,8 +12,8 @@ $migrator = new Migrator($repository, $capsule->getDatabaseManager(), new Filesy
if (! $repository->repositoryExists()) { if (! $repository->repositoryExists()) {
$repository->createRepository(); $repository->createRepository();
echo "Migration table created.\n"; logger('migration')->info("Migration table created");
} }
$migrator->run(__DIR__ . '/../database/migrations'); $migrator->run(__DIR__ . '/../database/migrations');
echo "Migrations complete.\n"; logger('migration')->info("Migrations completed successfully");

26
bootstrap/autoload.php Normal file
View file

@ -0,0 +1,26 @@
<?php
// Load Composer autoloader
require __DIR__ . '/../vendor/autoload.php';
// Load helper functions
require __DIR__ . '/helpers.php';
// Ensure storage directories exist
$storageDir = __DIR__ . '/../storage';
$logsDir = $storageDir . '/logs';
if (!is_dir($storageDir)) {
mkdir($storageDir, 0755, true);
}
if (!is_dir($logsDir)) {
mkdir($logsDir, 0755, true);
}
// Ensure database file exists
$dbPath = $storageDir . '/database.sqlite';
if (!file_exists($dbPath)) {
touch($dbPath);
}
// Load database configuration
require __DIR__ . '/database.php';

31
bootstrap/helpers.php Normal file
View file

@ -0,0 +1,31 @@
No <?php
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
if (!function_exists('base_path')) {
function base_path($path = '') {
return __DIR__ . '/../' . $path;
}
}
if (!function_exists('logger')) {
function logger(string $channel = 'app'): Logger {
static $loggers = [];
if (!isset($loggers[$channel])) {
$logger = new Logger($channel);
// Ensure logs directory exists
$logsDir = __DIR__ . '/../storage/logs';
if (!is_dir($logsDir)) {
mkdir($logsDir, 0755, true);
}
$logger->pushHandler(new StreamHandler($logsDir . "/{$channel}.log", Logger::INFO));
$loggers[$channel] = $logger;
}
return $loggers[$channel];
}
}