FRED™  3.0
FRED™: Framework for Rapid and Easy Development
File Class Reference

File storage and archiving. More...

Inheritance diagram for File:
Component Thing

Public Member Functions

 name ($type, $id)
 Filename for a file. More...
 
 exists ($type, $id)
 Check if a file exists. More...
 
 save ($type, $id, $data)
 Save date into a file (archive existing file first). More...
 
 delete ($type, $id)
 Delete a file (archive first). More...
 
 archives ($type, $id, $time=null)
 Find archive files. More...
 
 purge ($type, $time)
 Purge the archive. More...
 
 purgeAll ()
 Purge archive for all types with an optional "purge" parameter. More...
 
- Public Member Functions inherited from Component
 __construct ($fred, $config=null)
 
 __destruct ()
 
 clientConfig ()
 Public configuration. More...
 
 config ($key, $default=null)
 Retrieve a config value. More...
 
 ping ()
 Ping function. More...
 
 filemtime ($filename)
 Filemtime with session cache. More...
 
 component ($name)
 Get a component (local or default). More...
 
 components (... $names)
 Get multiple components in an array. More...
 
- Public Member Functions inherited from Thing
 propertyExists ($property)
 Check if a property exists (public or published). More...
 
 constants ($prefix=null)
 Return all constants. More...
 
 get ($key)
 Get one or more properties. More...
 
 set ($key, $value=null)
 Set one or more properties. More...
 
 __get ($key)
 
 __set ($key, $value)
 

Data Fields

const EVENT_ARCHIVE = 'file:archive'
 
const EVENT_SAVE = 'file:save'
 
const EVENT_DELETE = 'file:delete'
 
 $mode = null
 File mode (not set if empty). More...
 
- Data Fields inherited from Component
 $filemtimeTtl = 0
 
- Data Fields inherited from Thing
const HIDDEN = 0
 Property is hidden. More...
 
const READABLE = 1
 Property is readable. More...
 
const WRITEABLE = 2
 Property is writeable. More...
 
const READWRITE = 3
 Property is readable and writeable. More...
 

Protected Member Functions

 format ($format, $id, $index=null, $time=null)
 
 archive ($type, $id, &$filename=null)
 Archive a file (if it exists). More...
 
 find ($dir, $dirs, $time=null)
 Find archive files in a directory. More...
 
- Protected Member Functions inherited from Component
 init ()
 
 done ()
 
 getSession ()
 
- Protected Member Functions inherited from Thing
 publish ($property, $visibility=self::READABLE)
 Publish a property (or hide it again). More...
 
 alias ($alias, $property, $object=null)
 Define an alias for a property (of another object). More...
 
 configure ($config)
 Configure the object. More...
 
 _get ($key)
 Default getter if no specific setter is defined, and the property is also not published (readable). More...
 
 _set ($key, $value)
 Default setter if no specific setter is defined, and the property is also not published (writeable). More...
 

Protected Attributes

 $_indexBase = 1
 Index starting value. More...
 
 $_indexSize = 0
 Minimum index length (prefixed with zeros when smaller). More...
 
 $_types = []
 Key = type name, value = array with 'format' and optional 'archive' format. An asterisk is. More...
 
- Protected Attributes inherited from Component
 $_fred = null
 
 $_config = null
 
 $_name = null
 
 $_components = []
 Local components (key = component name, value = component). More...
 
 $_session = null
 
- Protected Attributes inherited from Thing
 $_published = []
 Published properties (key = name of property, value = visibility). More...
 
 $_aliases = []
 Alias properties (key = alias, value = [object,property]). More...
 

Detailed Description

File storage and archiving.

Definition at line 8 of file File.php.

Member Function Documentation

◆ archive()

archive (   $type,
  $id,
$filename = null 
)
protected

Archive a file (if it exists).

Parameters
string$typeFile type.
string$idFile ID.
string$filenameFilename for the current file.
Returns
string Archive filename (null if archive not set; false if no current file or error).

Definition at line 53 of file File.php.

◆ archives()

archives (   $type,
  $id,
  $time = null 
)

Find archive files.

Parameters
string$typeFile type.
string$idFile ID.
int$timeOnly select files older than this timestamp (empty = no filter).
Returns
array Archive files found (null if archive not set).

Definition at line 120 of file File.php.

◆ delete()

delete (   $type,
  $id 
)

Delete a file (archive first).

Parameters
string$typeFile type.
string$idFile ID.
Returns
bool True if file does not exist afterwards.

Definition at line 87 of file File.php.

◆ exists()

exists (   $type,
  $id 
)

Check if a file exists.

Parameters
string$typeFile type.
string$idFile ID.
Returns
bool True if the file exists.

Definition at line 43 of file File.php.

◆ find()

find (   $dir,
  $dirs,
  $time = null 
)
protected

Find archive files in a directory.

Parameters
string$dirDirectory to scan.
array$dirsDirectory filters for sub-directories.
int$timeOnly select files older than this timestamp (empty = no filter).
Returns
array Key = full name, value = info

Definition at line 99 of file File.php.

◆ format()

format (   $format,
  $id,
  $index = null,
  $time = null 
)
protected

Definition at line 23 of file File.php.

◆ name()

name (   $type,
  $id 
)

Filename for a file.

Parameters
string$typeFile type.
string$idFile ID.
Returns
string Filename.

Definition at line 34 of file File.php.

◆ purge()

purge (   $type,
  $time 
)

Purge the archive.

Parameters
string$typeFile type.
int$timePurge files older than this timestamp.
Returns
int Number if files purged (null if archive not set).

Definition at line 143 of file File.php.

◆ purgeAll()

purgeAll ( )

Purge archive for all types with an optional "purge" parameter.

Returns
int Number if files purged.

Definition at line 153 of file File.php.

◆ save()

save (   $type,
  $id,
  $data 
)

Save date into a file (archive existing file first).

Parameters
string$typeFile type.
string$idFile ID.
string$dataData to save.
Returns
int Number of bytes written or false on error.

Definition at line 74 of file File.php.

Field Documentation

◆ $_indexBase

$_indexBase = 1
protected

Index starting value.

Definition at line 16 of file File.php.

◆ $_indexSize

$_indexSize = 0
protected

Minimum index length (prefixed with zeros when smaller).

Definition at line 17 of file File.php.

◆ $_types

$_types = []
protected

Key = type name, value = array with 'format' and optional 'archive' format. An asterisk is.

Definition at line 18 of file File.php.

◆ $mode

$mode = null

File mode (not set if empty).

Definition at line 14 of file File.php.

◆ EVENT_ARCHIVE

const EVENT_ARCHIVE = 'file:archive'

Definition at line 10 of file File.php.

◆ EVENT_DELETE

const EVENT_DELETE = 'file:delete'

Definition at line 12 of file File.php.

◆ EVENT_SAVE

const EVENT_SAVE = 'file:save'

Definition at line 11 of file File.php.


The documentation for this class was generated from the following file: