Skip to content

Commit

Permalink
Adding version information in the Tpay configuration view
Browse files Browse the repository at this point in the history
  • Loading branch information
krzGablo committed Aug 5, 2024
1 parent e3caa27 commit 5863bd5
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions Provider/ConfigurationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Tpay\Magento2\Provider;

use Composer\InstalledVersions;
use Composer\Autoload\ClassLoader;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Framework\Locale\Resolver;
Expand Down Expand Up @@ -222,11 +222,13 @@ public function getMagentoVersion(): string

public function buildMagentoInfo(): string
{
$apiVersions = $this->getApisVersions();

return sprintf(
'magento2:%s|tpay-openapi-php:%s|tpay-php:%s|magento2basic:%s|PHP:%s',
$this->getMagentoVersion(),
InstalledVersions::getPrettyVersion('tpay-com/tpay-openapi-php'),
InstalledVersions::getPrettyVersion('tpay-com/tpay-php'),
$apiVersions[0],
$apiVersions[1],
$this->getTpayPluginVersion(),
phpversion()
);
Expand Down Expand Up @@ -257,4 +259,30 @@ private function getTpayPluginVersion(): string

return 'n/a';
}

private function getApisVersions(): array
{
$apiVersions = ['n/a', 'n/a'];

if (true === method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders')) {
$vendorDir = array_keys(ClassLoader::getRegisteredLoaders())[0];
$installed = $vendorDir . '/composer/installed.php';

if (false === file_exists($installed)) {
return $apiVersions;
}

$dir = require $installed;

if (isset($dir['versions']['tpay-com/tpay-openapi-php'])) {
$apiVersions[0] = $dir['versions']['tpay-com/tpay-openapi-php']['pretty_version'];
}

if (isset($dir['versions']['tpay-com/tpay-php'])) {
$apiVersions[1] = $dir['versions']['tpay-com/tpay-php']['pretty_version'];
}
}

return $apiVersions;
}
}

0 comments on commit 5863bd5

Please sign in to comment.