PHP Class luya\helpers\FileHelper

Author: Basil Suter ([email protected])
Inheritance: extends yii\helpers\BaseFileHelper
Show file Open project: zephir/luya Class Usage Examples

Public Methods

Method Description
ensureExtension ( string $file, string $extension ) : the Append a file extension to a path/file if there is no or an empty extension provided, this helper methods is used to make sure the right extension existing on files.
getFileContent ( string $fileName ) : string | boolean Basic helper to retreive the content of a file and catched exception. The filename will auto alias encode by Yii::getAlias function.
getFileHash ( string $sourceFile ) : false | string Generate a md5 hash of a file. This is eqauls to md5sum command
getFileInfo ( string $sourceFile ) : object Get extension and name from a file for the provided source/path of the file.
humanReadableFilesize ( integer $size ) : string Generate a human readable size informations from provided Byte/s size
writeFile ( string $fileName, string $content ) : boolean Basic helper method to write files with exception capture. The fileName will auto wrapped trough the Yii::getAlias function.

Method Details

ensureExtension() public static method

Append a file extension to a path/file if there is no or an empty extension provided, this helper methods is used to make sure the right extension existing on files.
public static ensureExtension ( string $file, string $extension ) : the
$file string The file where extension should be append if not existing
$extension string
return the ensured file/path with extension

getFileContent() public static method

Basic helper to retreive the content of a file and catched exception. The filename will auto alias encode by Yii::getAlias function.
Since: 1.0.0-beta7
public static getFileContent ( string $fileName ) : string | boolean
$fileName string The path to the file to get the content
return string | boolean

getFileHash() public static method

Generate a md5 hash of a file. This is eqauls to md5sum command
public static getFileHash ( string $sourceFile ) : false | string
$sourceFile string The path to the file
return false | string Returns false or the md5 hash of this file

getFileInfo() public static method

Get extension and name from a file for the provided source/path of the file.
public static getFileInfo ( string $sourceFile ) : object
$sourceFile string The path of the file
return object With extension and name keys.

humanReadableFilesize() public static method

Generate a human readable size informations from provided Byte/s size
public static humanReadableFilesize ( integer $size ) : string
$size integer The size to convert in Byte
return string The readable size definition

writeFile() public static method

Basic helper method to write files with exception capture. The fileName will auto wrapped trough the Yii::getAlias function.
public static writeFile ( string $fileName, string $content ) : boolean
$fileName string The path to the file with file name
$content string The content to store in this File
return boolean