74 lines
1.7 KiB
PHP
74 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Database\MySqlConnection;
|
|
use Illuminate\Database\Connection;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register any application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register()
|
|
{
|
|
Connection::resolverFor('mysql', function ($connection, $database, $prefix, $config) {
|
|
return new MySqlConnection($connection, $database, $prefix, $config);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Bootstrap any application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot()
|
|
{
|
|
$this->loadMigrations();
|
|
}
|
|
|
|
private function loadMigrations()
|
|
{
|
|
$invalidContents = ['.', '..', '.gitkeep'];
|
|
$migrationsDir = database_path() . '/migrations/';
|
|
|
|
$migrationFilesPaths = $this->getMigrationFilesPaths(
|
|
$invalidContents,
|
|
$migrationsDir
|
|
);
|
|
|
|
$this->loadMigrationsFrom($migrationFilesPaths);
|
|
}
|
|
|
|
private function getMigrationFilesPaths($invalidContents, $currentDirectory, $paths = [])
|
|
{
|
|
$contents = opendir($currentDirectory);
|
|
|
|
while ($content = readdir($contents)) {
|
|
|
|
if (!in_array($content, $invalidContents)) {
|
|
|
|
$fullPath = $currentDirectory . $content;
|
|
|
|
if (is_dir($fullPath)) {
|
|
|
|
$paths = $this->getMigrationFilesPaths(
|
|
$invalidContents,
|
|
$fullPath . '/',
|
|
$paths
|
|
);
|
|
|
|
continue;
|
|
}
|
|
|
|
$paths[] = $fullPath;
|
|
}
|
|
}
|
|
|
|
return $paths;
|
|
}
|
|
}
|