Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"dbschemix\\core\\": "src"
},
"files": [
"src/internal/filesystem/functions.php"
"src/internal/filesystem/functions.php",
"src/internal/functions.php"
]
},
"autoload-dev": {
Expand Down
6 changes: 2 additions & 4 deletions src/internal/action/Command.php → src/command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
60 changes: 60 additions & 0 deletions src/internal/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

namespace dbschemix\core\internal;

use OutOfBoundsException;
use Composer\InstalledVersions;

/**
* @api
* @param non-empty-string $package
* @return non-empty-string
* @throws OutOfBoundsException of package is not installed
*/
function get_package_version(string $package): string
{
/**
* @var array<non-empty-string, non-empty-string> $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.");
}
Loading