]> git.agnieray.net Git - galette.git/blob - galette/lib/Galette/Core/Galette.php
4674f20e428f0de7dc2983c2d038176f69ae1bdd
[galette.git] / galette / lib / Galette / Core / Galette.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Galette application instance
7 *
8 * PHP version 5
9 *
10 * Copyright © 2020 The Galette Team
11 *
12 * This file is part of Galette (http://galette.tuxfamily.org).
13 *
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
26 *
27 * @category Core
28 * @package Galette
29 *
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2020 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
33 * @link https://galette.eu
34 * @since Available since 0.9.4-dev - 2020-05-18
35 */
36
37 namespace Galette\Core;
38
39 /**
40 * Galette application instance
41 *
42 * @category Core
43 * @name Telemetry
44 * @package Galette
45 * @author Johan Cwiklinski <johan@x-tnd.be>
46 * @copyright 2020 The Galette Team
47 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
48 * @link https://galette.eu
49 * @since Available since 0.9.4-dev - 2020-05-18
50 */
51 class Galette
52 {
53 /**
54 * Retrieve Galette version from git, if present.
55 *
56 * @param boolean $time Include time and timezone. Defaults to false.
57 *
58 * @return string
59 */
60 public static function gitVersion($time = false)
61 {
62 $galette_version = GALETTE_VERSION;
63
64 //used for both gith and nightly installs
65 $version = str_replace('-dev', '-git', GALETTE_VERSION);
66 if (strstr($version, '-git') === false) {
67 $version .= '-git';
68 }
69
70 if (is_dir(GALETTE_ROOT.'../.git')) {
71 $commitHash = trim(exec('git log --pretty="%h" -n1 HEAD'));
72
73 $commitDate = new \DateTime(trim(exec('git log -n1 --pretty=%ci HEAD')));
74
75 $galette_version = sprintf(
76 '%s-%s (%s)',
77 $version,
78 $commitHash,
79 $commitDate->format(($time ? 'Y-m-d H:i:s T' : 'Y-m-d'))
80 );
81 } elseif (GALETTE_NIGHTLY !== false) {
82 $galette_version = $version . '-' . GALETTE_NIGHTLY;
83 }
84 return $galette_version;
85 }
86 }