You are here

public function HttpStreamWrapper::stream_stat in Remote Stream Wrapper 8

Return value

array

Overrides PhpStreamWrapperInterface::stream_stat

1 call to HttpStreamWrapper::stream_stat()
HttpStreamWrapper::url_stat in src/StreamWrapper/HttpStreamWrapper.php

File

src/StreamWrapper/HttpStreamWrapper.php, line 221

Class

HttpStreamWrapper
HTTP(s) stream wrapper.

Namespace

Drupal\remote_stream_wrapper\StreamWrapper

Code

public function stream_stat() {

  // @see https://github.com/guzzle/psr7/blob/master/src/StreamWrapper.php
  $stat = [
    'dev' => 0,
    // device number
    'ino' => 0,
    // inode number
    'mode' => 0100000 | 0444,
    // inode protection (regular file + read only)
    'nlink' => 0,
    // number of links
    'uid' => 0,
    // userid of owner
    'gid' => 0,
    // groupid of owner
    'rdev' => 0,
    // device type, if inode device *
    'size' => 0,
    // size in bytes
    'atime' => 0,
    // time of last access (Unix timestamp)
    'mtime' => 0,
    // time of last modification (Unix timestamp)
    'ctime' => 0,
    // time of last inode change (Unix timestamp)
    'blksize' => 0,
    // blocksize of filesystem IO
    'blocks' => 0,
  ];
  try {
    $response = $this
      ->requestTryHeadLookingForHeader($this->uri, 'Content-Length', $this->config);
    if ($response
      ->hasHeader('Content-Length')) {
      $stat['size'] = (int) $response
        ->getHeaderLine('Content-Length');
    }
    elseif ($size = $response
      ->getBody()
      ->getSize()) {
      $stat['size'] = $size;
    }
    if ($response
      ->hasHeader('Last-Modified')) {
      if ($mtime = strtotime($response
        ->getHeaderLine('Last-Modified'))) {
        $stat['mtime'] = $mtime;
      }
    }
    return $stat;
  } catch (\Exception $exception) {
    watchdog_exception('remote_stream_wrapper', $exception);
    return NULL;
  }
}