]>
git.agnieray.net Git - galette.git/blob - galette/lib/Galette/Core/CheckModules.php
995fd0fb60fb79df19fe17654bd5ff63d4bdd3d1
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Required modules checking
10 * Copyright © 2007-2014 The Galette Team
12 * This file is part of Galette (http://galette.tuxfamily.org).
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.
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.
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/>.
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2012-2014 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
34 * @link http://galette.tuxfamily.org
35 * @since Available since 0.7.1dev - 2012-03-12
38 namespace Galette\Core
;
41 * Required modules checking
46 * @author Johan Cwiklinski <johan@x-tnd.be>
47 * @copyright 2012-2014 The Galette Team
48 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
49 * @link http://galette.tuxfamily.org
50 * @since Available since 0.7.1dev - 2012-03-12
54 private $good = array();
55 private $should = array();
56 private $missing = array();
76 * @param boolean $do Whether to do checks, defaults to true
78 public function __construct($do = true)
86 * Check various modules and dispatch them beetween:
87 * - good: module that are present,
88 * - may: modules that may be present but are not,
89 * - should: modules that should be present but are not,
90 * - missing: required modules that are missing
92 * @param boolean $translated Use translations (default to true)
96 public function doCheck($translated = true)
98 $string = ($translated ?
_T("'%s' module") : "'%s' module");
99 foreach ($this->modules
as $name => $required) {
100 if ($name == 'pdo') {
101 //one of mysql or pgsql driver must be present
102 $mstring = "either 'mysql' or 'pgsql' PDO driver";
104 $mstring = _T("either 'mysql' or 'pgsql' PDO driver");
107 !extension_loaded('pdo_mysql')
108 && !extension_loaded('pdo_pgsql')
110 $this->missing
[] = $mstring;
112 $this->good
[$name] = $mstring;
115 $mstring = str_replace('%s', $name, $string);
116 if (!extension_loaded($name)) {
118 $this->missing
[] = $mstring;
120 $this->should
[] = $mstring;
123 $this->good
[$name] = str_replace('%s', $name, $string);
130 * HTML formatted results for checks
132 * @param boolean $translated Use translations (default to true)
136 public function toHtml($translated = true)
140 if (defined('GALETTE_THEME_DIR')) {
141 $img_dir = GALETTE_THEME_DIR
. 'images/';
143 $img_dir = GALETTE_TPL_SUBDIR
. 'images/';
146 if (count($this->missing
) > 0) {
147 $ko = ($translated ?
_T('Ko') : 'Ko');
148 foreach ($this->missing
as $m) {
149 $html .= '<li><span>' . $m . '</span><span><img src="' .
150 $img_dir . 'icon-invalid.png" alt="' .
151 $ko . '"/></span></li>';
155 if (count($this->good
) > 0) {
156 $ok = ($translated ?
_T('Ok') : 'Ok');
157 foreach ($this->good
as $m) {
158 $html .= '<li><span>' . $m . '</span><span><img src="' .
159 $img_dir . 'icon-valid.png" alt="' .
160 $ok . '"/></span></li>';
164 if (count($this->should
) > 0) {
165 foreach ($this->should
as $m) {
166 $html .= '<li><span>' . $m . '</span><span><img src="' .
167 $img_dir . 'icon-warning.png" alt=""' .
176 * Check if it is ok to use Galette with current modules
180 public function isValid()
182 return count($this->missing
) === 0;
186 * Check if a specific module is OK for that instance
188 * @param string $module Module name to check
192 public function isGood($module)
194 return isset($this->good
[$module]);
198 * Retrieve good modules
202 public function getGoods()
208 * Retrieve should modules
212 public function getShoulds()
214 return $this->should
;
218 * Retrieve missing modules
222 public function getMissings()
224 return $this->missing
;