Skip to content
Snippets Groups Projects
Commit 1c6f55f0 authored by Giovannoni Laurent's avatar Giovannoni Laurent
Browse files

FIX delete non usefull files

parent 6fba0d36
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,6 @@ require_once 'core/services/Abstract.php';
require_once 'core/core_tables.php';
require_once 'core/class/class_functions.php';
require_once 'core/class/class_db_pdo.php';
require_once 'core/services/Logs.php';
/**
* Fonctions pour réaliser le CRUD sur la base de donnees
......
<?php
/**
* @copyright 2016 capgemini
*
* This file is part of Maarch Framework.
*
* Maarch Framework 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.
*
* Maarch Framework 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 Maarch Framework. If not, see <http://www.gnu.org/licenses/>.
*/
require_once 'core'. DIRECTORY_SEPARATOR . 'services'. DIRECTORY_SEPARATOR . 'LogsAbstract.php';
class Core_Logs_Service extends Core_LogsAbstract_Service {
// Do your stuff
}
<?php
/**
* @copyright 2017 Maarch
*
* This file is part of Maarch Framework.
*
* Maarch Framework 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.
*
* Maarch Framework 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 Maarch Framework. If not, see <http://www.gnu.org/licenses/>.
*/
require_once 'core'. DIRECTORY_SEPARATOR . 'services'. DIRECTORY_SEPARATOR . 'Abstract.php';
require_once 'core'. DIRECTORY_SEPARATOR . 'services'. DIRECTORY_SEPARATOR . 'String.php';
if (!defined('_LOG4PHP'))
define(
'_LOG4PHP',
'log4php'
);
if (!defined('_BDD'))
define(
'_BDD',
'database'
);
if (!defined('_LOGGER_NAME_TECH_DEFAULT'))
define(
'_LOGGER_NAME_TECH_DEFAULT',
'loggerTechnique'
);
if (!defined('_LOGGER_NAME_FUNC_DEFAULT'))
define(
'_LOGGER_NAME_FUNC_DEFAULT',
'loggerFonctionnel'
);
require_once 'apps'. DIRECTORY_SEPARATOR . 'maarch_entreprise'. DIRECTORY_SEPARATOR . 'tools'. DIRECTORY_SEPARATOR . 'log4php'. DIRECTORY_SEPARATOR . 'Logger.php';
class Core_LogsAbstract_Service extends Core_Abstract_Service {
protected static function getLoggingMethodConfFile()
{
$xmlFileName = 'logging_method.xml';
if (file_exists($sLoggingMethodConfFile = 'custom'
.DIRECTORY_SEPARATOR.$_SESSION['custom_override_id']
.DIRECTORY_SEPARATOR . 'apps'
.DIRECTORY_SEPARATOR.$_SESSION['config']['app_id']
.DIRECTORY_SEPARATOR.'xml'
.DIRECTORY_SEPARATOR.$xmlFileName
)) {
return $sLoggingMethodConfFile;
}
if (file_exists($sLoggingMethodConfFile =
'apps'
.DIRECTORY_SEPARATOR.$_SESSION['config']['app_id']
.DIRECTORY_SEPARATOR.'xml'
.DIRECTORY_SEPARATOR.$xmlFileName
)) {
return $sLoggingMethodConfFile;
}
return null;
}
public static function getLoggingFormat(array $aArgs = []) {
self::checkRequired($aArgs,['key']);
self::checkNumeric($aArgs,['key']);
$logging_methods = self::getLoggingMethod($aArgs);
return empty($logging_methods[$aArgs['key']]['LOG_FORMAT']) ? '[%RESULT%][%CODE_METIER%][%WHERE%][%ID%][%HOW%][%USER%][%WHAT%][%ID_MODULE%][%REMOTE_IP%]' : $logging_methods[$aArgs['key']]['LOG_FORMAT'];
}
public static function getLoggingCodeMetier(array $aArgs = []) {
self::checkRequired($aArgs,['key']);
self::checkNumeric($aArgs,['key']);
$logging_methods = self::getLoggingFormat($aArgs);
return empty($logging_methods[$aArgs['key']]['CODE_METIER']) ? '[%RESULT%][%CODE_METIER%][%WHERE%][%ID%][%HOW%][%USER%][%WHAT%][%ID_MODULE%][%REMOTE_IP%]' : $logging_methods[$aArgs['key']]['CODE_METIER'];
}
/**
* Get the logging method in the configuration file
*/
protected static function getLoggingMethod(array $aArgs = []) {
$sLoggingMethodConfFile = self::getLoggingMethodConfFile();
$logging_methods = [];
if ( ! $sLoggingMethodConfFile = self::getLoggingMethodConfFile() ) {
$logging_methods[0]['ID'] = 'database';
$logging_methods[0]['ACTIVATED'] = true;
$logging_methods[1]['ID'] = 'log4php';
$logging_methods[1]['ACTIVATED'] = true;
$logging_methods[1]['LOGGER_NAME_TECH'] = 'loggerTechnique';
$logging_methods[1]['LOGGER_NAME_FUNC'] = 'loggerFonctionnel';
$logging_methods[1]['LOG_FORMAT'] = '[%RESULT%][%CODE_METIER%][%WHERE%][%ID%][%HOW%][%USER%][%WHAT%][%ID_MODULE%][%REMOTE_IP%]';
$logging_methods[1]['CODE_METIER'] = 'MAARCH';
return $logging_methods;
}
if (! file_exists($sLoggingMethodConfFile) ) {
throw new \Exception('not file_exists : '.$sLoggingMethodConfFile);
}
$xmlConfig = @simplexml_load_file($sLoggingMethodConfFile);
if (! $xmlConfig) {
throw new \Exception('simplexml_load_file failed : '.$sLoggingMethodConfFile);
}
if (! $xmlConfig->METHOD) {
throw new \Exception('no data METHOD found : '.$sLoggingMethodConfFile);
}
foreach ($xmlConfig->METHOD as $METHOD) {
$id = ((string)$METHOD->ID);
$activated = ((boolean)$METHOD->ENABLED);
$loggerNameTech = ((string)$METHOD->LOGGER_NAME_TECH);
$loggerNameFunc = ((string)$METHOD->LOGGER_NAME_FUNC);
$logFormat = ((string)$METHOD->APPLI_LOG_FORMAT);
$codeMetier = ((string)$METHOD->CODE_METIER);
array_push(
$logging_methods,
array(
'ID' => $id,
'ACTIVATED' => $activated,
'LOGGER_NAME_TECH' => $loggerNameTech,
'LOGGER_NAME_FUNC' => $loggerNameFunc,
'LOG_FORMAT' => $logFormat,
'CODE_METIER' => $codeMetier
)
);
}
return $logging_methods;
}
protected static function getConfFile(array $aArgs = []) {
if ( empty($_SESSION['config']['app_id']) ) {
$_SESSION['config']['app_id'] = 'maarch_entreprise';
}
if (
!empty($_SESSION['config']['corepath']) && !empty($_SESSION['custom_override_id'])
&& file_exists($configFileLog4PHP =
$_SESSION['config']['corepath']. DIRECTORY_SEPARATOR . 'custom'
. DIRECTORY_SEPARATOR . $_SESSION['custom_override_id']
. DIRECTORY_SEPARATOR . 'apps'
. DIRECTORY_SEPARATOR . $_SESSION['config']['app_id']
. DIRECTORY_SEPARATOR . 'xml'
. DIRECTORY_SEPARATOR . 'log4php.xml'
)) {
return $configFileLog4PHP;
}
if (file_exists($configFileLog4PHP =
'apps'
. DIRECTORY_SEPARATOR . $_SESSION['config']['app_id']
. DIRECTORY_SEPARATOR . 'xml'
. DIRECTORY_SEPARATOR . 'log4php.xml'
)) {
return $configFileLog4PHP;
}
return 'apps'
. DIRECTORY_SEPARATOR . $_SESSION['config']['app_id']
. DIRECTORY_SEPARATOR . 'xml'
. DIRECTORY_SEPARATOR . 'log4php.default.xml';
}
protected static function format_message(array &$aArgs) {
$aArgs['message'] = @$aArgs['message'];
switch (true) {
case is_object($aArgs['message']):
if ( $aArgs['message'] instanceof \Exception ) {
$e = $aArgs['message'];
$aArgs['code'] = $e->getCode();
$aArgs['message'] = 'Exception: '.$e->getMessage();
$aArgs['debug'] = $e->getTraceAsString();
break;
}
$aArgs['message'] = '--object--';
break;
case is_array($aArgs['message']):
$aArgs['message'] = '--array--';
break;
default:
$aArgs['message'] = (string)$aArgs['message'];
break;
}
$aArgs['message'] = str_replace("\n", '\n', $aArgs['message']);
// Old method :
$formatter = new functions();
$aArgs['message'] = $formatter->wash_html(
$aArgs['message'],
''
);
$aArgs['message'] = Core_String_Service::wd_remove_accents($aArgs['message']);
if(!empty($_SESSION['user']['UserId'])){
$aArgs['message'] = '[' . $_SESSION['user']['UserId'] . '] ' . $aArgs['message'];
}
return $aArgs;
}
protected static function logs(array $aArgs = []) {
// Initialisation du Logger :
Logger::configure(
self::getConfFile()
);
if ( @$aArgs['class'] ) {
Logger::getLogger($aArgs['class']);
}
$aLoggingMethods = self::getLoggingMethod();
$aArgs = self::format_message($aArgs);
if ( @$aArgs['class'] ) {
$sLog .= "[class:{$aArgs['class']}]";
Logger::getLogger($aArgs['class']);
}
foreach ($aLoggingMethods as $logging_method) {
if ( ! $logging_method['ACTIVATED'] ) {
continue;
}
if (isset($aArgs['isTech']) && $aArgs['isTech']) {
$logger = Logger::getLogger(
$logging_method['LOGGER_NAME_TECH']
);
} else {
if(!isset($logging_method['LOGGER_NAME_FUNC'])){
$logging_method['LOGGER_NAME_FUNC'] = 'loggerFonctionnel';
}
$logger = Logger::getLogger(
$logging_method['LOGGER_NAME_FUNC']
);
}
if ( empty($logger) ) {
throw new \Exception('logger not-loading', 1);
}
// Format :
$sLog = '';
if ( @$aArgs['file'] ) {
$sLog .= "[file:{$aArgs['file']}]";
}
if ( @$aArgs['class'] ) {
$sLog .= "[class:{$aArgs['class']}]";
}
if ( @$aArgs['function'] ) {
$sLog .= "[function:{$aArgs['function']}]";
}
if ( @$aArgs['code'] ) {
$aArgs['code'] = (int)$aArgs['code'];
$sLog .= "[code:{$aArgs['code']}]";
}
if(!isset($logging_method['CODE_METIER'])){
$logging_method['CODE_METIER'] = 'SIPol';
}
$sLog = str_replace('%CODE_METIER%', $logging_method['CODE_METIER'], "{$sLog}{$aArgs['message']}");
// Log :
switch ($aArgs['type']) {
case 'debug':
case _LEVEL_DEBUG:
$logger->debug($sLog);
break;
case 'info':
case _LEVEL_INFO:
$logger->info($sLog);
break;
case 'warning':
case _LEVEL_WARN:
$logger->warn($sLog);
break;
case 'error':
case _LEVEL_ERROR:
$logger->error($sLog);
break;
case _LEVEL_FATAL:
$logger->fatal($sLog);
break;
default:
$logger->error($sLog);
}
}
return true;
}
public static function debug(array $aArgs = []) {
$aArgs['type'] = 'debug';
return self::logs($aArgs);
}
public static function info(array $aArgs = []) {
$aArgs['type'] = 'info';
return self::logs($aArgs);
}
public static function warning(array $aArgs = []) {
$aArgs['type'] = 'warning';
return self::logs($aArgs);
}
public static function error(array $aArgs = []) {
$aArgs['type'] = 'error';
return self::logs($aArgs);
}
public static function fatal(array $aArgs = []) {
$aArgs['type'] = _LEVEL_FATAL;
return self::logs($aArgs);
}
/*
timestart : timestamp Debut
timeend : timestamp Fin
level : level log4php
message : message dans les logs
*/
public static function executionTimeLog($timestart, $timeend, $level, $message){
if(empty($timeend)){
$timeend = microtime(true);
}
$time = $timeend - $timestart;
self::$level(['message' => $message.'. Done in ' . number_format($time, 3) . ' secondes.']);
}
}
<?php
/**
* @copyright 2016 capgemini
*
* This file is part of Maarch Framework.
*
* Maarch Framework 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.
*
* Maarch Framework 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 Maarch Framework. If not, see <http://www.gnu.org/licenses/>.
*/
require_once 'core/services/ModulesAbstract.php';
class Core_Modules_Service extends Core_ModulesAbstract_Service {
// Do your stuff
}
\ No newline at end of file
<?php
/**
* @copyright 2017 Maarch
*
* This file is part of Maarch Framework.
*
* Maarch Framework 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.
*
* Maarch Framework 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 Maarch Framework. If not, see <http://www.gnu.org/licenses/>.
*/
require_once 'core/services/Abstract.php';
class Core_ModulesAbstract_Service extends Core_Abstract_Service {
public static function getApiMethod() {
$aMethod = parent::getApiMethod();
$aMethod['getList'] = 'getList';
return $aMethod;
}
/**
* Renvoie la liste des modules
* @throw \Exception $e
* @param array $args
* @return array $aModules
**/
public static function getList(array $args = []) {
if ( ! file_exists('modules') ) {
throw new \Exception('path modules not-found');
}
$aDir = scandir('modules');
$aModules = [];
foreach ($aDir as $dir) {
if ( '.'==$dir[0]) continue;
if ( !is_dir("modules/$dir") ) continue;
$aModules[$dir] = $dir;
}
return $aModules;
}
/**
* Renvoie la liste des services
* @param array $args
* - require : inclue directement la definition du service si ce n'ai pas fait
* @return array $aModules
**/
public static function getServicesList(array $args = []) {
// Initialisation :
$aServices = [];
$aServices['apps'] = [];
// Recherche dans Apps :
foreach ([
$_SESSION['config']['corepath'].'custom'.DIRECTORY_SEPARATOR.$_SESSION['custom_override_id']."/apps/maarch_entreprise/services",
"apps/maarch_entreprise/services",
] as $sPathModuleService) {
if ( is_dir($sPathModuleService) ) {
$aDir = scandir($sPathModuleService);
foreach ($aDir as $dir) {
if ( '.'==$dir[0]) continue;
if ( preg_match('/svn-commit/', $dir) ) continue;
if ( !is_file("$sPathModuleService/$dir") ) continue;
$sService = preg_replace('/\.php$/', '', $dir);
$sService = 'Apps_'.ucfirst($sService).'_Service';
if ( !empty($aServices['apps'][$sService]) ) continue; // Déjà fait
if ( !class_exists($sService) && !empty($args['require']) ) require_once "$sPathModuleService/$dir";
$aServices['apps'][$sService] = $sService;
}
}
}
if ( empty($aServices['apps']) ) {
unset($aServices['apps']);
}
// Recherche dans Core :
$aServices['core'] = [];
foreach ([
$_SESSION['config']['corepath'].'custom'.DIRECTORY_SEPARATOR.$_SESSION['custom_override_id']."/core/services",
"core/services",
] as $sPathModuleService) {
if ( is_dir($sPathModuleService) ) {
$aDir = scandir($sPathModuleService);
foreach ($aDir as $dir) {
if ( '.'==$dir[0]) continue;
if ( preg_match('/svn-commit/', $dir) ) continue;
if ( !is_file("$sPathModuleService/$dir") ) continue;
$sService = preg_replace('/\.php$/', '', $dir);
$sService = 'Core_'.ucfirst($sService).'_Service';
if ( !empty($aServices['core'][$sService]) ) continue; // Déjà fait
if ( !class_exists($sService) && !empty($args['require']) ) require_once "$sPathModuleService/$dir";
$aServices['core'][$sService] = $sService;
}
}
}
if ( empty($aServices['core']) ) {
unset($aServices['core']);
}
// Recherche dans tous les modules :
$aModules = self::getList();
foreach ($aModules as $sModule) {
// Recherche dans maarch + custom :
foreach ([
$_SESSION['config']['corepath'].'custom'.DIRECTORY_SEPARATOR.$_SESSION['custom_override_id']."/modules/{$sModule}/services",
"modules/{$sModule}/services",
] as $sPathModuleService) {
if ( is_dir($sPathModuleService) ) {
$aDir = scandir($sPathModuleService);
foreach ($aDir as $dir) {
if ( '.'==$dir[0]) continue;
if ( preg_match('/svn-commit/', $dir) ) continue;
if ( !is_file("$sPathModuleService/$dir") ) continue;
$sService = preg_replace('/\.php$/', '', $dir);
$sService = ucfirst($sModule).'_'.ucfirst($sService).'_Service';
if ( !empty($aServices[$sModule][$sService]) ) continue; // Déjà fait
if ( !class_exists($sService) && !empty($args['require']) ) require_once "$sPathModuleService/$dir";
$aServices[$sModule][$sService] = $sService;
}
}
}
if ( empty($aServices[$sModule]) ) {
unset($aServices[$sModule]);
}
}
// Retour :
return $aServices;
}
}
\ No newline at end of file
<?php
/**
* @copyright 2017 Maarch
*
* This file is part of Maarch Framework.
*
* Maarch Framework 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.
*
* Maarch Framework 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 Maarch Framework. If not, see <http://www.gnu.org/licenses/>.
*/
require_once 'core/services/Logs.php';
/**
* Service des gestion des appels rest
*/
class Core_Rest_Service {
/**
* Constructeur
*/
public function __construct() {
}
/**
* Encodage en json
* @param array $json Liste d'arguments
* - string status [description]
* - string result [description]
* - string errors [description]
* - string debug [description]
*/
public function json(array $json) {
header('Content-Type: application/json');
if ( !isset($json['status']) ) {
throw new \Exception('$oServiceRest->return([...]) : status not-isset');
}
if ( !isset($json['result']) ) {
throw new \Exception('$oServiceRest->return([...]) : result not-isset');
}
if ( !isset($json['errors']) ) {
throw new \Exception('$oServiceRest->return([...]) : error not-isset');
}
if ( empty($json['debug']) ) {
$json['debug'] = null;
}
if ( is_array($json['result']) ) {
$json['result_count'] = count($json['result']);
}
echo json_encode($json);
exit;
}
/**
* Renvoi avec succès des données encodées en json
* @param array $json Liste d'arguments
* - string status [description]
* - string result [description]
* - string errors [description]
* - string debug [description]
*/
public function returnSuccess(array $json) {
$this->json([
'status' => empty($json['status']) ? 0 : $json['status'],
'result' => $json['result'],
'errors' => [],
'debug' => empty($json['debug'])? null : $json['debug'],
]);
}
/**
* Renvoi avec erreur des données encodées en json
* @param array $json Liste d'arguments
* - string status [description]
* - string result [description]
* - string errors [description]
* - string debug [description]
*/
public function returnError(array $json) {
if ( is_string($json['errors'])) {
$json['errors'] = [$json['errors']];
}
$json['status'] = empty($json['status']) ? -1 : $json['status'];
$json['debug'] = empty($json['debug'])? null : $json['debug'];
Core_Logs_Service::error([
'message' => 'Exception : '.$json['errors'][0]."\n".$json['debug'],
'code' => $json['status'],
'file' => __FILE__,
]);
$this->json([
'status' => $json['status'],
'result' => false,
'errors' => $json['errors'],
'debug' => DEBUG ? $json['debug'] : null,
]);
}
public function returnWarning(array $json) {
if ( is_string($json['errors'])) {
$json['errors'] = [$json['errors']];
}
$json['status'] = empty($json['status']) ? -1 : $json['status'];
$json['debug'] = empty($json['debug'])? null : $json['debug'];
Core_Logs_Service::warning([
'message' => 'Exception : '.$json['errors'][0]."\n".$json['debug'],
'code' => $json['status'],
'file' => __FILE__,
]);
$this->json([
'status' => $json['status'],
'result' => false,
'errors' => $json['errors'],
'debug' => DEBUG ? $json['debug'] : null,
]);
}
}
<?php
/**
* @copyright 2016 capgemini
*
* This file is part of Maarch Framework.
*
* Maarch Framework 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.
*
* Maarch Framework 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 Maarch Framework. If not, see <http://www.gnu.org/licenses/>.
*/
require_once 'core'. DIRECTORY_SEPARATOR . 'services'. DIRECTORY_SEPARATOR . 'StringAbstract.php';
class Core_String_Service extends Core_StringAbstract_Service {
// Do your stuff
}
<?php
/**
* @copyright 2016 capgemini
*
* This file is part of Maarch Framework.
*
* Maarch Framework 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.
*
* Maarch Framework 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 Maarch Framework. If not, see <http://www.gnu.org/licenses/>.
*/
require_once 'core'. DIRECTORY_SEPARATOR . 'services'. DIRECTORY_SEPARATOR . 'Abstract.php';
class Core_StringAbstract_Service extends Core_Abstract_Service {
/**
* Delete accents
*
* @param $str (string)
* @param $charset = 'utf-8' (string)
*
* @return string $str
*/
public static function wd_remove_accents(
$str,
$charset ='utf-8'
)
{
$str = htmlentities(
$str,
ENT_NOQUOTES,
"utf-8"
);
$str = preg_replace(
'#\&([A-za-z])(?:uml|circ|tilde|acute|grave|cedil|ring)\;#',
'\1',
$str
);
$str = preg_replace(
'#\&([A-za-z]{2})(?:lig)\;#',
'\1',
$str
);
$str = preg_replace(
'#\&[^;]+\;#',
'',
$str
);
return $str;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment