summaryrefslogtreecommitdiff
path: root/src/Helpers/Version.php
blob: 97fe6ef366229a7f423f66f1b9d908a45f3b5a0d (plain)
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
41
42
<?php

namespace Engelsystem\Helpers;

use Engelsystem\Config\Config;

class Version
{
    /** @var Config */
    protected $config;

    /** @vat string */
    protected $storage;

    /** @var string */
    protected $versionFile = 'VERSION';

    /**
     * @param string $storage
     * @param Config $config
     */
    public function __construct(string $storage, Config $config)
    {
        $this->storage = $storage;
        $this->config = $config;
    }

    /**
     * @return string
     */
    public function getVersion()
    {
        $file = $this->storage . DIRECTORY_SEPARATOR . $this->versionFile;

        $version = 'n/a';
        if (file_exists($file)) {
            $version = trim(file_get_contents($file));
        }

        return $this->config->get('version', $version);
    }
}