create(ParserFactory::PREFER_PHP7); $this->aVarsMap = array( 'MySettings' => array(), 'MyModuleSettings' => array(), 'MyModules' => array(), ); if ($sConfig !== null) { $this->BrowseFile($oParser, $sConfig); } } /** * @return array */ public function GetVarsMap() { return $this->aVarsMap; } /** * @param $arrayName * @param $key * * @return array */ public function GetVarValue($arrayName, $key) { if (!array_key_exists($arrayName, $this->aVarsMap)){ return array('found' => false); } $arrayValue = $this->aVarsMap[$arrayName]; if (!array_key_exists($key, $arrayValue)){ return array('found' => false); } return array('found' => true, 'value' => $arrayValue[$key]); } /** * @param \PhpParser\Parser $oParser * @param $sConfig * * @return \Combodo\iTop\Config\Validator\ConfigNodesVisitor */ private function BrowseFile(\PhpParser\Parser $oParser, $sConfig) { $prettyPrinter = new Standard(); try { $aNodes = $oParser->parse($sConfig); } catch (\Error $e) { $sMessage = Dict::Format('config-parse-error', $e->getMessage(), $e->getLine()); $this->oException = new \Exception($sMessage, 0, $e); } foreach ($aNodes as $oAssignation) { if (! $oAssignation instanceof Assign) { continue; } $sCurrentRootVar = $oAssignation->var->name; if (!array_key_exists($sCurrentRootVar, $this->aVarsMap)) { continue; } $aCurrentRootVarMap =& $this->aVarsMap[$sCurrentRootVar]; foreach ($oAssignation->expr->items as $oItem) { $sValue = $prettyPrinter->prettyPrintExpr($oItem->value); $aCurrentRootVarMap[$oItem->key->value] = $sValue; } } } }