class Loader implements LoaderInterface

Default implementation of Imagine\File\LoaderInterface.

Constants

MINIMUM_CURL_VERSION

The mimimum supported version of curl.

Properties

protected string $path The file path.
protected bool $isUrl Does $path contain an URL?
protected string|null $data The loaded data.
protected bool|null $isCurlSupported Is curl available, with a decent version?

Methods

__construct(string|mixed $path)

Initialize the instance.

bool
isLocalFile()

Is this a local file.

string
getPath()

Get the path of the file (local or remote).

bool
hasReadData()

Is the binary content already loaded?

string
getData()

Get the file binary contents.

string
__toString()

The string representation of this object must be the file path (local or remote).

string
readLocalFile()

Read a local file.

checkLocalFile()

Check that the file exists and it's readable.

string
readRemoteFile()

Read a remote file.

bool
isCurlSupported()

Check if curl is available and it's a decent version.

string
readRemoteFileWithCurl()

Read a remote file using the cURL extension.

setCurlOptions(resource $curl)

Set curl options.

string
readRemoteFileWithFileGetContents()

Read a remote file using the file_get_contents.

Details

at line 61
__construct(string|mixed $path)

Initialize the instance.

Parameters

string|mixed $path the file path (or an object whose string representation is the file path)

Exceptions

InvalidArgumentException throws an InvalidArgumentException is $path is an empty string, or is not an object that has a __toString method

at line 82
bool isLocalFile()

Is this a local file.

Return Value

bool

See also

LoaderInterface::isLocalFile

at line 92
string getPath()

Get the path of the file (local or remote).

Return Value

string

See also

LoaderInterface::getPath

at line 102
bool hasReadData()

Is the binary content already loaded?

Return Value

bool

See also

LoaderInterface::hasReadData

at line 115
string getData()

Get the file binary contents.

Return Value

string

See also

LoaderInterface::getData

at line 133
string __toString()

The string representation of this object must be the file path (local or remote).

Return Value

string

See also

LoaderInterface::__toString

at line 145
protected string readLocalFile()

Read a local file.

Return Value

string

Exceptions

InvalidArgumentException

at line 161
protected checkLocalFile()

Check that the file exists and it's readable.

at line 179
protected string readRemoteFile()

Read a remote file.

Return Value

string

Exceptions

InvalidArgumentException
RuntimeException

at line 193
protected bool isCurlSupported()

Check if curl is available and it's a decent version.

Return Value

bool

at line 218
protected string readRemoteFileWithCurl()

Read a remote file using the cURL extension.

Return Value

string

Exceptions

InvalidArgumentException

at line 259
protected setCurlOptions(resource $curl)

Set curl options.

Parameters

resource $curl

Exceptions

RuntimeException

at line 287
protected string readRemoteFileWithFileGetContents()

Read a remote file using the file_get_contents.

Return Value

string

Exceptions

InvalidArgumentException