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

Breadcrumb

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

function RemoteFilesystem::getRemoteContents

Get contents of remote URL.

@param-out list<string> $responseHeaders

Parameters

string $originUrl The origin URL:

string $fileUrl The file URL:

resource $context The stream context:

string[] $responseHeaders:

int $maxFileSize The maximum allowed file size:

Return value

string|false The response contents or false on failure

1 call to RemoteFilesystem::getRemoteContents()
RemoteFilesystem::get in vendor/composer/composer/src/Composer/Util/RemoteFilesystem.php
Get file content or copy action.

File

vendor/composer/composer/src/Composer/Util/RemoteFilesystem.php, line 516

Class

RemoteFilesystem
@internal @author François Pluchino <francois.pluchino@opendisplay.com> @author Jordi Boggiano <j.boggiano@seld.be> @author Nils Adermann <naderman@naderman.de>

Namespace

Composer\Util

Code

protected function getRemoteContents(string $originUrl, string $fileUrl, $context, ?array &$responseHeaders = null, ?int $maxFileSize = null) {
    $result = false;
    try {
        $e = null;
        if ($maxFileSize !== null) {
            $result = file_get_contents($fileUrl, false, $context, 0, $maxFileSize);
        }
        else {
            // passing `null` to file_get_contents will convert `null` to `0` and return 0 bytes
            $result = file_get_contents($fileUrl, false, $context);
        }
    } catch (\Throwable $e) {
    }
    if ($result !== false && $maxFileSize !== null && Platform::strlen($result) >= $maxFileSize) {
        throw new MaxFileSizeExceededException('Maximum allowed download size reached. Downloaded ' . Platform::strlen($result) . ' of allowed ' . $maxFileSize . ' bytes');
    }
    // https://www.php.net/manual/en/reserved.variables.httpresponseheader.php
    if (\PHP_VERSION_ID >= 80400) {
        $responseHeaders = http_get_last_response_headers();
        http_clear_last_response_headers();
    }
    else {
        $responseHeaders = $http_response_header ?? [];
    }
    if (null !== $e) {
        throw $e;
    }
    return $result;
}

API Navigation

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