コード例 #1
0
 /**
  * Format a value before processing.
  *
  * @param array|string $value
  * @return array|string
  */
 protected function formatValue($value)
 {
     if (is_array($value)) {
         return Formatter::formatArray($value);
     }
     return Formatter::formatScalar($value);
 }
コード例 #2
0
 /**
  * Immediately replaces part of data using regular expression
  *
  * @param $searchPattern string
  * @param $replaceWith string
  * @return $this
  */
 public function doRegexpReplace($searchPattern, $replaceWith)
 {
     $this->content = preg_replace_callback($searchPattern, function ($matches) use($replaceWith) {
         $indent = isset($matches['indent']) ? $matches['indent'] : '';
         $output = $indent;
         $output .= isset($matches['start']) ? $matches['start'] : '';
         $output .= isset($matches['target']) ? Formatter::indentLines($replaceWith, mb_strlen($indent), true) : '';
         $output .= isset($matches['end']) ? $matches['end'] : '';
         return $output;
     }, $this->content);
     return $this;
 }