PHP Class Ouzo\Utilities\Files

Exibir arquivo Open project: letsdrink/ouzo Class Usage Examples

Public Methods

Method Description
convertUnitFileSize ( integer $size ) : string Converts file size in bytes to a string with unit.
copyContent ( string $inputFile, string $outputFile, integer $bufferSize = 1024 ) Copies content from $inputFile to $outputFile.
delete ( string $path ) : boolean Deletes file, throws FileNotFoundException if the file does not exist.
deleteIfExists ( $path ) : boolean Deletes file if exists, otherwise return false if the file does not exist.
exists ( string $path ) : boolean Checks if the given file exists.
getFilesRecursivelyWithSpecifiedExtension ( string $dir, string $extension ) : array Returns all files from the given directory that have the given extension.
load ( string $path, boolean $loadOnce = true ) Loads a file using require or require_once if the $loadOnce flag is set to true, if the file does not exist, throws FileNotFoundException.
loadIfExists ( string $path, boolean $loadOnce = true ) : boolean Loads a file using require or require_once if the $loadOnce flag is set to true.
mimeType ( string $path ) : string Returns mime type for the given file path.
move ( string $sourcePath, string $destinationPath ) : boolean Moves file from the source to the destination, throws FileNotFoundException if the source directory does not exist.
size ( string $path ) : integer Returns a size of the given file.

Private Methods

Method Description
_require ( $path, $loadOnce )

Method Details

convertUnitFileSize() public static method

Example: $unit = Files::convertUnitFileSize(146432); Result: 143 KB
public static convertUnitFileSize ( integer $size ) : string
$size integer
return string

copyContent() public static method

Copies content from $inputFile to $outputFile.
public static copyContent ( string $inputFile, string $outputFile, integer $bufferSize = 1024 )
$inputFile string
$outputFile string
$bufferSize integer

delete() public static method

Deletes file, throws FileNotFoundException if the file does not exist.
public static delete ( string $path ) : boolean
$path string
return boolean

deleteIfExists() public static method

Deletes file if exists, otherwise return false if the file does not exist.
public static deleteIfExists ( $path ) : boolean
$path
return boolean

exists() public static method

Checks if the given file exists.
public static exists ( string $path ) : boolean
$path string
return boolean

getFilesRecursivelyWithSpecifiedExtension() public static method

Returns all files from the given directory that have the given extension.
public static getFilesRecursivelyWithSpecifiedExtension ( string $dir, string $extension ) : array
$dir string
$extension string
return array

load() public static method

Loads a file using require or require_once if the $loadOnce flag is set to true, if the file does not exist, throws FileNotFoundException.
public static load ( string $path, boolean $loadOnce = true )
$path string
$loadOnce boolean

loadIfExists() public static method

Loads a file using require or require_once if the $loadOnce flag is set to true.
public static loadIfExists ( string $path, boolean $loadOnce = true ) : boolean
$path string
$loadOnce boolean
return boolean

mimeType() public static method

Returns mime type for the given file path.
public static mimeType ( string $path ) : string
$path string
return string

move() public static method

Moves file from the source to the destination, throws FileNotFoundException if the source directory does not exist.
public static move ( string $sourcePath, string $destinationPath ) : boolean
$sourcePath string
$destinationPath string
return boolean

size() public static method

Returns a size of the given file.
public static size ( string $path ) : integer
$path string
return integer