phinx icon indicating copy to clipboard operation
phinx copied to clipboard

Problems whith path when compiling phinx application in a phar

Open franksl opened this issue 5 years ago • 1 comments

Hi, I have a console application that includes some phinx commands (basically built as explained here: https://book.cakephp.org/phinx/0/en/commands.html#wrapping-phinx-in-another-symfony-console-application).

In order to move the tool easily I compile an execuatble phar by using phing. My problem is that paths inside phar's are changed and used by php with the phar:// prefix. As the php manual specifies there are many functions which are not phar aware, especially glob(), which is used in the Util::getFiles() method called by the Manager::getMigrationFiles() method. The result is that no migration classes are found when executing the migrate command from the phar.

I suggest using the nette/finder library to change the Util::getFiles() method (and possibily other ones using glob), with something like this:

public static function getFiles($paths)
{
    $files = [];
    foreach ($paths as $path) {
        foreach (\Nette\Utils\Finder::findFiles('*.php')->from($path) as $v) {
            $files[] = $v->__toString();
        }
    }
    $files = array_unique($files);

    return $files;
}

Many thanks, Frank

franksl avatar Nov 05 '20 12:11 franksl

Unfortunately nette/finder does not support all of glob like the { } modifier, and so would lose ability to handle this case from the docs:

paths:
    migrations: '%%PHINX_CONFIG_DIR%%/module/*/{data,scripts}/migrations'

However, we could probably do a pre-pass on these paths, and convert it from the above into:

paths:
    migrations:
        - '%%PHINX_CONFIG_DIR%%/module/*/data/migrations'
        - '%%PHINX_CONFIG_DIR%%/module/*/scripts}/migrations'

and then feed that into nette/finder (or whatever library that isn't glob directly).

MasterOdin avatar Nov 05 '20 19:11 MasterOdin