diff --git a/composer.json b/composer.json index ee37c00..84b1400 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,8 @@ "dbschemix\\core\\": "src" }, "files": [ - "src/internal/filesystem/functions.php" + "src/internal/filesystem/functions.php", + "src/internal/functions.php" ] }, "autoload-dev": { diff --git a/src/internal/action/Command.php b/src/command/Command.php similarity index 95% rename from src/internal/action/Command.php rename to src/command/Command.php index 0c6fcea..1c75033 100644 --- a/src/internal/action/Command.php +++ b/src/command/Command.php @@ -2,18 +2,16 @@ declare(strict_types=1); -namespace dbschemix\core\internal\action; +namespace dbschemix\core\command; use Override; use Throwable; -use dbschemix\core\command\CommandInterface; -use dbschemix\core\command\Options; use dbschemix\core\connection\ConnectionInterface; use dbschemix\core\Config; use dbschemix\core\Context; /** - * @psalm-internal dbschemix\core + * @psalm-internal dbschemix */ final readonly class Command implements CommandInterface { diff --git a/src/internal/functions.php b/src/internal/functions.php new file mode 100644 index 0000000..57b5c0b --- /dev/null +++ b/src/internal/functions.php @@ -0,0 +1,60 @@ + $versions + */ + static $versions = []; + if (isset($versions[$package])) { + return $versions[$package]; + } + + if (InstalledVersions::isInstalled($package)) { + $version = InstalledVersions::getPrettyVersion($package); + + if ($version !== null) { + assert($version !== ''); + + return $versions[$package] = $version; + } + } + + throw new OutOfBoundsException("Package `$package` is not installed."); +} + +/** + * @api + * @param non-empty-string $package + * @return non-empty-string + * @throws OutOfBoundsException of package is not installed + */ +function get_package_path(string $package): string +{ + $packagePath = InstalledVersions::getInstallPath($package); + + if ($packagePath !== null) { + $filepath = realpath($packagePath); + if ($filepath !== false) { + /** + * @var non-empty-string + */ + return $filepath; + } + } + + throw new OutOfBoundsException("Package `$package` have a null install path."); +}