\Klutz_Driver_File

Klutz Driver implementation for comics as files.

Required parameters:

'directory'  The main directory the comics are stored in
'sumsfile'   The filename to hold md5sums for images

Summary

Methods
Properties
Constants
factory()
listDates()
imageSize()
imageExists()
storeImage()
retrieveImage()
Klutz_Driver_file()
loadSums()
saveSums()
rebuildSums()
addSum()
removeSum()
isUnique()
removeImage()
removeDate()
$basedir
$subdir
$sumsfile
$diffs
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Properties

$basedir

$basedir : string

The base directory we store comics in.

Type

string

$subdir

$subdir : string

The format for the various subdirectories.

WARNING: DO NOT CHANGE THIS!

Type

string

$sumsfile

$sumsfile : string

The file we store unique image identifiers in.

Type

string

$diffs

$diffs : array

The actual array of unique image identifiers (md5 sums right now).

Key is the full path of the comic, value is md5

Type

array

Methods

factory()

factory(string  $driver = null, array  $params = null) : object

Gets a concrete Klutz_Driver instance.

Parameters

string $driver

The type of concrete Klutz_Driver subclass to return. The code for the driver is dynamically included.

array $params

A hash containing any additional configuration or connection parameters a subclass might need

Returns

object —

Klutz_Driver The newly created concrete instance, or false on error.

listDates()

listDates(\timestamp  $date = null, \timestamp  $oldest = null, \timestamp  $newest = null) : array

Get a list of the dates for which we have comics between $oldest and $newest. Only returns dates we have at least one comic for.

Parameters

\timestamp $date

The reference date (default today)

\timestamp $oldest

The earliest possible date to return (default first of the month)

\timestamp $newest

The latest possible date to return (default last date of the month)

Returns

array —

timestamps Any dates between $oldest and $newest that we have comics for.

imageSize()

imageSize(string  $index, \timestamp  $date = null) : string

Get the image dimensions for the requested image.

The image is not stored locally so this function returns an empty string. Performance hit is too expensive to make this worth it.

Parameters

string $index

The index of the comic to check

\timestamp $date

The date of the comic to check (default today)

Returns

string —

Attributes for an tag giving height and width

imageExists()

imageExists(string  $index, \timestamp  $date = null) : boolean

Find out if we already have a local copy of this image.

Even though we never actually store a local copy, pretend.

Parameters

string $index

The index of the comic to check

\timestamp $date

The date of the comic to check (default today)

Returns

boolean —

False in this driver

storeImage()

storeImage(string  $index, string  $image,   $date = null) : boolean

Store an image for later retrieval.

Even though we never actually store a local copy, pretend.

Parameters

string $index

The index of the comic to retrieve

string $image

Raw (binary) image data to store

$date

Returns

boolean —

True on success, false otherwise

retrieveImage()

retrieveImage(string  $index, \timestamp  $date = null) : mixed

Retrieve an image from storage. Make sure the image exists first with imageExists().

Parameters

string $index

The index of the comic to retrieve

\timestamp $date

The date for which we want $comic

Returns

mixed —

If the image exists locally, return a Klutz_Image object. If it doesn't, return a string with the URL pointing to the comic.

Klutz_Driver_file()

Klutz_Driver_file(array  $params = array()) 

Constructs a new file storage object.

Parameters

array $params

A hash containing connection parameters.

loadSums()

loadSums() : void

Load a list of unique identifiers for comics from the sumsfile.

saveSums()

saveSums() : void

Save the list of unique identifiers for comics to the sumsfile.

rebuildSums()

rebuildSums() : void

Rebuild the table of unique identifiers.

addSum()

addSum(string  $index, \timestamp  $date, string  $data) : void

Add a unique identifier for a given image.

Parameters

string $index

The index for the comic

\timestamp $date

The date of the comic

string $data

The md5 of the raw (binary) image data

removeSum()

removeSum(string  $index = null, \timestamp  $date = null) : void

Remove the unique identifier for the given comic and/or date. If both are passed, removes the uid for that comic and date. If only a comic is passed, removes all uids for that comic. If only a date is passed removes uids for all comics on that date. If neither is passed, all uids are wiped out.

Parameters

string $index

Index for the comic to delete. If left out all comics will be assumed.

\timestamp $date

Date to remove. If left out, assumes all dates.

isUnique()

isUnique(  $image) : boolean

Determine if the image passed is a unique image (one we don't already have).

This allows for $days = random, etc., but keeps us from getting the same comic day after day.

Parameters

$image

Returns

boolean —

True if unique, false otherwise.

removeImage()

removeImage(string  $index, \timestamp  $date = null) : boolean

Remove an image from the storage system (including its unique ID).

Parameters

string $index

The index of the comic to remove

\timestamp $date

The date of the comic to remove (default today)

Returns

boolean —

True on success, else false

removeDate()

removeDate(\timestamp  $date = null) : boolean

Remove all images from the storage system (including unique IDs) for a given date.

Parameters

\timestamp $date

The date to remove comics for (default today)

Returns

boolean —

True on success, else false