engine = $engine; $this->article = $article; } public function parse($formel, $breakValid = false) { $i = 0; while((strpos($formel,'$F') !== false || strpos($formel,'$P') !== false || strpos($formel,'$V') !== false || strpos($formel,'$CV') !== false) && $i < 12) { $formel = $this->parseCalcVariables($formel, $breakValid); $formel = $this->parseFormulas($formel, $breakValid); $formel = $this->parseParameters($formel, $breakValid); $formel = $this->parseVariables($formel, $breakValid); $i++; } return $formel; } private function parseVariables($formel, $breakValid = false) { preg_match_all('/\$V\w*\$V/', $formel, $founds); $variables = $this->engine->getVariables(); if (!empty($founds [0])) { foreach ($founds [0] as $key => $found) { $foundvalue = str_replace('$V', '', $found); if (isset($variables [$foundvalue])) { if ($variables [$foundvalue] == 'null') { $formel = str_replace($found, 0, $formel); } else { if ($foundvalue == 'auflage') { $formel = str_replace($found, str_replace(',', '.', $variables [$foundvalue]), $formel); } else { if ($variables [$foundvalue] == '') { $formel = str_replace($found, 0, $formel); } else { $formel = str_replace($found, $variables [$foundvalue], $formel); } } } } else { if($breakValid) { $this->engine->validDirty = true; } $formel = str_replace($found, 0, $formel); } } } return $formel; } private function parseParameters($formel, $breakValid = false) { preg_match_all('/\$P\w*\$P/', $formel, $founds); if (!empty($founds [0])) { try{ @eval($this->engine->getParameters()); @eval($this->engine->getFormulas()); }catch (\Throwable $e) { } foreach ($founds [0] as $key => $found) { $foundvalue = str_replace('$P', '', $found); if (isset($$foundvalue)) { $formel = str_replace($found, $$foundvalue, $formel); } else { if($breakValid) { $this->engine->validDirty = true; } $formel = str_replace($found, 0, $formel); } } } return $formel; } private function parseFormulas($formel, $breakValid = false) { preg_match_all('/\$F\w*\$F/', $formel, $founds); if (!empty($founds [0])) { try{ @eval($this->engine->getParameters()); @eval($this->engine->getFormulas()); }catch (\Throwable $e) { } foreach ($founds [0] as $key => $found) { $foundvalue = str_replace('$F', '', $found); if(isset($$foundvalue)) { $formel = str_replace($found, $$foundvalue, $formel); }else{ if($breakValid) { $this->engine->validDirty = true; } $formel = str_replace($found, 0, $formel); } } } return $formel; } private function parseCalcVariables($formel, $breakValid = false) { preg_match_all('/\$CV[\w\.]*\$CV/', $formel, $founds); $variables = $this->engine->getCalcVariables(); if (!empty($founds [0])) { foreach ($founds [0] as $key => $found) { $foundvalue = str_replace('$CV', '', $found); if (isset($variables [$foundvalue])) { if ($variables [$foundvalue] == 'null') { $formel = str_replace($found, 0, $formel); } else { if ($foundvalue == 'auflage') { $formel = str_replace($found, str_replace(',', '.', $variables [$foundvalue]), $formel); } else { if ($variables [$foundvalue] == '') { $formel = str_replace($found, 0, $formel); } else { if(is_array($variables [$foundvalue])) { $formel = str_replace($found, 0, $formel); }else{ $formel = str_replace($found, $variables [$foundvalue], $formel); } } } } } else { if($breakValid) { $this->engine->validDirty = true; } $formel = str_replace($found, 0, $formel); } } } return $formel; } }