Parse the Xml result from Subversion

@param  string $output
@param  array  $arguments
@return array
171029
public function parseListOutput($output, array $arguments = array())
    {
        if (!isset($arguments['--xml']) || false === $arguments['--xml']) {
            // non xml results are not supported
            return $output;
        }

        $head = $this->getClient()->getHead();

        $sxml = simplexml_load_string($output);

        $retval = array();
        foreach ($sxml->xpath('//entry') as $item) {
            $filename = (string) $item->name;
            $kind     = (string) $item->attributes()->kind;
            $revision = (string) $item->commit->attributes()->revision;
            $date     = (string) $item->commit->date;
            $author   = (string) $item->commit->author;

            $commit = new Commit($revision, new \DateTime($date), $author);

            $file = new VcsFileInfo($filename, $head, $kind);
            $file->setCommit($commit);

            $retval[] = $file;
        }

        return $retval;
    }
604459
private function parseQueryResult($result = [])
    {
        $rdsDeliveryExecution = new RdsDeliveryExecution($this);

        if (array_key_exists(self::COLUMN_ID, $result)) {
            $rdsDeliveryExecution->setIdentifier($result[self::COLUMN_ID]);
        }

        if (array_key_exists(self::COLUMN_LABEL, $result)) {
            $rdsDeliveryExecution->setLabel($result[self::COLUMN_LABEL]);
        }

        if (array_key_exists(self::COLUMN_DELIVERY_ID, $result)) {
            $rdsDeliveryExecution->setDelivery($result[self::COLUMN_DELIVERY_ID]);
        }

        if (array_key_exists(self::COLUMN_STATUS, $result)) {
            $rdsDeliveryExecution->setState($result[self::COLUMN_STATUS]);
        }

        if (array_key_exists(self::COLUMN_USER_ID, $result)) {
            $rdsDeliveryExecution->setUserIdentifier($result[self::COLUMN_USER_ID]);
        }

        if (array_key_exists(self::COLUMN_STARTED_AT, $result)) {
            $rdsDeliveryExecution->setStartTime(new \DateTime($result[self::COLUMN_STARTED_AT]));
        }

        if (array_key_exists(self::COLUMN_FINISHED_AT, $result)) {
            $rdsDeliveryExecution->setFinishTime(new \DateTime($result[self::COLUMN_FINISHED_AT]));
        }

        return $this->propagate(new DeliveryExecution($rdsDeliveryExecution));
    }
1362600
private function prepareTitleOutput($output)
    {
        return htmlspecialchars(
            Str::limit(strip_tags($output), $this->getMax()), ENT_QUOTES, 'UTF-8', false
        );
    }
756151
public function merge($output)
    {
        if (empty($this->files)) {
            throw new \LogicException("You need to add some files to merge by calling one of addFile, addFiles, setFiles methods");
        }

        /**
         * @var string $outputFiles
         */
        $outputFiles = array();
        foreach ($this->files as $file) {
            if (!$this->supports($file)) {
                if (!$this->omitUnsupported) {
                    throw new UnsupportedException(sprintf("Transformer for file '%s' not found, mime: %s", $file->getPath(), $file->getMimeType()));
                }
                continue;
            }
            if (!$this->driver->supports($file)) {
                $outputFile = $this->getTransformer($file)->transform($file);
                if (!$outputFile) {
                    throw new \LogicException(sprintf("Transformer should return NeuroSys\\FileMerger\\File in '%s' format", $this->driver->getFormat()));
                }
                $outputFiles[] = $outputFile->getPath();
            } else {
                $outputFiles[] = $file->getPath();
            }
        }

        if (count($outputFiles) == 1) {
            copy(end($outputFiles), $output);
        } elseif ($outputFiles) {
            $this->driver->merge($outputFiles, $output);
        }

        // reset files array
        $this->files = array();
    }
487622
public function format(array $output): iterable
    {
        $formatted = [];
        foreach ($output as $row) {
            $formatted[] = $this->createCommit($row);
        }
        return $formatted;
    }
46666
protected function parseOutput($output)
    {
        $lines = explode("\n", $output);

        // This is the escape sequence that kills the stuff on the line, then
        // adds new text to it. The fake lines are separated by CRs instead of
        // NLs. You can thank whoever invented Bash for that
        $escapeStr = "\x1b\x5b\x4b";

        $actualLines = array();
        foreach ($lines as $line) {
            if (stripos($line, $escapeStr) !== false) {
                // Explode on the CR and take the last item, as that is the
                // actual line we want to show
                $parts = explode("\r", $line);

                $actualLine = array_pop($parts);

                // Remove the escape sequence
                $actualLines[] = str_replace($escapeStr, '', $actualLine);
            } else {
                $actualLines[] = $line;
            }
        }

        return trim(implode("\n", $actualLines));
    }
119821
public static function normalizeOutputsStruct(array $outputs) {
        $result = [];

        foreach ($outputs as $k => $v) {
            if (is_numeric($k)) {
                if (!is_array($v)) {
                    throw new \InvalidArgumentException("outputs should be [address => value, ] or [[address, value], ] or [['address' => address, 'value' => value], ]");
                }

                if (isset($v['address']) && isset($v['value'])) {
                    $address = $v['address'];
                    $value = $v['value'];
                } elseif (count($v) == 2 && isset($v[0]) && isset($v[1])) {
                    $address = $v[0];
                    $value = $v[1];
                } else {
                    throw new \InvalidArgumentException("outputs should be [address => value, ] or [[address, value], ] or [['address' => address, 'value' => value], ]");
                }
            } else {
                $address = $k;
                $value = $v;
            }

            $result[] = ['address' => $address, 'value' => $value];
        }

        return $result;
    }
150291
protected function getWebPath($output)
    {
        $path = trim(dirname($output), '/');
        $count = count(explode('/', $path));

        $path = '';

        for ($i = 0; $i < $count-1; $i++) {
            $path.= '/..';
        }

        return $path;
    }
1132618
protected function parse_output() {
		foreach ( $this->output as $output ) {
			$skip = false;

			// Apply any sanitization callbacks defined.
			$value = $this->apply_sanitize_callback( $output, $this->value );

			// Skip if value is empty.
			if ( '' === $this->value ) {
				$skip = true;
			}

			// No need to proceed this if the current value is the same as in the "exclude" value.
			if ( isset( $output['exclude'] ) && is_array( $output['exclude'] ) ) {
				foreach ( $output['exclude'] as $exclude ) {
					if ( is_array( $value ) ) {
						if ( is_array( $exclude ) ) {
							$diff1 = array_diff( $value, $exclude );
							$diff2 = array_diff( $exclude, $value );

							if ( empty( $diff1 ) && empty( $diff2 ) ) {
								$skip = true;
							}
						}
						// If 'choice' is defined check for sub-values too.
						// Fixes https://github.com/aristath/kirki/issues/1416.
						if ( isset( $output['choice'] ) && isset( $value[ $output['choice'] ] ) && $exclude == $value[ $output['choice'] ] ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
							$skip = true;
						}
					}
					if ( $skip ) {
						continue;
					}

					// Skip if value is defined as excluded.
					if ( $exclude === $value || ( '' === $exclude && empty( $value ) ) ) {
						$skip = true;
					}
				}
			}
			if ( $skip ) {
				continue;
			}

			// Apply any value patterns defined.
			$value = $this->apply_value_pattern( $output, $value );

			if ( isset( $output['element'] ) && is_array( $output['element'] ) ) {
				$output['element'] = array_unique( $output['element'] );
				sort( $output['element'] );
				$output['element'] = implode( ',', $output['element'] );
			}

			$value = $this->process_value( $value, $output );

			if ( ( is_admin() && ! is_customize_preview() ) || ( isset( $_GET['editor'] ) && '1' === $_GET['editor'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification

				// Check if this is an admin style.
				if ( ! isset( $output['context'] ) || ! in_array( 'editor', $output['context'], true ) ) {
					continue;
				}
			} elseif ( isset( $output['context'] ) && ! in_array( 'front', $output['context'], true ) ) {

				// Check if this is a frontend style.
				continue;
			}
			$this->process_output( $output, $value );
		}
	}
430984
public function XML_val($field, $arguments = [], $cache = false)
    {
        $result = $this->obj($field, $arguments, $cache);
        // Might contain additional formatting over ->XML(). E.g. parse shortcodes, nl2br()
        return $result->forTemplate();
    }
871051
public static function parse(array $arguments):array
    {
        if (count($arguments) < 1) {
            throw new Server500(new \ArrayObject(array("explain" => "Cannot parse value without commands",
                "solution" => "Please set an command to parse it")));
        }
        $exec = self::parseExecutable($arguments);

        if (isset($arguments[0])) {
            unset($arguments[0]);
        }

        $com = self::parseCommands($arguments);
        $opt = self::parseOptions($arguments);

        return (["global" => $exec, "commands" => $com, "options" => $opt]);
    }
819994
public function parseDiffOutput($output, array $arguments = array())
    {
        if (!isset($arguments['--name-status']) || false === $arguments['--name-status']) {
            // non name-status results are not supported
            return $output;
        }

        $lines = explode("\n", rtrim($output));

        $retval = array();
        foreach ($lines as $line) {
            if (preg_match('/([ACDMRTUXB])(\d*)\s+(.*)?/', $line, $matches)) {
                list($fullmatch, $status, $number, $filename) = $matches;

                if ($number && preg_match('/(.*\s)+(.*)/', $filename, $filenameMatches)) {
                    list($fullmatch, $originalName, $filename) = $filenameMatches;
                }

                $file = new VcsFileInfo($filename, $this->getClient()->getHead());
                $file->setStatus($status);

                $retval[] = $file;
            } else {
                throw new \Exception('Unable to parse line "'. $line . '"');
            }
        }

        return $retval;
    }
198811
private function parseDu($duOutput, array $mountPaths)
    {
        $mountSizes = [];
        $duOutputSplit = explode("\n", $duOutput, count($mountPaths));
        foreach ($mountPaths as $i => $mountPath) {
            if (!isset($duOutputSplit[$i])) {
                throw new \RuntimeException("Failed to find row $i of 'du' command output: \n" . $duOutput);
            }
            list($mountSizes[$mountPath],) = explode("\t", $duOutputSplit[$i], 2);
        }

        return $mountSizes;
    }
907771
private function parseS3CmdListOutput($output)
    {
        $backups = array();

        if (null === $output) {
            return $backups;
        }

        foreach (explode("\n", $output) as $row) {
            if ('' === $row) {
                continue;
            }

            $backups[] = $this->parseS3CmdListRow($row);
        }

        return $backups;
    }
1352361
protected function getOutputContext(DOMNode $output)
	{
		$contexts = [
			'boolean(ancestor::attribute)'             => 'attribute',
			'@disable-output-escaping="yes"'           => 'raw',
			'count(ancestor::element[@name="script"])' => 'raw'
		];
		foreach ($contexts as $expr => $context)
		{
			if ($this->evaluate($expr, $output))
			{
				return $context;
			}
		}

		return 'text';
	}
211089
public function get_content_for_all_regions($output) {
        $contents = array();
        $this->check_is_loaded();

        foreach ($this->regions as $region => $val) {
            $this->ensure_content_created($region, $output);
            $contents[$region] = $this->visibleblockcontent[$region];
        }
        return $contents;
    }
740715
protected function _outputHandle($output=null)
    {
        if ($output === null) {
            // do nothing
        } elseif ($output instanceof ResponseInterface) {
            $this->response = $output;
        } elseif ($output) {
            if (is_scalar($output)) {
                $this->response = $this->renderText($output);
            } elseif (is_array($output)) {
                $this->response = $this->renderJson($output);
            } elseif ($output instanceof Collection) {
                $this->response = $this->renderJson($output->all());
            }
        }
        
        if ($data = $this->getRenderBuffer()) {
            $this->response->write($data);
        }
        
        return $this->response;
    }