-
Notifications
You must be signed in to change notification settings - Fork 3
/
Version.php
40 lines (34 loc) · 894 Bytes
/
Version.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
namespace Concise;
class Version
{
public function findVendorFolder()
{
$path = __DIR__;
for ($i = 0; $i < 10; ++$i) {
$dir = scandir($path);
if (in_array('vendor', $dir)) {
return "$path/vendor";
}
$path .= "/..";
}
}
public function getVersionForPackage($packageName)
{
$vendor = $this->findVendorFolder(__DIR__);
if (!$vendor) {
return '';
}
$packages = json_decode(file_get_contents("$vendor/composer/installed.json"));
foreach ($packages as $package) {
if ($package->name === $packageName) {
return $package->version;
}
}
return '';
}
public function getConciseVersion()
{
return $this->getVersionForPackage('elliotchance/concise');
}
}