Back to Patcher class

Method findHeader

protected static bool
findHeader
(mixed &$lines, mixed &$src, mixed &$dst)
Find the diff header
Parameters
  • array $lines The udiff array of lines
  • string $src The source file
  • string $dst The destination file
Returns
  • bool TRUE in case of success, FALSE in case of failure
Since
  • 3.0.0
-
  • \RuntimeException
Class: Patcher
Project: Joomla

Method findHeader - Source code

/**
 * Find the diff header
 *
 * The internal array pointer of $lines is on the next line after the finding
 *
 * @param   array   $lines  The udiff array of lines
 * @param   string  $src    The source file
 * @param   string  $dst    The destination file
 *
 * @return  boolean  TRUE in case of success, FALSE in case of failure
 *
 * @since   3.0.0
 * @throws  \RuntimeException
 */
protected static function findHeader(&$lines, &$src, &$dst)
{
    // Get the current line
    $line = current($lines);
    // Search for the header
    while ($line !== false && !preg_match(self::SRC_FILE, $line, $m)) {
        $line = next($lines);
    }
    if ($line === false) {
        // No header found, return false
        return false;
    }
    // Set the source file
    $src = $m[1];
    // Advance to the next line
    $line = next($lines);
    if ($line === false) {
        throw new \RuntimeException('Unexpected EOF');
    }
    // Search the destination file
    if (!preg_match(self::DST_FILE, $line, $m)) {
        throw new \RuntimeException('Invalid Diff file');
    }
    // Set the destination file
    $dst = $m[1];
    // Advance to the next line
    if (next($lines) === false) {
        throw new \RuntimeException('Unexpected EOF');
    }
    return true;
}