|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Automation tool mixed with code generator for easier continuous development |
|
4
|
|
|
* |
|
5
|
|
|
* @link https://github.com/hiqdev/hidev |
|
6
|
|
|
* @package hidev |
|
7
|
|
|
* @license BSD-3-Clause |
|
8
|
|
|
* @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/) |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace hidev\components; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* `version` file component. |
|
15
|
|
|
*/ |
|
16
|
|
|
class Version extends \hidev\base\ConfigFile |
|
17
|
|
|
{ |
|
18
|
|
|
protected $_file = 'version'; |
|
19
|
|
|
|
|
20
|
|
|
protected $fileRelease; |
|
21
|
|
|
protected $fileHash; |
|
22
|
|
|
protected $release; |
|
23
|
|
|
protected $date; |
|
24
|
|
|
protected $time; |
|
25
|
|
|
protected $zone; |
|
26
|
|
|
protected $hash; |
|
27
|
|
|
protected $commit; |
|
28
|
|
|
|
|
29
|
|
|
public function init() |
|
30
|
|
|
{ |
|
31
|
|
|
if ($this->exists()) { |
|
32
|
|
|
$line = trim($this->getFile()->read()); |
|
33
|
|
|
list($this->release, $this->date, $this->time, $this->zone, $this->hash) = explode(' ', $line); |
|
34
|
|
|
$this->fileRelease = $this->release; |
|
35
|
|
|
$this->fileHash = $this->hash; |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function load() |
|
40
|
|
|
{ |
|
41
|
|
|
$line = trim($this->exec('git', ['log', '-n', '1', '--pretty=%ai %H %s'])[0]); |
|
|
|
|
|
|
42
|
|
|
list($this->date, $this->time, $this->zone, $this->hash, $this->commit) = explode(' ', $line, 5); |
|
43
|
|
|
if ($this->hash !== $this->fileHash) { |
|
44
|
|
|
$this->release = implode('-', ['dev', $this->release, substr($this->hash, 0, 7)]); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function save() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->getFile()->write(implode(' ', [$this->release, $this->date, $this->time, $this->zone, $this->hash]) . "\n"); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function setRelease($release = null) |
|
54
|
|
|
{ |
|
55
|
|
|
$this->release = $this->getRelease($release); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function getRelease($release = null) |
|
59
|
|
|
{ |
|
60
|
|
|
return $release ?: $this->release ?: 'dev'; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function pretty() |
|
64
|
|
|
{ |
|
65
|
|
|
return implode(' ', [$this->release, $this->date, $this->time, $this->hash]); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function getAbspath() |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->getFile()->getAbspath(); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: