32 lines
793 B
PHP
32 lines
793 B
PHP
<?php
|
|
// FsDbMigrationRepo.php
|
|
// Created: 2023-01-07
|
|
// Updated: 2023-01-07
|
|
|
|
namespace Index\Data\Migration;
|
|
|
|
class FsDbMigrationRepo implements IDbMigrationRepo {
|
|
public function __construct(
|
|
private string $path
|
|
) {}
|
|
|
|
public function getMigrations(): array {
|
|
if(!is_dir($this->path))
|
|
return [];
|
|
$files = glob(realpath($this->path) . '/*.php');
|
|
$migrations = [];
|
|
|
|
foreach($files as $file)
|
|
$migrations[] = new FsDbMigrationInfo($file);
|
|
|
|
return $migrations;
|
|
}
|
|
|
|
public function saveMigrationTemplate(string $name, string $body): void {
|
|
if(!is_dir($this->path))
|
|
mkdir($this->path, 0777, true);
|
|
|
|
file_put_contents(realpath($this->path) . '/' . $name . '.php', $body);
|
|
}
|
|
}
|