\CRemoteImage

Get a image from a remote server using HTTP GET and If-Modified-Since.

Summary

Methods
Properties
Constants
getStatus()
getDetails()
setCache()
isCacheWritable()
useCache()
setHeaderFields()
save()
updateCacheDetails()
download()
loadCacheDetails()
getCachedSource()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
$saveFolder
$useCache
$http
$status
$defaultMaxAge
$url
$fileName
$fileJson
$cache
N/A

Properties

$saveFolder

$saveFolder : 

Path to cache files.

Type

$useCache

$useCache : 

Use cache or not.

Type

$http

$http : 

HTTP object to aid in download file.

Type

$status

$status : 

Status of the HTTP request.

Type

$defaultMaxAge

$defaultMaxAge : 

Defalt age for cached items 60*60*24*7.

Type

$url

$url : 

Url of downloaded item.

Type

$fileName

$fileName : 

Base name of cache file for downloaded item and name of image.

Type

$fileJson

$fileJson : 

Filename for json-file with details of cached item.

Type

$cache

$cache : 

Cache details loaded from file.

Type

Methods

getStatus()

getStatus() : integer

Get status of last HTTP request.

Returns

integer —

as status

getDetails()

getDetails() : array

Get JSON details for cache item.

Returns

array —

with json details on cache.

setCache()

setCache(  $path) : $this

Set the path to the cache directory.

Parameters

$path

Returns

$this

isCacheWritable()

isCacheWritable() : $this

Check if cache is writable or throw exception.

Throws

\Exception

if cahce folder is not writable.

Returns

$this

useCache()

useCache(boolean  $use = true) : $this

Decide if the cache should be used or not before trying to download a remote file.

Parameters

boolean $use

true to use the cache and false to ignore cache.

Returns

$this

setHeaderFields()

setHeaderFields() : $this

Set header fields.

Returns

$this

save()

save() : string

Save downloaded resource to cache.

Returns

string —

as path to saved file or false if not saved.

updateCacheDetails()

updateCacheDetails() : string

Got a 304 and updates cache with new age.

Returns

string —

as path to cached file.

download()

download(string  $url) : string

Download a remote file and keep a cache of downloaded files.

Parameters

string $url

a remote url.

Throws

\Exception

when status code does not match 200 or 304.

Returns

string —

as path to downloaded file or false if failed.

loadCacheDetails()

loadCacheDetails() : $this

Get the path to the cached image file if the cache is valid.

Returns

$this

getCachedSource()

getCachedSource() : string

Get the path to the cached image file if the cache is valid.

Returns

string —

as the path ot the image file or false if no cache.