private function parseWithConfig($configuration, $result) { $output = null; foreach ($this->options as $option) { /* * if there are multiple paths for one setting */ if (is_array($option->path)) { foreach ($option->path as $config => $path) { //($setting = ArrayTools::accessArrayElementByPath($configuration, $path)) !== null ?: $setting = $option->default[$config]; $setting = ArrayTools::accessArrayElementByPath($configuration, $path); if ($setting === null) { if ($option->default[$config] !== null) { LogCLI::MessageResult('Setting ' . $config . ' not set, defaulting to: ' . $option->default[$config], 7, LogCLI::OK); } $setting = $option->default[$config]; } $values[$config] = $setting; } $this->_dispatchAction($option, $values, $result); } else { //($setting = ArrayTools::accessArrayElementByPath($configuration, $option->path)) !== null ?: $setting = $option->default; $setting = ArrayTools::accessArrayElementByPath($configuration, $option->path); if ($setting === null) { $option->setDefaults(); if ($option->default !== null) { LogCLI::MessageResult('Setting ' . $option->name . ' not set, defaulting to: ' . $option->default, 7, LogCLI::OK); } $setting = $option->default; } //var_dump($setting); /* * If we got an array, how do we divide it? * By default by ' ' (space), but sometimes we want eg. PHP_EOL, or comma. */ $value = StringTools::makeList($setting, $option->divideBy); $this->_dispatchAction($option, $value, $result); } } //foreach(preg_split("/(\r?\n)/", $this->template) as $line) foreach (explode(PHP_EOL, $this->template) as $line) { //$parsedline = ParseTools::sprintfn($line, $result->options); $parsedline = ParseTools::parseStringWithReplacementList($line, $result->options); // if all we got is whitespace, don't add it if (strlen(rtrim($parsedline)) < 1) { continue; } // if we got a multiline responds we have to indent it // TODO: maybe explode "\n" or PHP_EOL would be better? // if(count($lines = preg_split("/(\r?\n)/", $parsedline)) > 1) if (count($lines = explode(PHP_EOL, $parsedline)) > 1) { $indentedlines = array_shift($lines) . PHP_EOL; foreach ($lines as &$multiline) { $indentedlines .= StringTools::indentLinesToMatchOther(trim($line), $line, $multiline) . PHP_EOL; } $parsedline = rtrim($indentedlines); } $output .= $parsedline . PHP_EOL; } return $output; }
public function insertScope($child, $parent, $pattern = null, $overrideIndentationTemplate = false) { if (!isset($pattern)) { $pattern =& $this->patterns[$child]; } LogCLI::MessageResult("Inserting: " . LogCLI::BLUE . $child . LogCLI::RESET . " => " . LogCLI::GREEN . $parent . LogCLI::RESET . " (will replace " . LogCLI::YELLOW . $pattern . LogCLI::RESET . ")", 3); //TODO: make sure this two IF's never get executed if (!isset($this->results[$parent])) { LogCLI::MessageResult("Notice: " . LogCLI::YELLOW . 'No such parent' . LogCLI::RESET . " - " . LogCLI::GREEN . $parent, 2); $proper_parent = explode('/', $parent); //$proper_parent = (isset($proper_parent[2])) ? $proper_parent[2] : $proper_parent[0]; $proper_parent = end($proper_parent); //!is_numeric(end($proper_parent)) ? $this->results[$parent] = $this->templates[$proper_parent]; } if (!isset($this->results[$child])) { LogCLI::MessageResult("Notice: " . LogCLI::YELLOW . 'No such child' . LogCLI::RESET . " - " . LogCLI::GREEN . $child, 2); $proper_child = explode('/', $child); //echo "PROPER CHILD: \n"; //var_dump($proper_child); $proper_child = isset($proper_child[2]) ? $proper_child[2] : $proper_child[0]; $this->results[$child] = $this->templates[$proper_child]; } //var_dump($this->results[$child]); if ($overrideIndentationTemplate !== false) { return preg_replace(StringTools::regexpify($pattern), trim(StringTools::indentLinesToMatchOther($pattern, $overrideIndentationTemplate, $this->results[$child], 0)), $this->results[$parent]) . PHP_EOL; } else { return preg_replace(StringTools::regexpify($pattern), trim(StringTools::indentLinesToMatchOther($pattern, $this->templates[$parent], $this->results[$child], 0)), $this->results[$parent]) . PHP_EOL; } }