. */ namespace SP\Config; use SP\Core\Exceptions\ConfigException; use SP\Util\Checks; /** * Class ConfigUtil * * @package Config */ class ConfigUtil { /** * Adaptador para convertir una cadena de extensiones a un array * * @param $filesAllowedExts * @return array */ public static function filesExtsAdapter(&$filesAllowedExts) { $exts = explode(',', $filesAllowedExts); array_walk($exts, function (&$value) { if (preg_match('/[^a-z0-9_-]+/i', $value)) { $value = null; } }); return $exts; } /** * Comprobar el archivo de configuración. * Esta función comprueba que el archivo de configuración exista y los permisos sean correctos. * * @throws \SP\Core\Exceptions\ConfigException */ public static function checkConfigDir() { if (!is_dir(APP_ROOT . DIRECTORY_SEPARATOR . 'config')) { clearstatcache(); throw new ConfigException(ConfigException::SP_CRITICAL, __('El directorio "/config" no existe', false)); } if (!is_writable(APP_ROOT . DIRECTORY_SEPARATOR . 'config')) { clearstatcache(); throw new ConfigException(ConfigException::SP_CRITICAL, __('No es posible escribir en el directorio "config"', false)); } $configPerms = decoct(fileperms(APP_ROOT . DIRECTORY_SEPARATOR . 'config') & 0777); if ($configPerms !== '750' && !Checks::checkIsWindows()) { clearstatcache(); throw new ConfigException( ConfigException::SP_ERROR, __('Los permisos del directorio "/config" son incorrectos', false), __('Actual:', false) . ' ' . $configPerms . ' - ' . __('Necesario: 750', false)); } } }