Commit bf27ba04d7367f003726045f07d3cff86e0232b8
1 parent
f7093283
Exists in
master
and in
66 other branches
Add templated parameters support
Showing
10 changed files
with
318 additions
and
25 deletions
Show diff stats
src/InputOutput/IHMImpl/Config/IHMConfigClass.php
@@ -14,7 +14,13 @@ class IHMConfigClass | @@ -14,7 +14,13 @@ class IHMConfigClass | ||
14 | private static $constantsFile = "constants.xml"; | 14 | private static $constantsFile = "constants.xml"; |
15 | 15 | ||
16 | private static $functionsFile = "functions.xml"; | 16 | private static $functionsFile = "functions.xml"; |
17 | + | ||
18 | + private static $paramTemplateDir = "ParamTemplate/"; | ||
17 | 19 | ||
20 | + private static $paramTemplateFile = "ParamTemplateList.xml"; | ||
21 | + | ||
22 | + private static $paramTemplateGenerateDir = "generateTemplateParams"; | ||
23 | + | ||
18 | private static $dataDir = "data/"; | 24 | private static $dataDir = "data/"; |
19 | 25 | ||
20 | private static $compilationDir = "compilation/"; | 26 | private static $compilationDir = "compilation/"; |
@@ -76,6 +82,21 @@ class IHMConfigClass | @@ -76,6 +82,21 @@ class IHMConfigClass | ||
76 | return IHM_SRC_DIR.self::$genericDataDir.self::$functionsDir.self::$functionsFile; | 82 | return IHM_SRC_DIR.self::$genericDataDir.self::$functionsDir.self::$functionsFile; |
77 | } | 83 | } |
78 | 84 | ||
85 | + public static function getParamTemplateFilePath($fileName) | ||
86 | + { | ||
87 | + return IHM_SRC_DIR.self::$genericDataDir.self::$paramTemplateDir.$fileName.".xml"; | ||
88 | + } | ||
89 | + | ||
90 | + public static function getTemplateParamGeneratePath() | ||
91 | + { | ||
92 | + return self::getUserPath().self::$paramTemplateGenerateDir; | ||
93 | + } | ||
94 | + | ||
95 | + public static function getParamTemplateListFilePath() | ||
96 | + { | ||
97 | + return IHM_SRC_DIR.self::$genericDataDir.self::$paramTemplateDir.self::$paramTemplateFile; | ||
98 | + } | ||
99 | + | ||
79 | public static function getUserParamManagerFilePath() | 100 | public static function getUserParamManagerFilePath() |
80 | { | 101 | { |
81 | return self::getUserWSPath().self::$userParamMgrFile; | 102 | return self::getUserWSPath().self::$userParamMgrFile; |
src/InputOutput/IHMImpl/ParamInfo/IHMInputOutputParamInfoClass.php
@@ -8,12 +8,14 @@ | @@ -8,12 +8,14 @@ | ||
8 | class IHMInputOutputParamInfoClass implements InputOutputInterface | 8 | class IHMInputOutputParamInfoClass implements InputOutputInterface |
9 | { | 9 | { |
10 | private $paramInfoData = null; | 10 | private $paramInfoData = null; |
11 | + private $paramTemplateMgr = null; | ||
11 | 12 | ||
12 | /* | 13 | /* |
13 | * @brief Constructor | 14 | * @brief Constructor |
14 | */ | 15 | */ |
15 | function __construct() | 16 | function __construct() |
16 | { | 17 | { |
18 | + $this->paramTemplateMgr = new IHMParamTemplateClass(); | ||
17 | } | 19 | } |
18 | 20 | ||
19 | /* | 21 | /* |
@@ -42,6 +44,10 @@ class IHMInputOutputParamInfoClass implements InputOutputInterface | @@ -42,6 +44,10 @@ class IHMInputOutputParamInfoClass implements InputOutputInterface | ||
42 | if (!isset($input->paramId) || empty($input->paramId)) | 44 | if (!isset($input->paramId) || empty($input->paramId)) |
43 | throw new Exception("Param info request need a param id as argument"); | 45 | throw new Exception("Param info request need a param id as argument"); |
44 | 46 | ||
47 | + $templatedParams = $this->paramTemplateMgr->getParamTemplates(); | ||
48 | + | ||
49 | + if (array_key_exists($input->paramId, $templatedParams)) | ||
50 | + $this->paramInfoData->setTemplateInfo($templatedParams[$input->paramId]); | ||
45 | 51 | ||
46 | $paramInfoFilePath = IHMConfigClass::getLocalParamInfoPath().'info_'.$input->paramId.".xml"; | 52 | $paramInfoFilePath = IHMConfigClass::getLocalParamInfoPath().'info_'.$input->paramId.".xml"; |
47 | 53 | ||
@@ -86,6 +92,9 @@ class IHMInputOutputParamInfoClass implements InputOutputInterface | @@ -86,6 +92,9 @@ class IHMInputOutputParamInfoClass implements InputOutputInterface | ||
86 | "success" => true, | 92 | "success" => true, |
87 | "data" => $data->getResult() | 93 | "data" => $data->getResult() |
88 | ); | 94 | ); |
95 | + if ($data->getTemplateInfo() != NULL) { | ||
96 | + $result["template"] = $data->getTemplateInfo(); | ||
97 | + } | ||
89 | } | 98 | } |
90 | } | 99 | } |
91 | 100 |
src/InputOutput/IHMImpl/Params/DownloadImpl/IHMInputOutputParamsDownloadClass.php
@@ -74,7 +74,7 @@ class IHMInputOutputParamsDownloadClass extends IHMInputOutputParamsAbstractClas | @@ -74,7 +74,7 @@ class IHMInputOutputParamsDownloadClass extends IHMInputOutputParamsAbstractClas | ||
74 | //add params to output | 74 | //add params to output |
75 | foreach ($input->list as $param) | 75 | foreach ($input->list as $param) |
76 | { | 76 | { |
77 | - $paramInfo = $this->paramManager->addExistingParam($param->name,$this->paramsData); | 77 | + $paramInfo = $this->paramManager->addExistingParam($param->name, $this->paramsData); |
78 | switch ($param->type) { | 78 | switch ($param->type) { |
79 | case 0: | 79 | case 0: |
80 | //scalar - nothing to do | 80 | //scalar - nothing to do |
src/InputOutput/IHMImpl/Params/GeneratorImpl/IHMInputOutputParamsGeneratorClass.php
@@ -16,7 +16,7 @@ class IHMInputOutputParamsGeneratorClass extends IHMInputOutputParamsAbstractCla | @@ -16,7 +16,7 @@ class IHMInputOutputParamsGeneratorClass extends IHMInputOutputParamsAbstractCla | ||
16 | 16 | ||
17 | $this->paramsData->setParamId($input->paramId); | 17 | $this->paramsData->setParamId($input->paramId); |
18 | 18 | ||
19 | - $paramInfo = $this->paramManager->addExistingParam($input->paramId,$this->paramsData); | 19 | + $paramInfo = $this->paramManager->addExistingParam($input->paramId, $this->paramsData); |
20 | 20 | ||
21 | return $this->paramsData; | 21 | return $this->paramsData; |
22 | } | 22 | } |
src/InputOutput/IHMImpl/Params/IHMInputOutputParamsAbstractClass.php
@@ -10,6 +10,7 @@ abstract class IHMInputOutputParamsAbstractClass implements InputOutputInterface | @@ -10,6 +10,7 @@ abstract class IHMInputOutputParamsAbstractClass implements InputOutputInterface | ||
10 | protected $paramManager = null; | 10 | protected $paramManager = null; |
11 | protected $expressionManager = null; | 11 | protected $expressionManager = null; |
12 | protected $jobsManager = null; | 12 | protected $jobsManager = null; |
13 | + | ||
13 | protected $paramsData = null; | 14 | protected $paramsData = null; |
14 | protected $requestID = ""; | 15 | protected $requestID = ""; |
15 | protected $requestDirPrefix = ""; | 16 | protected $requestDirPrefix = ""; |
src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php
@@ -619,7 +619,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass | @@ -619,7 +619,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass | ||
619 | if ($paramData->{'param-drawing-object'}->{'serie-xaxis-param'} == '') | 619 | if ($paramData->{'param-drawing-object'}->{'serie-xaxis-param'} == '') |
620 | continue; | 620 | continue; |
621 | 621 | ||
622 | - $paramXInfo = $this->paramManager->addExistingParam($paramData->{'param-drawing-object'}->{'serie-xaxis-param'},$this->paramsData); | 622 | + $paramXInfo = $this->paramManager->addExistingParam($paramData->{'param-drawing-object'}->{'serie-xaxis-param'}, $this->paramsData); |
623 | if ($paramXInfo['id'] == '') | 623 | if ($paramXInfo['id'] == '') |
624 | throw new Exception('Cannot retrieve X parameter.'); | 624 | throw new Exception('Cannot retrieve X parameter.'); |
625 | $requestParamsNode->addParam($paramXInfo['id']); | 625 | $requestParamsNode->addParam($paramXInfo['id']); |
@@ -646,7 +646,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass | @@ -646,7 +646,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass | ||
646 | foreach ($paramsData as $paramData) | 646 | foreach ($paramsData as $paramData) |
647 | { | 647 | { |
648 | //Param | 648 | //Param |
649 | - $paramInfo = $this->paramManager->addExistingParam($paramData->{'param-id'},$this->paramsData); | 649 | + $paramInfo = $this->paramManager->addExistingParam($paramData->{'param-id'}, $this->paramsData, $paramData->{'param-template-args'}); |
650 | 650 | ||
651 | $paramInfo['indexes'] = array(); | 651 | $paramInfo['indexes'] = array(); |
652 | $dim1 = $paramData->{'param-dim-1'}; | 652 | $dim1 = $paramData->{'param-dim-1'}; |
@@ -731,7 +731,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass | @@ -731,7 +731,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass | ||
731 | continue; | 731 | continue; |
732 | } | 732 | } |
733 | 733 | ||
734 | - $paramColoredInfo = $this->paramManager->addExistingParam($paramData->{'param-drawing-object'}->{'serie-colored-param'},$this->paramsData); | 734 | + $paramColoredInfo = $this->paramManager->addExistingParam($paramData->{'param-drawing-object'}->{'serie-colored-param'}, $this->paramsData); |
735 | if ($paramColoredInfo['id'] == '') | 735 | if ($paramColoredInfo['id'] == '') |
736 | throw new Exception('Cannot retrieve colored parameter.'); | 736 | throw new Exception('Cannot retrieve colored parameter.'); |
737 | $requestParamsNode->addParam($paramColoredInfo['id']); | 737 | $requestParamsNode->addParam($paramColoredInfo['id']); |
@@ -923,7 +923,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass | @@ -923,7 +923,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass | ||
923 | case 'min-max': | 923 | case 'min-max': |
924 | $errorBarTypeNode = $errorBarNode->getBarByType(RequestOutputPlotYSerieErrorBarTypeEnum::MINMAX); | 924 | $errorBarTypeNode = $errorBarNode->getBarByType(RequestOutputPlotYSerieErrorBarTypeEnum::MINMAX); |
925 | 925 | ||
926 | - $minParamInfo = $this->paramManager->addExistingParam($serieData->{'serie-errorbar-minparam'},$this->paramsData); | 926 | + $minParamInfo = $this->paramManager->addExistingParam($serieData->{'serie-errorbar-minparam'}, $this->paramsData); |
927 | if ($minParamInfo['id'] == '') | 927 | if ($minParamInfo['id'] == '') |
928 | throw new Exception('Cannot retrieve min. error parameter.'); | 928 | throw new Exception('Cannot retrieve min. error parameter.'); |
929 | $requestParamsNode->addParam($minParamInfo['id']); | 929 | $requestParamsNode->addParam($minParamInfo['id']); |
@@ -934,7 +934,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass | @@ -934,7 +934,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass | ||
934 | else | 934 | else |
935 | throw new Exception('Min parameter for error bar must be a component.'); | 935 | throw new Exception('Min parameter for error bar must be a component.'); |
936 | 936 | ||
937 | - $maxParamInfo = $this->paramManager->addExistingParam($serieData->{'serie-errorbar-maxparam'},$this->paramsData); | 937 | + $maxParamInfo = $this->paramManager->addExistingParam($serieData->{'serie-errorbar-maxparam'}, $this->paramsData); |
938 | if ($maxParamInfo['id'] == '') | 938 | if ($maxParamInfo['id'] == '') |
939 | throw new Exception('Cannot retrieve max. error parameter.'); | 939 | throw new Exception('Cannot retrieve max. error parameter.'); |
940 | $requestParamsNode->addParam($maxParamInfo['id']); | 940 | $requestParamsNode->addParam($maxParamInfo['id']); |
@@ -948,7 +948,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass | @@ -948,7 +948,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass | ||
948 | case 'delta': | 948 | case 'delta': |
949 | $errorBarTypeNode = $errorBarNode->getBarByType(RequestOutputPlotYSerieErrorBarTypeEnum::DELTA); | 949 | $errorBarTypeNode = $errorBarNode->getBarByType(RequestOutputPlotYSerieErrorBarTypeEnum::DELTA); |
950 | 950 | ||
951 | - $deltaParamInfo = $this->paramManager->addExistingParam($serieData->{'serie-errorbar-deltaparam'},$this->paramsData); | 951 | + $deltaParamInfo = $this->paramManager->addExistingParam($serieData->{'serie-errorbar-deltaparam'}, $this->paramsData); |
952 | if ($deltaParamInfo['id'] == '') | 952 | if ($deltaParamInfo['id'] == '') |
953 | throw new Exception('Cannot retrieve delta error parameter.'); | 953 | throw new Exception('Cannot retrieve delta error parameter.'); |
954 | $requestParamsNode->addParam($deltaParamInfo['id']); | 954 | $requestParamsNode->addParam($deltaParamInfo['id']); |
src/InputOutput/IHMImpl/Params/StatisticsImpl/IHMInputOutputParamsStatisticsClass.php
@@ -37,7 +37,7 @@ class IHMInputOutputParamsStatisticsClass extends IHMInputOutputParamsAbstractCl | @@ -37,7 +37,7 @@ class IHMInputOutputParamsStatisticsClass extends IHMInputOutputParamsAbstractCl | ||
37 | 37 | ||
38 | foreach ($paramFunctionAssociation as $param => $functions) { | 38 | foreach ($paramFunctionAssociation as $param => $functions) { |
39 | 39 | ||
40 | - $paramInfo = $this->paramManager->addExistingParam($param,$this->paramsData); | 40 | + $paramInfo = $this->paramManager->addExistingParam($param, $this->paramsData); |
41 | $paramsNode->addParam($paramInfo['id']); | 41 | $paramsNode->addParam($paramInfo['id']); |
42 | $outputParamNode = $catalogNode->addParam($paramInfo['id'],$paramInfo['indexes']); | 42 | $outputParamNode = $catalogNode->addParam($paramInfo['id'],$paramInfo['indexes']); |
43 | foreach ($functions as $function) $outputParamNode->addFunction($function); | 43 | foreach ($functions as $function) $outputParamNode->addFunction($function); |
src/InputOutput/IHMImpl/Tools/IHMParamManagerClass.php
@@ -9,25 +9,27 @@ class IHMParamManagerClass | @@ -9,25 +9,27 @@ class IHMParamManagerClass | ||
9 | { | 9 | { |
10 | protected $userParameterLoader = null; | 10 | protected $userParameterLoader = null; |
11 | protected $expressionParser = null; | 11 | protected $expressionParser = null; |
12 | + protected $templateParamsManager = null; | ||
12 | 13 | ||
13 | /* | 14 | /* |
14 | * @brief Constructor | 15 | * @brief Constructor |
15 | */ | 16 | */ |
16 | function __construct() | 17 | function __construct() |
17 | { | 18 | { |
19 | + $this->templateParamsManager = new IHMParamTemplateClass(); | ||
18 | } | 20 | } |
19 | 21 | ||
20 | /* | 22 | /* |
21 | * @brief Add an existing parameter | 23 | * @brief Add an existing parameter |
22 | */ | 24 | */ |
23 | - public function addExistingParam($param,$paramsData) | 25 | + public function addExistingParam($param, $paramsData, $templateArgs = NULL) |
24 | { | 26 | { |
25 | if ($this->isDerivedParam($param)) | 27 | if ($this->isDerivedParam($param)) |
26 | return $this->addDerivedParam($param,$paramsData); | 28 | return $this->addDerivedParam($param,$paramsData); |
27 | else if ($this->isUploadedParam($param)) | 29 | else if ($this->isUploadedParam($param)) |
28 | return $this->addUploadedParam($param,$paramsData); | 30 | return $this->addUploadedParam($param,$paramsData); |
29 | else | 31 | else |
30 | - return $this->addLocalParam($param,$paramsData); | 32 | + return $this->addLocalParam($param,$paramsData, $templateArgs); |
31 | return ""; | 33 | return ""; |
32 | } | 34 | } |
33 | 35 | ||
@@ -63,7 +65,7 @@ class IHMParamManagerClass | @@ -63,7 +65,7 @@ class IHMParamManagerClass | ||
63 | /* | 65 | /* |
64 | * @brief Add a local parameter | 66 | * @brief Add a local parameter |
65 | */ | 67 | */ |
66 | - private function addLocalParam($param,$paramsData) | 68 | + private function addLocalParam($param, $paramsData, $templateArgs) |
67 | { | 69 | { |
68 | //local parameter | 70 | //local parameter |
69 | $indexes = array(); | 71 | $indexes = array(); |
@@ -78,30 +80,48 @@ class IHMParamManagerClass | @@ -78,30 +80,48 @@ class IHMParamManagerClass | ||
78 | } | 80 | } |
79 | else | 81 | else |
80 | $paramId = $param; | 82 | $paramId = $param; |
81 | - | ||
82 | - $paramPath = IHMConfigClass::getLocalParamDBPath().$paramId.".xml"; | ||
83 | - if (!file_exists($paramPath)) | ||
84 | - throw new Exception('Cannot find parameter local file '.$paramId); | 83 | + |
84 | + //check templated parameter | ||
85 | + $real_param_id = $paramId; | ||
86 | + if ($this->templateParamsManager->isTemplatedParam($paramId)) { | ||
87 | + $paramPath = $this->templateParamsManager->generateTemplatedParamFile($paramId, $templateArgs); | ||
88 | + $real_param_id = $this->templateParamsManager->getTemplatedParamId($paramId, $templateArgs); | ||
89 | + if (empty($paramPath) || !file_exists($paramPath)) | ||
90 | + throw new Exception('Cannot generate parameter template file '.$paramId); | ||
91 | + } | ||
92 | + else { | ||
93 | + $paramPath = IHMConfigClass::getLocalParamDBPath().$paramId.".xml"; | ||
94 | + if (!file_exists($paramPath)) | ||
95 | + throw new Exception('Cannot find parameter local file '.$paramId); | ||
96 | + } | ||
85 | 97 | ||
86 | - $paramsData->addParamToCopy($paramId,$paramPath); | 98 | + $paramsData->addParamToCopy($real_param_id,$paramPath); |
87 | 99 | ||
88 | - $this->addLinkedLocalParams($paramId,$paramsData); | 100 | + $this->addLinkedLocalParams($paramId, $paramsData, $templateArgs); |
89 | 101 | ||
90 | - return array("id" => $paramId, "indexes" => $indexes, "calib_infos" => $calib_infos); | 102 | + return array("id" => $real_param_id, "indexes" => $indexes, "calib_infos" => $calib_infos); |
91 | } | 103 | } |
92 | 104 | ||
93 | /* | 105 | /* |
94 | * @brief Add linked parameter | 106 | * @brief Add linked parameter |
95 | */ | 107 | */ |
96 | - private function addLinkedLocalParams($paramId,$paramsData) | 108 | + private function addLinkedLocalParams($paramId,$paramsData,$templateArgs = NULL) |
97 | { | 109 | { |
98 | $doc = new DOMDocument("1.0", "UTF-8"); | 110 | $doc = new DOMDocument("1.0", "UTF-8"); |
99 | $doc->preserveWhiteSpace = false; | 111 | $doc->preserveWhiteSpace = false; |
100 | $doc->formatOutput = true; | 112 | $doc->formatOutput = true; |
101 | 113 | ||
102 | - $paramPath = IHMConfigClass::getLocalParamDBPath().$paramId.".xml"; | 114 | + $real_param_id = $real_param_id; |
115 | + if ($this->templateParamsManager->isTemplatedParam($paramId)) { | ||
116 | + $paramPath = $this->templateParamsManager->generateTemplatedParamFile($paramId, $templateArgs); | ||
117 | + $real_param_id = $this->templateParamsManager->getTemplatedParamId($paramId, $templateArgs); | ||
118 | + } | ||
119 | + else { | ||
120 | + $paramPath = IHMConfigClass::getLocalParamDBPath().$paramId.".xml"; | ||
121 | + } | ||
122 | + | ||
103 | 123 | ||
104 | - if (!$doc->load($paramPath)) | 124 | + if (empty($paramPath) || !$doc->load($paramPath)) |
105 | throw new Exception('Cannot find parameter local file '.$paramId); | 125 | throw new Exception('Cannot find parameter local file '.$paramId); |
106 | 126 | ||
107 | //<get> | 127 | //<get> |
@@ -120,9 +140,15 @@ class IHMParamManagerClass | @@ -120,9 +140,15 @@ class IHMParamManagerClass | ||
120 | $linkedParamId = $amdaParamNode->getAttribute('name'); | 140 | $linkedParamId = $amdaParamNode->getAttribute('name'); |
121 | if ($linkedParamId == '') | 141 | if ($linkedParamId == '') |
122 | continue; | 142 | continue; |
123 | - $linkedParamPath = IHMConfigClass::getLocalParamDBPath().$linkedParamId.".xml"; | ||
124 | - $paramsData->addParamToCopy($linkedParamId,$linkedParamPath); | ||
125 | - $this->addLinkedLocalParams($linkedParamId,$paramsData); | 143 | + $real_linked_param_id = $linkedParamId; |
144 | + if ($this->templateParamsManager->isTemplatedParam($linkedParamId)) { | ||
145 | + $linkedParamPath = $this->templateParamsManager->generateTemplatedParamFile($linkedParamId, $templateArgs); | ||
146 | + $real_linked_param_id = $this->templateParamsManager->getTemplatedParamId($linkedParamId, $templateArgs); | ||
147 | + } | ||
148 | + else | ||
149 | + $linkedParamPath = IHMConfigClass::getLocalParamDBPath().$linkedParamId.".xml"; | ||
150 | + $paramsData->addParamToCopy($real_linked_param_id,$linkedParamPath); | ||
151 | + $this->addLinkedLocalParams($linkedParamId, $paramsData); | ||
126 | } | 152 | } |
127 | } | 153 | } |
128 | 154 |
src/InputOutput/IHMImpl/Tools/IHMParamTemplateClass.php
0 โ 100644
@@ -0,0 +1,225 @@ | @@ -0,0 +1,225 @@ | ||
1 | +<?php | ||
2 | + | ||
3 | +/** | ||
4 | + * @class IHMParamTemplateClass | ||
5 | + * @brief Class used to manage templated parameters | ||
6 | + * @details | ||
7 | + */ | ||
8 | +class IHMParamTemplateClass | ||
9 | +{ | ||
10 | + protected $paramTemplateList = null; | ||
11 | + | ||
12 | + private static $paramTemplateNode = 'paramTemplate'; | ||
13 | + private static $paramTemplateIdAtt = 'paramId'; | ||
14 | + private static $paramTemplateFileNameAtt = 'fileName'; | ||
15 | + private static $paramTemplateArgumentsNode = 'arguments'; | ||
16 | + private static $paramTemplateArgumentNode = 'argument'; | ||
17 | + private static $paramTemplateArgumentKeyAtt = 'key'; | ||
18 | + private static $paramTemplateArgumentNameAtt = 'name'; | ||
19 | + private static $paramTemplateArgumentTypeAtt = 'type'; | ||
20 | + private static $paramTemplateArgumentDefaultAtt = 'default'; | ||
21 | + private static $paramTemplateArgumentListItemNode = 'item'; | ||
22 | + private static $paramTemplateArgumentListItemKeyAtt = 'key'; | ||
23 | + private static $paramTemplateArgumentListItemNameAtt = 'name'; | ||
24 | + | ||
25 | + /* | ||
26 | + * @brief Constructor | ||
27 | + */ | ||
28 | + function __construct() | ||
29 | + { | ||
30 | + } | ||
31 | + | ||
32 | + /* | ||
33 | + * @brief Get list of templated parameters | ||
34 | + */ | ||
35 | + public function getParamTemplates() { | ||
36 | + $this->loadUserParamManagerFile(); | ||
37 | + return $this->paramTemplateList; | ||
38 | + } | ||
39 | + | ||
40 | + /* | ||
41 | + * @brief Check if param_id is a templated parameter | ||
42 | + */ | ||
43 | + public function isTemplatedParam($param_id) { | ||
44 | + $list = $this->getParamTemplates(); | ||
45 | + return array_key_exists($param_id, $list); | ||
46 | + } | ||
47 | + | ||
48 | + /* | ||
49 | + * @brief Get templated parameter id | ||
50 | + */ | ||
51 | + public function getTemplatedParamId($param_id, $template_args) { | ||
52 | + $templatePath = $this->getTemplatePath($param_id); | ||
53 | + | ||
54 | + if (empty($templatePath)) | ||
55 | + return ""; | ||
56 | + | ||
57 | + if (!isset($template_args)) | ||
58 | + $template_args = array(); | ||
59 | + | ||
60 | + //Enrich template args with default values | ||
61 | + $this->addDefaultValues($param_id, $template_args); | ||
62 | + | ||
63 | + return basename($this->replaceArgs($templatePath, $template_args), ".xml"); | ||
64 | + } | ||
65 | + | ||
66 | + /* | ||
67 | + * @brief Generate parameter file from template | ||
68 | + */ | ||
69 | + public function generateTemplatedParamFile($param_id, $template_args) { | ||
70 | + $templatePath = $this->getTemplatePath($param_id); | ||
71 | + if (empty($templatePath)) | ||
72 | + return ""; | ||
73 | + | ||
74 | + if (!isset($template_args)) | ||
75 | + $template_args = array(); | ||
76 | + | ||
77 | + //Enrich template args with default values | ||
78 | + $this->addDefaultValues($param_id, $template_args); | ||
79 | + | ||
80 | + $dst_param_id = $this->getTemplatedParamId($param_id, $template_args); | ||
81 | + | ||
82 | + //Build destination file path | ||
83 | + $dstDir = IHMConfigClass::getTemplateParamGeneratePath(); | ||
84 | + if (!is_dir($dstDir)) | ||
85 | + mkdir($dstDir); | ||
86 | + $dstFilePath = $dstDir."/".$dst_param_id.".xml"; | ||
87 | + | ||
88 | + //Check if it's necessary to generate the parameter file | ||
89 | + if (file_exists($dstFilePath)) { | ||
90 | + $dateModifDst = filemtime($dstFilePath); | ||
91 | + $dateModifTemplate = filemtime($templatePath); | ||
92 | + | ||
93 | + if ($dateModifTemplate != $dateModifDst) | ||
94 | + //no modification - reuse old generated file | ||
95 | + return $dstFilePath; | ||
96 | + } | ||
97 | + | ||
98 | + //Generate file | ||
99 | + $templateHandle = fopen($templatePath, "r"); | ||
100 | + $dstHandle = fopen($dstFilePath, "w"); | ||
101 | + if (!$templateHandle || !$dstHandle) | ||
102 | + return ""; | ||
103 | + while (($line = fgets($templateHandle)) !== false) { | ||
104 | + fwrite($dstHandle, $this->replaceArgs($line, $template_args)); | ||
105 | + } | ||
106 | + fclose($templateHandle); | ||
107 | + fclose($dstHandle); | ||
108 | + | ||
109 | + $dateModifTemplate = filemtime($templatePath); | ||
110 | + touch($dstFilePath, $dateModifTemplate); | ||
111 | + | ||
112 | + return $dstFilePath; | ||
113 | + } | ||
114 | + | ||
115 | + /* | ||
116 | + * @brief Get template file path | ||
117 | + */ | ||
118 | + private function getTemplatePath($param_id) { | ||
119 | + if (!$this->isTemplatedParam($param_id)) | ||
120 | + return ""; | ||
121 | + return IHMConfigClass::getParamTemplateFilePath($this->paramTemplateList[$param_id]['fileName']); | ||
122 | + } | ||
123 | + | ||
124 | + /* | ||
125 | + * @brief Replace args in string | ||
126 | + */ | ||
127 | + private function replaceArgs($string, $template_args) { | ||
128 | + $result = $string; | ||
129 | + foreach ($template_args as $template_arg_key => $template_arg_value) { | ||
130 | + $result = str_replace("##".$template_arg_key."##", $template_arg_value, $result); | ||
131 | + } | ||
132 | + return $result; | ||
133 | + } | ||
134 | + | ||
135 | + /* | ||
136 | + * @brief Enrich Template args with default values | ||
137 | + */ | ||
138 | + private function addDefaultValues($param_id, &$template_args) { | ||
139 | + $list = $this->getParamTemplates(); | ||
140 | + | ||
141 | + if (!array_key_exists($param_id, $list)) | ||
142 | + return; | ||
143 | + | ||
144 | + $arguments = $list[$param_id]->arguments; | ||
145 | + foreach ($arguments as $arg_key => $arg_def) { | ||
146 | + if (!array_key_exists($arg_key, $template_args)) | ||
147 | + $template_args[$arg_key] = $arg_def->default; | ||
148 | + } | ||
149 | + } | ||
150 | + | ||
151 | + /* | ||
152 | + * @brief Load list of templated parameters | ||
153 | + */ | ||
154 | + private function loadUserParamManagerFile() | ||
155 | + { | ||
156 | + if (isset($this->paramTemplateList)) | ||
157 | + return; | ||
158 | + | ||
159 | + $this->paramTemplateList = array(); | ||
160 | + | ||
161 | + //load xml file | ||
162 | + $dom = new DomDocument("1.0"); | ||
163 | + if (!$dom->load(IHMConfigClass::getParamTemplateListFilePath())) | ||
164 | + return; | ||
165 | + | ||
166 | + $paramTemplateNodes = $dom->getElementsByTagName(self::$paramTemplateNode); | ||
167 | + | ||
168 | + foreach ($paramTemplateNodes as $paramTemplateNode) { | ||
169 | + $paramId = $paramTemplateNode->getAttribute(self::$paramTemplateIdAtt); | ||
170 | + $paramFileName = $paramTemplateNode->getAttribute(self::$paramTemplateFileNameAtt); | ||
171 | + | ||
172 | + if (empty($paramId) || empty($paramFileName)) | ||
173 | + continue; | ||
174 | + | ||
175 | + $arguments = array(); | ||
176 | + | ||
177 | + $argumentsNode = $paramTemplateNode->getElementsByTagName(self::$paramTemplateArgumentsNode); | ||
178 | + | ||
179 | + if (count($argumentsNode) > 0) { | ||
180 | + $argumentsNode = $argumentsNode->item(0); | ||
181 | + $argumentNodes = $argumentsNode->getElementsByTagName(self::$paramTemplateArgumentNode); | ||
182 | + | ||
183 | + foreach($argumentNodes as $argumentNode) { | ||
184 | + $argumentKey = $argumentNode->getAttribute(self::$paramTemplateArgumentKeyAtt); | ||
185 | + $argumentName = $argumentNode->getAttribute(self::$paramTemplateArgumentNameAtt); | ||
186 | + $argumentType = $argumentNode->getAttribute(self::$paramTemplateArgumentTypeAtt); | ||
187 | + $argumentDefault = $argumentNode->getAttribute(self::$paramTemplateArgumentDefaultAtt); | ||
188 | + | ||
189 | + if (empty($argumentKey) || empty($argumentType)) | ||
190 | + continue; | ||
191 | + | ||
192 | + $arguments[$argumentKey] = array( | ||
193 | + "name" => (empty($argumentName) ? $argumentKey : $argumentName), | ||
194 | + "type" => $argumentType, | ||
195 | + "default" => $argumentDefault | ||
196 | + ); | ||
197 | + | ||
198 | + switch ($argumentType) { | ||
199 | + case "list" : | ||
200 | + $arguments[$argumentKey]['items'] = array(); | ||
201 | + | ||
202 | + $itemNodes = $argumentNode->getElementsByTagName(self::$paramTemplateArgumentListItemNode); | ||
203 | + foreach ($itemNodes as $itemNode) { | ||
204 | + $itemKey = $itemNode->getAttribute(self::$paramTemplateArgumentListItemKeyAtt); | ||
205 | + $itemName = $itemNode->getAttribute(self::$paramTemplateArgumentListItemNameAtt); | ||
206 | + if ($itemKey == "") | ||
207 | + continue; | ||
208 | + $arguments[$argumentKey]['items'][$itemKey] = (empty($itemName) ? $itemKey : $itemName); | ||
209 | + } | ||
210 | + | ||
211 | + break; | ||
212 | + default: | ||
213 | + //Nothing to do | ||
214 | + } | ||
215 | + } | ||
216 | + } | ||
217 | + | ||
218 | + $this->paramTemplateList[$paramId] = array( | ||
219 | + "fileName" => $paramFileName, | ||
220 | + "arguments" => $arguments | ||
221 | + ); | ||
222 | + | ||
223 | + } | ||
224 | + } | ||
225 | +} | ||
0 | \ No newline at end of file | 226 | \ No newline at end of file |
src/Request/ParamInfoRequestDataClass.php
@@ -21,6 +21,7 @@ class ParamInfoRequestDataClass extends RequestDataClass | @@ -21,6 +21,7 @@ class ParamInfoRequestDataClass extends RequestDataClass | ||
21 | { | 21 | { |
22 | private $filePath = ""; | 22 | private $filePath = ""; |
23 | private $paramId = ""; | 23 | private $paramId = ""; |
24 | + private $templateInfo = NULL; | ||
24 | private $type = ParamInfoTypeEnumClass::UNKNOWN; | 25 | private $type = ParamInfoTypeEnumClass::UNKNOWN; |
25 | private $result = NULL; | 26 | private $result = NULL; |
26 | 27 | ||
@@ -63,6 +64,16 @@ class ParamInfoRequestDataClass extends RequestDataClass | @@ -63,6 +64,16 @@ class ParamInfoRequestDataClass extends RequestDataClass | ||
63 | { | 64 | { |
64 | $this->paramId = $paramId; | 65 | $this->paramId = $paramId; |
65 | } | 66 | } |
67 | + | ||
68 | + public function getTemplateInfo() | ||
69 | + { | ||
70 | + return $this->templateInfo; | ||
71 | + } | ||
72 | + | ||
73 | + public function setTemplateInfo($templateInfo) | ||
74 | + { | ||
75 | + $this->templateInfo = $templateInfo; | ||
76 | + } | ||
66 | } | 77 | } |
67 | 78 | ||
68 | ?> | 79 | ?> |
69 | \ No newline at end of file | 80 | \ No newline at end of file |