Constants

M_READ_EXISTING_BEGIN

M_READ_EXISTING_BEGIN

Open for reading only; place the file pointer at the beginning of the file.

M_RW_EXISTING_BEGIN

M_RW_EXISTING_BEGIN

Open for reading and writing; place the file pointer at the beginning of the file.

M_WRITE_TRUNCATE_BEGIN

M_WRITE_TRUNCATE_BEGIN

Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.

M_RW_TRUNCATE_BEGIN

M_RW_TRUNCATE_BEGIN

Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.

M_WRITE_END

M_WRITE_END

Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.

M_RW_END

M_RW_END

Open for reading and writing; place the file pointer at the end of the file.

If the file does not exist, attempt to create it.

M_WRITE_NONEXIST_BEGIN

M_WRITE_NONEXIST_BEGIN

Create and open for writing only; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call.

M_RW_NONEXIST_BEGIN

M_RW_NONEXIST_BEGIN

Create and open for reading and writing; otherwise it has the same behavior as M_WRITE_NONEXIST_BEGIN

M_WRITE_BEGIN

M_WRITE_BEGIN

Open the file for writing only. If the file does not exist, it is created.

If it exists, it is neither truncated (as opposed to M_WRITE_TRUNCATE_BEGIN), nor the call to this function fails (as is the case with M_WRITE_NONEXIST_BEGIN). The file pointer is positioned on the beginning of the file. This may be useful if it's desired to get an advisory lock (see flock()) before attempting to modify the file, as using M_WRITE_NONEXIST_BEGIN could truncate the file before the lock was obtained (if truncation is desired, ftruncate() can be used after the lock is requested).

M_RW_BEGIN

M_RW_BEGIN

Open the file for reading and writing; otherwise it has the same behavior as M_WRITE_BEGIN.

Properties

$content

$content : string

The file content

Type

string

$name

$name : string

The file name

Type

string

$dir

$dir : string

The file directory

Type

string

$replace

$replace : array

Replacements for placeholders

Type

array

$filepath

$filepath : string

The full file path. Updates with every setName & setDir

Type

string

$gz

$gz : boolean

Whether GZIP is installed

Type

boolean

Methods

__construct()

__construct() 

Instantiates the class

convert_size()

convert_size(integer  $size) : string

Converts a filesize for display

Parameters

integer $size

The file size in bytes

Returns

string —

The file size in its largest form, e.g. 1024 bytes become 1KB;

append()

append() : boolean

Appends the file contents on the disc

Returns

boolean

get_extension()

get_extension(string  $filename, integer  $depth = 1, boolean  $only_that_member = false) : string

Gets the file extension based on name

Parameters

string $filename

The file name

integer $depth

The depth to search for, e.g. if the file name is foo.tar.gz, depth=1 would return "gz" while depth=2 would return .tar.gz

boolean $only_that_member

Only effective if $depth > 1. If FALSE and the extension is tar.gz, will return "tar.gz", if TRUE, will return "tar".

Returns

string

getExtension()

getExtension(integer  $depth = 1, boolean  $only_that_member = false) : string

Gets the file extension based on the currently set filename

Parameters

integer $depth

The depth to search for, e.g. if the file name is foo.tar.gz, depth=1 would return "gz" while depth=2 would return .tar.gz

boolean $only_that_member

Only effective if $depth > 1. If FALSE and the extension is tar.gz, will return "tar.gz", if TRUE, will return "tar".

Returns

string

delete()

delete() : boolean

Alias for self::unlink()

Returns

boolean

unlink()

unlink() : boolean

Deletes the file

Returns

boolean

fileExists()

fileExists() : boolean

Checks whether the file exists at the set path

Returns

boolean

gzipContent()

gzipContent(integer  $level = 9) : boolean

Gzip-encodes the fetched content

Parameters

integer $level

Compression strength (0-9)

Returns

boolean

ungzipContent()

ungzipContent() : boolean

Gzip-decodes the fetched content

Returns

boolean

write()

write() : \Alo\File

Overwrites the file contents on the disc

Returns

\Alo\File

read()

read() : boolean

Reads the file contents into $this->content

Throws

\Alo\Exception\FileException

When the file doesn't exist

Returns

boolean

__toString()

__toString() : string

Returns a string representation of the object data

Returns

string

getFilePath()

getFilePath() : string

Returns the file's path in the system

Returns

string

name()

name(string  $name = '') : \Alo\File|string

If no argument is passed, gets the file name, otherwise sets it

Parameters

string $name

The name

Throws

\Alo\Exception\FileException

When the name is invalid

Returns

\Alo\File|string

dir()

dir(string  $dir = '') : \Alo\File|string

If no argument is passed, gets the directory name, otherwise sets it

Parameters

string $dir

The directory

Throws

\Alo\Exception\FileException

When the name is invalid

Returns

\Alo\File|string

scandir()

scandir() : array

Scans the directory for files

Returns

array

content()

content(string  $content = '~none~') : \Alo\File|string

If no argument is passed, gets the currently set content, otherwise sets it

Parameters

string $content

Content to set

Throws

\Alo\Exception\FileException

When content is not scalar

Returns

\Alo\File|string

clearContent()

clearContent() : \Alo\File

Clears the file content

Returns

\Alo\File

addContent()

addContent(string  $c) : \Alo\File

Appends the file content

Parameters

string $c

The content

Returns

\Alo\File

replace()

replace(string  $subject) 

Perform placeholder replacement operations

Parameters

string $subject

The string to perform operations in

doWrite()

doWrite(string  $mode) : \Alo\File

Performs a write operation

Parameters

string $mode

The write mode - see class constants

Throws

\Alo\Exception\FileException

When fopen fails

Returns

\Alo\File

checkParams()

checkParams() : \Alo\File

Checks if the dir and name are set

Throws

\Alo\Exception\FileException

When the file path is not set

Returns

\Alo\File

updatePath()

updatePath() : \Alo\File

Updates the file path when the directory or file name are changed

Returns

\Alo\File