ProxyServer
in package
This is a lightweight proxy for serving images, generally meant to be used alongside SSL.
Table of Contents
Properties
- $cache : string
- $cachedbody : string
- $cachedsize : int
- $cachedtime : int
- $cachedtype : string
- $enabled : bool
- $maxDays : int
- $maxSize : int
- $secret : string
Methods
- __construct() : mixed
- Constructor. Loads up the settings for the proxy.
- checkRequest() : bool
- Checks whether the request is valid or not.
- housekeeping() : void
- Delete all old entries
- serve() : void
- Serves the request.
- cacheImage() : bool
- Attempts to cache the image while validating it.
- getCachedPath() : string
- Returns the request's hashed filepath
- isCached() : bool
- Check whether the image exists in local cache or not
- redirectexit() : void
- A helper function to redirect a request
Properties
$cache
protected
string
$cache
The cache directory.
$cachedbody
protected
string
$cachedbody
Body of object cached.
$cachedsize
protected
int
$cachedsize
Size of object cached.
$cachedtime
protected
int
$cachedtime
Time object cached.
$cachedtype
protected
string
$cachedtype
Type of object cached.
$enabled
protected
bool
$enabled
Whether or not this is enabled.
$maxDays
protected
int
$maxDays
Days until entries get deleted
$maxSize
protected
int
$maxSize
The maximum size for files to cache.
$secret
protected
string
$secret
A secret code used for hashing.
Methods
__construct()
Constructor. Loads up the settings for the proxy.
public
__construct() : mixed
checkRequest()
Checks whether the request is valid or not.
public
checkRequest() : bool
Return values
bool —Whether the request is valid.
housekeeping()
Delete all old entries
public
housekeeping() : void
serve()
Serves the request.
public
serve() : void
cacheImage()
Attempts to cache the image while validating it.
protected
cacheImage(string $request) : bool
Redirects to the origin if
- the image couldn't be fetched
- the MIME type doesn't indicate an image
- the image is too large
Parameters
- $request : string
-
The image to cache/validate.
Return values
bool —Whether the specified image was cached.
getCachedPath()
Returns the request's hashed filepath
protected
getCachedPath(Url|string $request) : string
Parameters
- $request : Url|string
-
The request to get the path for
Return values
string —The hashed filepath for the specified request
isCached()
Check whether the image exists in local cache or not
protected
isCached(string $request) : bool
Parameters
- $request : string
-
The image to check for in the cache
Return values
bool —Whether or not the requested image is cached
redirectexit()
A helper function to redirect a request
private
redirectexit(Url|string $request) : void
Parameters
- $request : Url|string