Files
Woles-Framework/app/Core/Database/Seeder.php

49 lines
1007 B
PHP
Raw Permalink Normal View History

<?php
namespace App\Core\Database;
/**
* NovaCore Database Seeder
* Base seeder class
*/
abstract class Seeder
{
protected Connection $connection;
public function __construct()
{
$this->connection = $this->getConnection();
}
/**
* Get database connection
*/
protected function getConnection(): Connection
{
$config = include __DIR__ . '/../../Config/database.php';
$connectionConfig = $config['connections'][$config['default']];
return new Connection($connectionConfig);
}
/**
* Run the seeder
*/
abstract public function run(): void;
/**
* Call another seeder
*/
protected function call(string $seeder): void
{
$seederClass = "Database\\Seeders\\{$seeder}";
if (!class_exists($seederClass)) {
throw new \Exception("Seeder class {$seederClass} not found");
}
$seederInstance = new $seederClass();
$seederInstance->run();
}
}