migrations
migrations copied to clipboard
Problems with phar:// paths in Finder
Hello, I did a simple command line wrapper for doctrine/migrations basically by using a custom integration like the manual explains here: https://www.doctrine-project.org/projects/doctrine-migrations/en/3.0/reference/custom-integration.html#custom-integration
I then built a phar (by using phing but the tool does not matter) to be able to use the migrations executable easily by using a single file. In configuration I specified a directory for versions classes like this:
$configuration->addMigrationsDirectory(
'MyDbMigrations',
__DIR__ . '/src/MyDbMigrations'
);
If I run the main php script from outside the phar everything works good. When I compile the phar and try to run a command I get an InvalidDirectory exception because Finder cannot find files under src/MyDbMigrations. I did some research and it seems that the glob() function used by GlobFinder does not work with phar:// paths so it fails in finding Version*.php files. How can this be overcome? It would be good if a custom Finder class could be injected in some way or that the GlobFinder class could be able to look for files in phar archives. I'll try to do a fork for now. Thanks Frank
Just a followup, I actually "solved" the problem by replacing the call to addMigrationsDirectory outlined in my previous message with this (using nette/finder project):
$path = __DIR__ . '/src/Si3dDbMigrations';
if (substr($path, 0, 5) == 'phar:') {
foreach (Finder::findFiles('Version*.php')->from($path) as $v) {
$c = 'MyDbMigrations\\' . substr($v->getFilename(), 0, -4);
$configuration->addMigrationClass($c);
}
} else {
$configuration->addMigrationsDirectory(
'MyDbMigrations',
__DIR__ . '/src/MyDbMigrations'
);
}
This will add my migration classes correctly both inside and outside the phar. Frank