mirror of
https://github.com/nuxsmin/sysPass.git
synced 2026-03-10 02:16:58 +01:00
* [ADD] PHP module checker. Work in progress
This commit is contained in:
34
lib/SP/Core/Exceptions/CheckException.php
Normal file
34
lib/SP/Core/Exceptions/CheckException.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* sysPass
|
||||
*
|
||||
* @author nuxsmin
|
||||
* @link http://syspass.org
|
||||
* @copyright 2012-2017, Rubén Domínguez nuxsmin@$syspass.org
|
||||
*
|
||||
* This file is part of sysPass.
|
||||
*
|
||||
* sysPass is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* sysPass is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace SP\Core\Exceptions;
|
||||
|
||||
/**
|
||||
* Class CheckException
|
||||
* @package SP\Core\Exceptions
|
||||
*/
|
||||
class CheckException extends SPException
|
||||
{
|
||||
|
||||
}
|
||||
@@ -24,6 +24,8 @@
|
||||
|
||||
namespace SP\Core;
|
||||
|
||||
use SP\Core\Exceptions\CheckException;
|
||||
|
||||
/**
|
||||
* Class PhpModuleChecker
|
||||
* @package SP\Core
|
||||
@@ -49,11 +51,11 @@ class PhpModuleChecker
|
||||
];
|
||||
|
||||
/**
|
||||
* Missing modules
|
||||
* Available modules
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $missing;
|
||||
protected $available;
|
||||
|
||||
/**
|
||||
* PhpModuleChecker constructor.
|
||||
@@ -70,18 +72,139 @@ class PhpModuleChecker
|
||||
{
|
||||
$loaded = get_loaded_extensions();
|
||||
|
||||
$this->missing = array_filter(self::MODULES, function ($module) use ($loaded) {
|
||||
return !in_array($module, $loaded);
|
||||
$this->available = array_filter(self::MODULES, function ($module) use ($loaded) {
|
||||
return in_array($module, $loaded);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Comprobar si el módulo de LDAP está instalado.
|
||||
* Comprobar si el módulo está instalado.
|
||||
*
|
||||
* @throws CheckException
|
||||
*/
|
||||
public function checkCurlAvailable()
|
||||
{
|
||||
if (!$this->checkIsAvailable('curl')) {
|
||||
throw new CheckException(sprintf(__('Módulo \'%s\' no disponible'), 'curl'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Comprobar si el módulo está instalado.
|
||||
*
|
||||
* @param $module
|
||||
* @return bool
|
||||
*/
|
||||
public function ldapIsAvailable()
|
||||
public function checkIsAvailable(string $module)
|
||||
{
|
||||
return extension_loaded('ldap');
|
||||
return in_array(strtolower($module), $this->available);
|
||||
}
|
||||
|
||||
/**
|
||||
* Comprobar si el módulo está instalado.
|
||||
*
|
||||
* @throws CheckException
|
||||
*/
|
||||
public function checkLdapAvailable()
|
||||
{
|
||||
if (!$this->checkIsAvailable('ldap')) {
|
||||
throw new CheckException(sprintf(__('Módulo \'%s\' no disponible'), 'ldap'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Comprobar si el módulo está instalado.
|
||||
*
|
||||
* @throws CheckException
|
||||
*/
|
||||
public function checkSimpleXmlAvailable()
|
||||
{
|
||||
if (!$this->checkIsAvailable('simplexml')) {
|
||||
throw new CheckException(sprintf(__('Módulo \'%s\' no disponible'), 'simplexml'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Comprobar si el módulo está instalado.
|
||||
*
|
||||
* @throws CheckException
|
||||
*/
|
||||
public function checkPharAvailable()
|
||||
{
|
||||
if (!$this->checkIsAvailable('phar')) {
|
||||
throw new CheckException(sprintf(__('Módulo \'%s\' no disponible'), 'phar'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Comprobar si el módulo está instalado.
|
||||
*
|
||||
* @throws CheckException
|
||||
*/
|
||||
public function checkJsonAvailable()
|
||||
{
|
||||
if (!$this->checkIsAvailable('json')) {
|
||||
throw new CheckException(sprintf(__('Módulo \'%s\' no disponible'), 'json'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Comprobar si el módulo está instalado.
|
||||
*
|
||||
* @throws CheckException
|
||||
*/
|
||||
public function checkPdoAvailable()
|
||||
{
|
||||
if (!$this->checkIsAvailable('pdo')) {
|
||||
throw new CheckException(sprintf(__('Módulo \'%s\' no disponible'), 'pdo'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Comprobar si el módulo está instalado.
|
||||
*
|
||||
* @throws CheckException
|
||||
*/
|
||||
public function checkGettextAvailable()
|
||||
{
|
||||
if (!$this->checkIsAvailable('gettext')) {
|
||||
throw new CheckException(sprintf(__('Módulo \'%s\' no disponible'), 'gettext'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Comprobar si el módulo está instalado.
|
||||
*
|
||||
* @throws CheckException
|
||||
*/
|
||||
public function checkOpenSslAvailable()
|
||||
{
|
||||
if (!$this->checkIsAvailable('openssl')) {
|
||||
throw new CheckException(sprintf(__('Módulo \'%s\' no disponible'), 'openssl'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Comprobar si el módulo está instalado.
|
||||
*
|
||||
* @throws CheckException
|
||||
*/
|
||||
public function checkGdAvailable()
|
||||
{
|
||||
if (!$this->checkIsAvailable('gd')) {
|
||||
throw new CheckException(sprintf(__('Módulo \'%s\' no disponible'), 'gd'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Comprobar si el módulo está instalado.
|
||||
*
|
||||
* @throws CheckException
|
||||
*/
|
||||
public function checkMbstringAvailable()
|
||||
{
|
||||
if (!$this->checkIsAvailable('mbstring')) {
|
||||
throw new CheckException(sprintf(__('Módulo \'%s\' no disponible'), 'mbstring'));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user