mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-03-17 03:17:44 +00:00
46 lines
948 B
PHP
46 lines
948 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/*
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Chill\MainBundle\Service;
|
|
|
|
use Composer\InstalledVersions;
|
|
|
|
readonly class VersionProvider
|
|
{
|
|
public function __construct(private string $packageName) {}
|
|
|
|
public function getVersion(): string
|
|
{
|
|
try {
|
|
$version = InstalledVersions::getPrettyVersion($this->packageName);
|
|
|
|
if (null === $version) {
|
|
return 'unknown';
|
|
}
|
|
|
|
return $version;
|
|
} catch (\OutOfBoundsException) {
|
|
return 'unknown';
|
|
}
|
|
}
|
|
|
|
public function getFormattedVersion(): string
|
|
{
|
|
$version = $this->getVersion();
|
|
|
|
if ('unknown' === $version) {
|
|
return 'Version unavailable';
|
|
}
|
|
|
|
return $version;
|
|
}
|
|
}
|