PHP Class f, kirby

Show file Open project: bastianallgeier/kirby Class Usage Examples

Public Methods

Method Description
append ( string $file, mixed $content ) : boolean Appends new content to an existing file
convert ( string $name, string $type = 'jpg' ) : string Convert the filename to a new extension
dirname ( string $file = __FILE__ ) : string Just an alternative for dirname() to stay consistent
extension ( $filename ) : string Gets the extension of a file
filename ( $name ) : string Extracts the filename from a file path
move ( string $old, string $new ) : boolean Moves a file to a new location
name ( $name, boolean $remove_path = false ) : string Extracts the name from a file path or filename without extension
nice_size ( integer $size ) : string Converts an integer size into a human readable format
read ( string $file, mixed $parse = false ) : mixed Reads the content of a file
remove ( string $file ) : boolean Deletes a file
safe_name ( string $string ) : string Sanitize a filename to strip unwanted special characters
size ( string $file, boolean $nice = false ) : mixed Returns the size of a file.
write ( string $file, mixed $content, boolean $append = false ) : boolean Creates a new file

Method Details

append() static public method

Appends new content to an existing file
static public append ( string $file, mixed $content ) : boolean
$file string The path for the file
$content mixed Either a string or an array. Arrays will be converted to JSON.
return boolean

convert() static public method

Convert the filename to a new extension
static public convert ( string $name, string $type = 'jpg' ) : string
$name string The file name
$type string The new extension
return string

dirname() static public method

Just an alternative for dirname() to stay consistent
static public dirname ( string $file = __FILE__ ) : string
$file string The path
return string

extension() static public method

Gets the extension of a file
static public extension ( $filename ) : string
return string

filename() static public method

Extracts the filename from a file path
static public filename ( $name ) : string
return string

move() static public method

Moves a file to a new location
static public move ( string $old, string $new ) : boolean
$old string The current path for the file
$new string The path to the new location
return boolean

name() static public method

Extracts the name from a file path or filename without extension
static public name ( $name, boolean $remove_path = false ) : string
$remove_path boolean remove the path from the name
return string

nice_size() static public method

Converts an integer size into a human readable format
static public nice_size ( integer $size ) : string
$size integer The file size
return string

read() static public method

Reads the content of a file
static public read ( string $file, mixed $parse = false ) : mixed
$file string The path for the file
$parse mixed if set to true, parse the result with the passed method. See: "str::parse()" for more info about available methods.
return mixed

remove() static public method

Deletes a file
static public remove ( string $file ) : boolean
$file string The path for the file
return boolean

safe_name() static public method

Sanitize a filename to strip unwanted special characters
static public safe_name ( string $string ) : string
$string string The file name
return string

size() static public method

Returns the size of a file.
static public size ( string $file, boolean $nice = false ) : mixed
$file string The path
$nice boolean True: return the size in a human readable format
return mixed

write() static public method

Creates a new file
static public write ( string $file, mixed $content, boolean $append = false ) : boolean
$file string The path for the new file
$content mixed Either a string or an array. Arrays will be converted to JSON.
$append boolean true: append the content to an exisiting file if available. false: overwrite.
return boolean