45 lines
1.1 KiB
PHP
45 lines
1.1 KiB
PHP
|
<?php
|
||
|
// FsDbMigrationInfo.php
|
||
|
// Created: 2023-01-07
|
||
|
// Updated: 2023-01-07
|
||
|
|
||
|
namespace Index\Data\Migration;
|
||
|
|
||
|
use DateTime;
|
||
|
use Index\Data\IDbConnection;
|
||
|
|
||
|
class FsDbMigrationInfo implements IDbMigrationInfo {
|
||
|
private string $path;
|
||
|
private string $name;
|
||
|
private string $className;
|
||
|
|
||
|
public function __construct(string $path) {
|
||
|
$this->path = $path;
|
||
|
$this->name = $name = pathinfo($path, PATHINFO_FILENAME);
|
||
|
|
||
|
$dateTime = substr($name, 0, 17);
|
||
|
$dateTime = str_replace('_', '', substr($dateTime, 0, 9)) . substr($dateTime, -8);
|
||
|
|
||
|
$classParts = explode('_', substr($name, 18));
|
||
|
$className = '';
|
||
|
|
||
|
foreach($classParts as $part)
|
||
|
$className .= ucfirst($part);
|
||
|
|
||
|
$this->className = $className . '_' . $dateTime;
|
||
|
}
|
||
|
|
||
|
public function getName(): string {
|
||
|
return $this->name;
|
||
|
}
|
||
|
|
||
|
public function getClassName(): string {
|
||
|
return $this->className;
|
||
|
}
|
||
|
|
||
|
public function migrate(IDbConnection $conn): void {
|
||
|
require_once $this->path;
|
||
|
(new $this->className)->migrate($conn);
|
||
|
}
|
||
|
}
|