Flourish PHP Unframework

fORMFile

static class, v1.0.0b30

Provides file manipulation functionality for fActiveRecord classes

Changes:
1.0.0b30Updated code for the new fUpload API 8/24/11
1.0.0b29Fixed a bug when uploading a new file to a column with an existing file that was not found on the filesystem 5/10/11
1.0.0b28Backwards Compatibility Break - configureImageUploadColumn() no longer accepts the optional $image_type as the fourth parameter, instead addFImageMethodCall() must be called with saveChanges as the $method and the image type as the first parameter 11/30/10
1.0.0b27Fixed column inheritance to properly handle non-images and inheriting into image upload columns 9/18/10
1.0.0b26Enhanced configureColumnInheritance() to ensure both columns specified have been set up as file upload columns 8/18/10
1.0.0b25Updated code to work with the new fORM API 8/6/10
1.0.0b24Changed validation messages array to use column name keys 5/26/10
1.0.0b23Fixed a bug with upload() that could cause a method called on a non-object error in relation to the upload directory not being defined 5/10/10
1.0.0b22Updated the TEMP_DIRECTORY constant to not include the trailing slash, code now uses DIRECTORY_SEPARATOR to fix issues on Windows 4/28/10
1.0.0b21Fixed set() to perform column inheritance, just like upload() does 3/15/10
1.0.0b20Fixed the set and process methods to return the record instance, changed upload methods to return the fFile object, updated reflect() with new return values 3/15/10
1.0.0b19Fixed a few missed instances of old fFile method names 12/16/09
1.0.0b18Updated code for the new fFile API 12/16/09
1.0.0b17Updated code for the new fORMDatabase and fORMSchema APIs 10/28/09
1.0.0b16fImage method calls for file upload columns will no longer cause notices due to a missing image type 9/9/09
1.0.0b15addFImageMethodCall() no longer requires column be an image upload column, inheritance to an image column now only happens for fImage objects 7/29/09
1.0.0b14Updated to use new fORM::registerInspectCallback() method 7/13/09
1.0.0b13Updated code for new fORM API 6/15/09
1.0.0b12Changed replacement values in preg_replace() calls to be properly escaped 6/11/09
1.0.0b11Updated code to use new fValidationException::formatField() method 6/4/09
1.0.0b10Fixed a bug where an inherited file upload column would not be properly re-set with an existing- input 5/26/09
1.0.0b9upload() and set() now set the $values entry to NULL for filenames that are empty 3/2/09
1.0.0b8Changed set() to accept objects and reject directories 1/21/09
1.0.0b7Changed the class to use the new fFilesystem::createObject() method 1/21/09
1.0.0b6Old files are now checked against the current file to prevent removal of an in-use file 12/23/08
1.0.0b5Fixed replicate() to ensure the temp directory exists and set() to use the temp directory 12/23/08
1.0.0b4objectify() no longer throws an exception when a file can't be found 12/18/08
1.0.0b3Added replicate() so that replicated files get pu in the temp directory 12/12/08
1.0.0b2Fixed a bug with objectifying file columns 11/24/08
1.0.0bThe initial implementation 5/28/08

Constants

::TEMP_DIRECTORY internal

Please note: this constant is primarily intended for internal use by Flourish and will normally not be useful in site/application code

The temporary directory to use for various tasks

Static Methods

::addFImageMethodCall() public

Adds an fImage method call to the image manipulation for a column if an image file is uploaded

Any call to fImage::saveChanges() will be called last. If no explicit method call to fImage::saveChanges() is made, it will be called implicitly with default parameters.

Signature

void addFImageMethodCall( mixed $class, string $column, string $method, array $parameters=array() )

Parameters

mixed $class The class name or instance of the class
string $column The column to call the method for
string $method The fImage method to call
array $parameters The parameters to pass to the method

::addFUploadMethodCall() public

Adds an fUpload method call to the fUpload initialization for a column

Signature

void addFUploadMethodCall( mixed $class, string $column, string $method, array $parameters=array() )

Parameters

mixed $class The class name or instance of the class
string $column The column to call the method for
string $method The fUpload method to call
array $parameters The parameters to pass to the method

::begin() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Begins a transaction, or increases the level

Signature

void begin( )

::commit() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Commits a transaction, or decreases the level

Signature

void commit( )

::configureColumnInheritance() public

Takes one file or image upload columns and sets it to inherit any uploaded/set files from another column

Signature

void configureColumnInheritance( mixed $class, string $column, string $inherit_from_column )

Parameters

mixed $class The class name or instance of the class
string $column The column that will inherit the uploaded file
string $inherit_from_column The column to inherit the uploaded file from

::configureFileUploadColumn() public

Sets a column to be a file upload column

Configuring a column to be a file upload column means that whenever fActiveRecord::populate() is called for an fActiveRecord object, any appropriately named file uploads (via $_FILES) will be moved into the directory for this column.

Setting the column to a file path will cause the specified file to be copied into the directory for this column.

Signature

void configureFileUploadColumn( mixed $class, string $column, fDirectory|string $directory )

Parameters

mixed $class The class name or instance of the class
string $column The column to set as a file upload column
fDirectory|string $directory The directory to upload/move to

::configureImageUploadColumn() public

Sets a column to be an image upload column

This method works exactly the same as configureFileUploadColumn() except that only image files are accepted.

To alter an image, including the file type, use addFImageMethodCall().

Signature

void configureImageUploadColumn( mixed $class, string $column, fDirectory|string $directory )

Parameters

mixed $class The class name or instance of the class
string $column The column to set as a file upload column
fDirectory|string $directory The directory to upload to

::delete() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Deletes the files for this record

Signature

void delete( fActiveRecord $object, array &$values, array &$old_values, array &$related_records, array &$cache )

Parameters

fActiveRecord $object The fActiveRecord instance
array &$values The current values
array &$old_values The old values
array &$related_records Any records related to this record
array &$cache The cache array for the record

::deleteOld() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Deletes old files for this record that have been replaced by new ones

Signature

void deleteOld( fActiveRecord $object, array &$values, array &$old_values, array &$related_records, array &$cache )

Parameters

fActiveRecord $object The fActiveRecord instance
array &$values The current values
array &$old_values The old values
array &$related_records Any records related to this record
array &$cache The cache array for the record

::encode() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Encodes a file for output into an HTML input tag

Signature

void encode( fActiveRecord $object, array &$values, array &$old_values, array &$related_records, array &$cache, string $method_name, array $parameters )

Parameters

fActiveRecord $object The fActiveRecord instance
array &$values The current values
array &$old_values The old values
array &$related_records Any records related to this record
array &$cache The cache array for the record
string $method_name The method that was called
array $parameters The parameters passed to the method

::inspect() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Adds metadata about features added by this class

Signature

void inspect( string $class, string $column, array &$metadata )

Parameters

string $class The class being inspected
string $column The column being inspected
array &$metadata The array of metadata about a column

::moveFromTemp() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Moves uploaded files from the temporary directory to the permanent directory

Signature

void moveFromTemp( fActiveRecord $object, array &$values, array &$old_values, array &$related_records, array &$cache )

Parameters

fActiveRecord $object The fActiveRecord instance
array &$values The current values
array &$old_values The old values
array &$related_records Any records related to this record
array &$cache The cache array for the record

::objectify() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Turns a filename into an fFile or fImage object

Signature

mixed objectify( string $class, string $column, mixed $value )

Parameters

string $class The class this value is for
string $column The column the value is in
mixed $value The value

Returns

The fFile, fImage or raw value

::populate() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Performs the upload action for file uploads during fActiveRecord::populate()

Signature

void populate( fActiveRecord $object, array &$values, array &$old_values, array &$related_records, array &$cache )

Parameters

fActiveRecord $object The fActiveRecord instance
array &$values The current values
array &$old_values The old values
array &$related_records Any records related to this record
array &$cache The cache array for the record

::prepare() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Prepares a file for output into HTML by returning filename or the web server path to the file

Signature

void prepare( fActiveRecord $object, array &$values, array &$old_values, array &$related_records, array &$cache, string $method_name, array $parameters )

Parameters

fActiveRecord $object The fActiveRecord instance
array &$values The current values
array &$old_values The old values
array &$related_records Any records related to this record
array &$cache The cache array for the record
string $method_name The method that was called
array $parameters The parameters passed to the method

::process() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Handles re-processing an existing image file

Signature

fActiveRecord process( fActiveRecord $object, array &$values, array &$old_values, array &$related_records, array &$cache, string $method_name, array $parameters )

Parameters

fActiveRecord $object The fActiveRecord instance
array &$values The current values
array &$old_values The old values
array &$related_records Any records related to this record
array &$cache The cache array for the record
string $method_name The method that was called
array $parameters The parameters passed to the method

Returns

The record object, to allow for method chaining

::processImage() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Performs image manipulation on an uploaded/set image

Signature

void processImage( string $class, string $column, fFile $image )

Parameters

string $class The name of the class we are manipulating the image for
string $column The column the image is assigned to
fFile $image The image object to manipulate

::reflect() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Adjusts the fActiveRecord::reflect() signatures of columns that have been configured in this class

Signature

void reflect( string $class, array &$signatures, boolean $include_doc_comments )

Parameters

string $class The class to reflect
array &$signatures The associative array of {method name} => {signature}
boolean $include_doc_comments If doc comments should be included with the signature

::replicate() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Creates a copy of an uploaded file in the temp directory for the newly cloned record

Signature

mixed replicate( string $class, string $column, mixed $value )

Parameters

string $class The class this value is for
string $column The column the value is in
mixed $value The value

Returns

The cloned fFile object

::reset() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Resets the configuration of the class

Signature

void reset( )

::rollback() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Rolls back a transaction, or decreases the level

Signature

void rollback( )

::set() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Copies a file from the filesystem to the file upload directory and sets it as the file for the specified column

This method will perform the fImage calls defined for the column.

Signature

fActiveRecord set( fActiveRecord $object, array &$values, array &$old_values, array &$related_records, array &$cache, string $method_name, array $parameters )

Parameters

fActiveRecord $object The fActiveRecord instance
array &$values The current values
array &$old_values The old values
array &$related_records Any records related to this record
array &$cache The cache array for the record
string $method_name The method that was called
array $parameters The parameters passed to the method

Returns

The record object, to allow for method chaining

::upload() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Uploads a file

Signature

fFile upload( fActiveRecord $object, array &$values, array &$old_values, array &$related_records, array &$cache, string $method_name, array $parameters )

Parameters

fActiveRecord $object The fActiveRecord instance
array &$values The current values
array &$old_values The old values
array &$related_records Any records related to this record
array &$cache The cache array for the record
string $method_name The method that was called
array $parameters The parameters passed to the method

Returns

The uploaded file

::validate() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Validates uploaded files to ensure they match all of the criteria defined

Signature

void validate( fActiveRecord $object, array &$values, array &$old_values, array &$related_records, array &$cache, array &$validation_messages )

Parameters

fActiveRecord $object The fActiveRecord instance
array &$values The current values
array &$old_values The old values
array &$related_records Any records related to this record
array &$cache The cache array for the record
array &$validation_messages The existing validation messages