This commit is contained in:
73
api/app/Providers/AppServiceProvider.php
Normal file
73
api/app/Providers/AppServiceProvider.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user