Skip to content

Commit

Permalink
ADD configFile trad
Browse files Browse the repository at this point in the history
  • Loading branch information
tomitomas committed Aug 30, 2024
1 parent 8d98379 commit 6a99cab
Showing 1 changed file with 52 additions and 34 deletions.
86 changes: 52 additions & 34 deletions src/tomitomasEqLogicTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,29 @@

trait tomitomasEqLogicTrait {

public function createCommands(string $file, string $type) {
$configFile = self::getFileContent($file);
$dict = $configFile['dictionary'];
private static function getConfigFileContent($filePath) {
if (!file_exists($filePath)) {
throw new Exception(__("Fichier de configuration non trouvé", __FILE__) . ' ' . $filePath);
}
$content = file_get_contents($filePath);
if (!is_json($content)) {
throw new Exception(__("Fichier de configuration incorrecte", __FILE__) . ' ' . $filePath);
}
$content = translate::exec($content, realpath($filePath));
return json_decode($content, true);
}

public function createCommands($filePath, $type = null) {
try {
if (isset($configFile['cmds'][$type])) {
$this->createCommandsFromConfigFile($configFile['cmds'][$type], $dict);

// on traduit le fichier de configuration
$configFile = self::getConfigFileContent($filePath);

// on lance la création des commandes (déjà traduites)
if ($type == null) {
$this->createCommandsFromConfig($configFile['cmds']);
} elseif (isset($configFile['cmds'][$type])) {
$this->createCommandsFromConfig($configFile['cmds'][$type]);
} else {
self::error($type . ' not found in config');
}
Expand All @@ -32,7 +49,7 @@ public static function getFileContent($path) {
return $content;
}

public function createCommandsFromConfigFile($commands, $dict) {
public function createCommandsFromConfig($commands) {
$cmd_updated_by = array();
foreach ($commands as $cmdData) {
$cmd = $this->getCmd(null, $cmdData["logicalId"]);
Expand Down Expand Up @@ -72,10 +89,6 @@ public function createCommandsFromConfigFile($commands, $dict) {

if (isset($cmdData['configuration'])) {
foreach ($cmdData['configuration'] as $key => $value) {
if ($key == 'listValueToCreate') {
$key = 'listValue';
$value = self::createListOption(explode(";", $value), $dict);
}
$cmd->setConfiguration($key, $value);
}
}
Expand Down Expand Up @@ -131,8 +144,36 @@ public static function getPlurial($nb) {
return ($nb > 1) ? 's' : '';
}

/**
public static function getConfigForCommunity($withQuote = true) {

$infoPlugin = '<b>Version OS</b> : ' . system::getDistrib() . ' ' . system::getOsVersion() . '<br/>';

$infoPlugin .= '<b>Version PHP</b> : ' . phpversion();

if ($withQuote) {
return self::getPreformattedText($infoPlugin);
}

return $infoPlugin;
}

public static function getPreformattedText($string) {
return '<br/>```text<br/>' . str_replace(array('<b>', '</b>', '&nbsp;'), array('', '', ' '), $string) . '<br/>```<br/>';
}

public static function backupExclude() {
return [
'resources/venv'
];
}


/*******************************
* From @Mips2648
******************************* /
/**
* Allow to perform a // task exec : now or later
*
* @param string $_method
Expand Down Expand Up @@ -163,29 +204,6 @@ public static function executeAsync(string $_method, $_option = null, $_date = '
}
}

public static function getConfigForCommunity($withQuote = true) {

$infoPlugin = '<b>Version OS</b> : ' . system::getDistrib() . ' ' . system::getOsVersion() . '<br/>';

$infoPlugin .= '<b>Version PHP</b> : ' . phpversion();

if ($withQuote) {
return self::getPreformattedText($infoPlugin);
}

return $infoPlugin;
}

public static function getPreformattedText($string) {
return '<br/>```text<br/>' . str_replace(array('<b>', '</b>', '&nbsp;'), array('', '', ' '), $string) . '<br/>```<br/>';
}

public static function backupExclude() {
return [
'resources/venv'
];
}

private static function pythonRequirementsInstalled(string $pythonPath, string $requirementsPath) {
if (!file_exists($pythonPath) || !file_exists($requirementsPath)) {
return false;
Expand Down

0 comments on commit 6a99cab

Please sign in to comment.