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

Breadcrumb

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

function Timestamps::save

Saves the updated phar file, optionally with an updated signature.

Parameters

string $path:

int $signatureAlgo One of Phar::MD5, Phar::SHA1, Phar::SHA256 or Phar::SHA512:

Return value

bool

File

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

Class

Timestamps

Namespace

Seld\PharUtils

Code

public function save($path, $signatureAlgo) {
    $pos = $this->determineSignatureBegin();
    $algos = array(
        \Phar::MD5 => 'md5',
        \Phar::SHA1 => 'sha1',
        \Phar::SHA256 => 'sha256',
        \Phar::SHA512 => 'sha512',
    );
    if (!isset($algos[$signatureAlgo])) {
        throw new \UnexpectedValueException('Invalid hash algorithm given: ' . $signatureAlgo . ' expected one of Phar::MD5, Phar::SHA1, Phar::SHA256 or Phar::SHA512');
    }
    $algo = $algos[$signatureAlgo];
    // re-sign phar
    //           signature
    $signature = hash($algo, substr($this->contents, 0, $pos), true) . pack('L', $signatureAlgo) . 'GBMB';
    $this->contents = substr($this->contents, 0, $pos) . $signature;
    return file_put_contents($path, $this->contents);
}

API Navigation

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