3
* Copyright (c) 2013-2014, Sebastian Bergmann <sebastian@phpunit.de>.
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions
10
* * Redistributions of source code must retain the above copyright
11
* notice, this list of conditions and the following disclaimer.
13
* * Redistributions in binary form must reproduce the above copyright
14
* notice, this list of conditions and the following disclaimer in
15
* the documentation and/or other materials provided with the
18
* * Neither the name of Sebastian Bergmann nor the names of his
19
* contributors may be used to endorse or promote products derived
20
* from this software without specific prior written permission.
22
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
* POSSIBILITY OF SUCH DAMAGE.
36
* @author Sebastian Bergmann <sebastian@phpunit.de>
37
* @copyright 2013-2014 Sebastian Bergmann <sebastian@phpunit.de>
38
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
39
* @link http://github.com/sebastianbergmann/version
40
* @since File available since Release 1.0.0
43
namespace SebastianBergmann;
47
* @author Sebastian Bergmann <sebastian@phpunit.de>
48
* @copyright 2013-2014 Sebastian Bergmann <sebastian@phpunit.de>
49
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
50
* @link http://github.com/sebastianbergmann/version
51
* @since Class available since Release 1.0.0
60
* @param string $release
63
public function __construct($release, $path)
65
$this->release = $release;
72
public function getVersion()
74
if ($this->version === null) {
75
if (count(explode('.', $this->release)) == 3) {
76
$this->version = $this->release;
78
$this->version = $this->release . '-dev';
81
$git = $this->getGitInformation($this->path);
84
if (count(explode('.', $this->release)) == 3) {
85
$this->version = $git;
87
$git = explode('-', $git);
89
$this->version = $this->release . '-' . end($git);
94
return $this->version;
99
* @return boolean|string
101
private function getGitInformation($path)
103
if (!is_dir($path . DIRECTORY_SEPARATOR . '.git')) {
109
$result = @exec('git describe --tags 2>&1', $output, $returnCode);
112
if ($returnCode !== 0) {