Skip to content

Commit dc6c35b

Browse files
committed
implemented getClientVersion()
1 parent ec39d95 commit dc6c35b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/MessageBird/Client.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace MessageBird;
44

5+
use PackageVersions\Versions;
6+
57
/**
68
* Class Client
79
*
@@ -15,6 +17,7 @@ class Client
1517
const VOICEAPI_ENDPOINT = 'https://voice.messagebird.com';
1618

1719
const CLIENT_VERSION = '1.14.1';
20+
const PACKAGE_NAME = 'messagebird/php-rest-api';
1821

1922
/**
2023
* @var string
@@ -242,4 +245,25 @@ private function getPhpVersion()
242245

243246
return 'PHP/' . PHP_VERSION_ID;
244247
}
248+
249+
/**
250+
* Get the current version of this package without hash or v-prefix
251+
* If this reposistory is checked out on a non-version-branch it will
252+
* have a format like dev-[branch]. (e.g. dev-master for the master branch)
253+
*
254+
* @return string
255+
*/
256+
private function getClientVersion()
257+
{
258+
$fullVersion = Versions::getVersion(static::PACKAGE_NAME);
259+
$splitVersion = explode('@', $fullVersion, 2);
260+
261+
if (strlen($splitVersion[0]) > 1 && $splitVersion[0]{0} == 'v') {
262+
// some tags ar v1.x.y, some are not (?)
263+
$versionWithoutVPrefix = substr($splitVersion[0], 1);
264+
} else {
265+
$versionWithoutVPrefix = $splitVersion[0];
266+
}
267+
return $versionWithoutVPrefix;
268+
}
245269
}

0 commit comments

Comments
 (0)