-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added X-Library header
- Loading branch information
Showing
5 changed files
with
115 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace MerchOne\PhpApiSdk\Util; | ||
|
||
use Composer\InstalledVersions; | ||
|
||
final class PackageInfo | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private string $name = 'PHP'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private string $version = 'unknown'; | ||
|
||
public function __construct() | ||
{ | ||
$this->boot(); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getVersionName(): string | ||
{ | ||
return str_replace('merch-one/', '', $this->name) . '/' . $this->version; | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
private function boot(): void | ||
{ | ||
$name = $this->name; | ||
|
||
try { | ||
$this->name = $this->currentPackage(); | ||
$this->version = InstalledVersions::getPrettyVersion($this->name); | ||
} catch (\Throwable $e) { | ||
$this->name = $name; | ||
$this->version = $this->getVersionFromComposerJson(); | ||
} | ||
} | ||
|
||
/** | ||
* @return string | ||
* @noinspection JsonEncodingApiUsageInspection | ||
*/ | ||
private function getVersionFromComposerJson(): string | ||
{ | ||
try { | ||
$json = json_decode( | ||
file_get_contents(__DIR__ . '/../../composer.json'), | ||
true | ||
); | ||
|
||
return $json['version']; | ||
} catch (\Throwable $e) { | ||
return 'unknown'; | ||
} | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
private function currentPackage(): string | ||
{ | ||
if (InstalledVersions::isInstalled('merch-one/laravel-api-sdk')) { | ||
return 'merch-one/laravel-api-sdk'; | ||
} | ||
|
||
return 'merch-one/php-api-sdk'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters