AloFramework documentation
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo

Namespaces

  • Alo
    • Cache
    • CLI
    • Controller
    • Db
    • Exception
    • FileSystem
    • Session
    • Validators
    • Windows
  • Controller
  • None
  • PHP

Classes

  • AbstractFileSystem
  • File

Class File

Object-oriented file handler

Alo\FileSystem\AbstractFileSystem
Extended byAlo\FileSystem\File
Namespace:Alo\FileSystem
Author:Arturas Molcanovas <a.molcanovas@gmail.com>
Located atsys/class/alo/filesystem/file.php

Methods summary

public
#__construct( )

Instantiates the class

Instantiates the class

Author

Art <a.molcanovas@gmail.com>

Overrides

Alo\FileSystem\AbstractFileSystem::__construct
public staticAlo\FileSystem\File
#file( )

Instantiates the class

Instantiates the class

Returns

Alo\FileSystem\File

Author

Art <a.molcanovas@gmail.com>
public static string
#convertSize(integer$size)

Converts a filesize for display

Converts a filesize for display

Parameters

$size
integer
$size The file size in bytes

Returns

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

Author

Art <a.molcanovas@gmail.com>
public boolean
#append( )

Appends the file contents on the disc

Appends the file contents on the disc

Returns

boolean

Throws

Alo\Exception\FileSystemException
When fopen fails

Author

Art <a.molcanovas@gmail.com>
protectedAlo\FileSystem\File
#doWrite(string$mode)

Performs a write operation

Performs a write operation

Parameters

$mode
string
$mode The write mode - see class constants

Returns

Alo\FileSystem\File

Throws

Alo\Exception\FileSystemException
When fopen fails

Author

Art <a.molcanovas@gmail.com>
protectedAlo\FileSystem\File
#checkParams( )

Checks if the dir and name are set

Checks if the dir and name are set

Returns

Alo\FileSystem\File

Throws

Alo\Exception\FileSystemException
When the file path is not set

Author

Art <a.molcanovas@gmail.com>
public string
#getExtension(integer$depth=1,boolean$onlyThatMember=false)

Gets the file extension based on the currently set filename

Gets the file extension based on the currently set filename

Parameters

$depth
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
$onlyThatMember
boolean
$onlyThatMember Only effective if $depth > 1. If FALSE and the extension is tar.gz, will return "tar.gz", if TRUE, will return "tar".

Returns

string

Author

Art <a.molcanovas@gmail.com>

Uses

self::get_extension()
public static string
#getExtensionStatically(string$filename,integer$depth=1,boolean$onlyThatMember=false)

Gets the file extension based on name

Gets the file extension based on name

Parameters

$filename
string
$filename The file name
$depth
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
$onlyThatMember
boolean
$onlyThatMember Only effective if $depth > 1. If FALSE and the extension is tar.gz, will return "tar.gz", if TRUE, will return "tar".

Returns

string

Author

Art <a.molcanovas@gmail.com>
public boolean
#delete( )

Alias for self::unlink()

Alias for self::unlink()

Returns

boolean

Author

Art <a.molcanovas@gmail.com>

Uses

Alo\FileSystem\File::unlink()
public boolean
#unlink( )

Deletes the file

Deletes the file

Returns

boolean

Throws

Alo\Exception\FileSystemException
When the file path is not set

Author

Art <a.molcanovas@gmail.com>

Used by

Alo\FileSystem\File::delete()
public boolean
#gzipContent(integer$level=9)

Gzip-encodes the fetched content

Gzip-encodes the fetched content

Parameters

$level
integer
$level Compression strength (0-9)

Returns

boolean

Throws

Alo\Exception\FileSystemException
When the file doesn't exist

Author

Art <a.molcanovas@gmail.com>
public boolean
#fileExists( )

Checks whether the file exists at the set path

Checks whether the file exists at the set path

Returns

boolean

Throws

Alo\Exception\FileSystemException
When the file path is not set

Author

Art <a.molcanovas@gmail.com>
public boolean
#read( )

Reads the file contents into $this->content

Reads the file contents into $this->content

Returns

boolean

Throws

Alo\Exception\FileSystemException
When the file doesn't exist

Author

Art <a.molcanovas@gmail.com>
public boolean
#ungzipContent( )

Gzip-decodes the fetched content

Gzip-decodes the fetched content

Returns

boolean

Throws

Alo\Exception\FileSystemException
When the file doesn't exist

Author

Art <a.molcanovas@gmail.com>
publicAlo\FileSystem\File
#write( )

Overwrites the file contents on the disc

Overwrites the file contents on the disc

Returns

Alo\FileSystem\File

Throws

Alo\Exception\FileSystemException
When the file path is not set

Author

Art <a.molcanovas@gmail.com>
public string
#__toString( )

Returns a string representation of the object data

Returns a string representation of the object data

Returns

string

Author

Art <a.molcanovas@gmail.com>
public string
#getFilePath( )

Returns the file's path in the system

Returns the file's path in the system

Returns

string

Author

Art <a.molcanovas@gmail.com>
publicAlo\FileSystem\File|string
#name(string$name='')

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

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

Parameters

$name
string
$name The name

Returns

Alo\FileSystem\File|string

Throws

Alo\Exception\FileSystemException
When the name is invalid

Author

Art <a.molcanovas@gmail.com>
protectedAlo\FileSystem\File
#updatePath( )

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

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

Returns

Alo\FileSystem\File

Author

Art <a.molcanovas@gmail.com>
publicAlo\FileSystem\File|string
#dir(string$dir='')

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

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

Parameters

$dir
string
$dir The directory

Returns

Alo\FileSystem\File|string

Throws

Alo\Exception\FileSystemException
When the name is invalid

Author

Art <a.molcanovas@gmail.com>
public array
#scandir( )

Scans the directory for files

Scans the directory for files

Returns

array

Author

Art <a.molcanovas@gmail.com>
publicAlo\FileSystem\File|string
#content(string$content='~none~')

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

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

Parameters

$content
string
$content Content to set

Returns

Alo\FileSystem\File|string

Throws

Alo\Exception\FileSystemException
When content is not scalar

Author

Art <a.molcanovas@gmail.com>
publicAlo\FileSystem\File
#clearContent( )

Clears the file content

Clears the file content

Returns

Alo\FileSystem\File

Author

Art <a.molcanovas@gmail.com>
publicAlo\FileSystem\File
#addContent(string$c)

Appends the file content

Appends the file content

Parameters

$c
string
$c The content

Returns

Alo\FileSystem\File

Author

Art <a.molcanovas@gmail.com>

Methods inherited fromAlo\FileSystem\AbstractFileSystem

replace()

Magic methods summary

Constants summary

stringM_READ_EXISTING_BEGIN'r'
#

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

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

stringM_RW_EXISTING_BEGIN'r+'
#

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

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

stringM_WRITE_TRUNCATE_BEGIN'w'
#

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.

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.

stringM_RW_TRUNCATE_BEGIN'w+'
#

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.

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.

stringM_WRITE_END'a'
#

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

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

stringM_RW_END'a+'
#

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.

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.

stringM_WRITE_NONEXIST_BEGIN'x'
#

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.

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.

stringM_RW_NONEXIST_BEGIN'x+'
#

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

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

See

Alo\FileSystem\File::M_WRITE_NONEXIST_BEGIN
stringM_WRITE_BEGIN'c'
#

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).

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).

See

Alo\FileSystem\File::M_WRITE_NONEXIST_BEGIN
Alo\FileSystem\File::M_WRITE_TRUNCATE_BEGIN
stringM_RW_BEGIN'c+'
#

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

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

See

self::M_WRITE_BEGIN;

Properties summary

protected static boolean$gz
#

Whether GZIP is installed

Whether GZIP is installed

protected string$content
#

The file content

The file content

protected string$name
#

The file name

The file name

protected string$dir
#

The file directory

The file directory

protected string$filepath
#

The full file path. Updates with every setName & setDir

The full file path. Updates with every setName & setDir

See

self::setName()
self::setDir()

Properties inherited fromAlo\FileSystem\AbstractFileSystem

$replace,$this

AloFramework documentation API documentation generated byApiGen 2.8.0