Tripal
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Drupal\tripal\Services\TripalFileRetriever Class Reference

Public Member Functions

 __construct (\GuzzleHttp\ClientInterface $httpClient, TripalLogger $logger)
 
 retrieveFileContents (string $url, array $options=[])
 

Static Public Member Functions

static create (ContainerInterface $container)
 

Protected Member Functions

 doRateLimit (float $rate_limit)
 
 doSleep (float $sleep_time)
 

Protected Attributes

 $httpClient = NULL
 
 $logger
 
 $last_request_time = NULL
 

Detailed Description

The TripalFileLoader class handles copying files from both remote URLs or local file paths, with resiliance against errors.

Constructor & Destructor Documentation

◆ __construct()

Drupal\tripal\Services\TripalFileRetriever::__construct ( \GuzzleHttp\ClientInterface  $httpClient,
TripalLogger  $logger 
)

Constructor

Member Function Documentation

◆ create()

static Drupal\tripal\Services\TripalFileRetriever::create ( ContainerInterface  $container)
static

{}

◆ doRateLimit()

Drupal\tripal\Services\TripalFileRetriever::doRateLimit ( float  $rate_limit)
protected

Implements a rate limit between successive download requests.

Parameters
float$rate_limitA number of seconds to wait between successive download requests. If zero, do not wait.

◆ doSleep()

Drupal\tripal\Services\TripalFileRetriever::doSleep ( float  $sleep_time)
protected

Sleep for the number of seconds specified by a float.

Since usleep() may not support > 1 second, this uses time_nanosleep().

Parameters
float$sleep_timeA positive real number specifying some amount of time to sleep.

◆ retrieveFileContents()

Drupal\tripal\Services\TripalFileRetriever::retrieveFileContents ( string  $url,
array  $options = [] 
)

Download the contents of a remote or local file from a specified URL.

The contents of the file are returned as a string for both remote and local files.

NOTE: This method will retry if it is unable to download the file from an accessible URL. This is controlled via the 'retries' and 'retry_delay' options. If the URL provided is inaccessible this triggers the 'rate_limit' option.

Parameters
string$urlThe address of the file to download
array$optionsValid keys:
  • retries (int): how many times to retry a download, default = 3.
  • rate_limit (float; default = 0): seconds between HTTP requests.
  • retry_delay (float; default 1): seconds between retries.
  • client_options (array): any options to pass to the http client.
Returns
string The data obtained from the specified url, or NULL if it could not be downloaded

Member Data Documentation

◆ $httpClient

object GuzzleHttp ClientInterface Drupal\tripal\Services\TripalFileRetriever::$httpClient = NULL
protected

The Drupal HTTP service (i.e. guzzle)

◆ $logger

TripalLogger Drupal\tripal\Services\TripalFileRetriever::$logger
protected

A logger object.


The documentation for this class was generated from the following file: