src/lib/Herrera/Box/Extract.php
public static function findStubLength(
        $file,
        $pattern = self::PATTERN_OPEN
    ) {
        if (!($fp = fopen($file, 'rb'))) {
            throw new RuntimeException(
                sprintf(
                    'The phar "%s" could not be opened for reading.',
                    $file
                )
            );
        }

        $stub = null;
        $offset = 0;
        $combo = str_split($pattern);

        while (!feof($fp)) {
            if (fgetc($fp) === $combo[$offset]) {
                $offset++;

                if (!isset($combo[$offset])) {
                    $stub = ftell($fp);

                    break;
                }
            } else {
                $offset = 0;
            }
        }

        fclose($fp);

        if (null === $stub) {
            throw new InvalidArgumentException(
                sprintf(
                    'The pattern could not be found in "%s".',
                    $file
                )
            );
        }

        return $stub;
    }
public static function findStubLength(
        $file,
        $pattern = self::PATTERN_OPEN
    ) {
        if (!($fp = fopen($file, 'rb'))) {
            throw new RuntimeException(
                sprintf(
                    'The phar "%s" could not be opened for reading.',
                    $file
                )
            );
        }

        $stub = null;
        $offset = 0;
        $combo = str_split($pattern);

        while (!feof($fp)) {
            if (fgetc($fp) === $combo[$offset]) {
                $offset++;

                if (!isset($combo[$offset])) {
                    $stub = ftell($fp);

                    break;
                }
            } else {
                $offset = 0;
            }
        }

        fclose($fp);

        if (null === $stub) {
            throw new InvalidArgumentException(
                sprintf(
                    'The pattern could not be found in "%s".',
                    $file
                )
            );
        }

        return $stub;
    }
public static function findStubLength ( $ file , $ pattern = self :: PATTERN_OPEN ) { if ( ! ( $ fp = fopen ( $ file , 'rb' ) ) ) { throw new RuntimeException ( sprintf ( 'The phar "%s" could not be opened for reading.' , $ file ) ) ; } $ stub = null ; $ offset = 0 ; $ combo = str_split ( $ pattern ) ; while ( ! feof ( $ fp ) ) { if ( fgetc ( $ fp ) === $ combo [ $ offset ] ) { $ offset ++ ; if ( ! isset ( $ combo [ $ offset ] ) ) { $ stub = ftell ( $ fp ) ; break ; } } else { $ offset = 0 ; } } fclose ( $ fp ) ; if ( null === $ stub ) { throw new InvalidArgumentException ( sprintf ( 'The pattern could not be found in "%s".' , $ file ) ) ; } return $ stub ; }
Finds the phar's stub length using the end pattern.

A "pattern" is a sequence of characters that indicate the end of a
stub, and the beginning of a manifest. This determines the complete
size of a stub, and is used as an offset to begin parsing the data
contained in the phar's manifest.

The stub generated included with the Box library uses what I like
to call an open-ended pattern. This pattern uses the function
"__HALT_COMPILER();" at the end, with no following whitespace or
closing PHP tag. By default, this method will use that pattern,
defined as `Extract::PATTERN_OPEN`.

The Phar class generates its own default stub. The pattern for the
default stub is slightly different than the one used by Box. This
pattern is defined as `Extract::PATTERN_DEFAULT`.

If you have used your own custom stub, you will need to specify its
pattern as the `$pattern` argument, if you cannot use either of the
pattern constants defined.

@param string $file    The phar file path.
@param string $pattern The stub end pattern.

@return integer The stub length.

@throws InvalidArgumentException If the pattern could not be found.
@throws RuntimeException         If the phar could not be read.
Finds the phar s stub length using the end pattern .