Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Timestamps.php

function Timestamps::determineSignatureBegin

Determine the beginning of the signature.

Return value

int

1 call to Timestamps::determineSignatureBegin()
Timestamps::save in vendor/seld/phar-utils/src/Timestamps.php
Saves the updated phar file, optionally with an updated signature.

File

vendor/seld/phar-utils/src/Timestamps.php, line 144

Class

Timestamps

Namespace

Seld\PharUtils

Code

private function determineSignatureBegin() {
    // detect signature position
    if (!preg_match('{__HALT_COMPILER\\(\\);(?: +\\?>)?\\r?\\n}', $this->contents, $match, PREG_OFFSET_CAPTURE)) {
        throw new \RuntimeException('Could not detect the stub\'s end in the phar');
    }
    // set starting position and skip past manifest length
    $pos = $match[0][1] + strlen($match[0][0]);
    $manifestEnd = $pos + 4 + $this->readUint($pos, 4);
    $pos += 4;
    $numFiles = $this->readUint($pos, 4);
    $pos += 4;
    // skip API version (YOLO)
    $pos += 2;
    // skip PHAR flags
    $pos += 4;
    $aliasLength = $this->readUint($pos, 4);
    $pos += 4 + $aliasLength;
    $metadataLength = $this->readUint($pos, 4);
    $pos += 4 + $metadataLength;
    $compressedSizes = 0;
    while ($numFiles > 0 && $pos < $manifestEnd - 24) {
        $filenameLength = $this->readUint($pos, 4);
        $pos += 4 + $filenameLength;
        // skip filesize and timestamp
        $pos += 2 * 4;
        $compressedSizes += $this->readUint($pos, 4);
        // skip compressed file size, crc32 checksum and file flags
        $pos += 3 * 4;
        $metadataLength = $this->readUint($pos, 4);
        $pos += 4 + $metadataLength;
        $numFiles--;
    }
    if ($numFiles !== 0) {
        throw new \LogicException('All files were not processed, something must have gone wrong');
    }
    return $manifestEnd + $compressedSizes;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal