PHP Class Airship\Cabin\Bridge\Blueprint\Files

Manage user-provided files.
Inheritance: extends BlueprintGear
Show file Open project: paragonie/airship Class Usage Examples

Protected Properties

Property Type Description
$finfo finfo

Public Methods

Method Description
__construct ( Database $db ) Files constructor.
createDirectory ( integer | null $parent = null, string $cabin = '', string $dirName = '' ) : boolean Create a new directory
deleteDir ( string $cabin, string $root, string $subdirectory ) : boolean Delete a directory
deleteFile ( array $fileInfo ) : boolean Delete a file
dirExists ( null $parent = null, string $cabin = '', string $dirName = '' ) : boolean Does the directory already exist?
ensureDirExists ( string $absolutePath, string $cabin = 'Hull' ) : boolean Programmatically ensure that the directory exists.
getChildrenOf ( mixed $directoryId = null, string $cabin = '' ) : array Get all of the directories beneath the current one
getContentsTree ( string $cabin, string $base, string $thisDir ) : array Get the contents of a given cabin/directory, recursively
getDirectoryCabin ( integer $directoryId ) : string Given a directory ID, get its cabin.
getDirectoryId ( array $parts, string $cabin ) : integer Get a directory ID, should it exist.
getDirectoryTree ( string $cabin = '', string $rootDir = '', string $ignore = '', string $pieces = '' ) : array Build a recursive directory tree
getFileInfo ( string $cabin = '', array $path = null, string $filename = '' ) : array Get detailed file information
getFilesCabin ( integer $fileId ) : string Given a file ID, get its Cabin
getFilesInDirectory ( null $directoryId = null, string $cabin = '' ) : array Get all of the directories beneath the current one
getMimeType ( string $filePath ) : string Get the MIME type for a given file.
isValidName ( string $name ) : boolean Does this file have a valid filename?
isolateFiles ( array $files = [] ) : array Turn PHP's native $_FILES mess into a sane array
moveDir ( string $cabin, string $root, string $subdirectory, array $post = [] ) : boolean Move/rename a directory
moveFile ( array $fileInfo, array $post, string $cabin ) : boolean Move/rename a file
processUpload ( integer | null $directoryId = null, string $cabin = '', array $file = [], array $attribution = [] ) : array Process an upload. Either it returns an array with useful data, OR it throws an UploadError

Protected Methods

Method Description
getContentsIterative ( integer $parent, string $path, string $cabin ) : array Get a list of all the files in a directory.
getUniqueFileName ( string $name, string $ext, integer | null $directoryId = null, string $cabin = '' ) : string Get a string that doesn't get exist in the DB

Private Methods

Method Description
moveUploadedFile ( string $tmp_name ) : string This method is private to avoid it from being accessed outside of the trusted methods (which handle validation). Don't change it.
recursiveDelete ( integer $directory, string $cabin ) : boolean Recursively delete everything in a specific directory

Method Details

__construct() public method

Files constructor.
public __construct ( Database $db )
$db Database

createDirectory() public method

Create a new directory
public createDirectory ( integer | null $parent = null, string $cabin = '', string $dirName = '' ) : boolean
$parent integer | null
$cabin string
$dirName string
return boolean

deleteDir() public method

Delete a directory
public deleteDir ( string $cabin, string $root, string $subdirectory ) : boolean
$cabin string
$root string
$subdirectory string
return boolean

deleteFile() public method

Delete a file
public deleteFile ( array $fileInfo ) : boolean
$fileInfo array
return boolean

dirExists() public method

Does the directory already exist?
public dirExists ( null $parent = null, string $cabin = '', string $dirName = '' ) : boolean
$parent null
$cabin string
$dirName string
return boolean

ensureDirExists() public method

Programmatically ensure that the directory exists.
public ensureDirExists ( string $absolutePath, string $cabin = 'Hull' ) : boolean
$absolutePath string
$cabin string
return boolean

getChildrenOf() public method

Get all of the directories beneath the current one
public getChildrenOf ( mixed $directoryId = null, string $cabin = '' ) : array
$directoryId mixed (usually an integer, sometimes null)
$cabin string
return array

getContentsIterative() protected method

Get a list of all the files in a directory.
protected getContentsIterative ( integer $parent, string $path, string $cabin ) : array
$parent integer
$path string
$cabin string
return array

getContentsTree() public method

Get the contents of a given cabin/directory, recursively
public getContentsTree ( string $cabin, string $base, string $thisDir ) : array
$cabin string
$base string
$thisDir string
return array

getDirectoryCabin() public method

Given a directory ID, get its cabin.
public getDirectoryCabin ( integer $directoryId ) : string
$directoryId integer
return string

getDirectoryId() public method

Get a directory ID, should it exist.
public getDirectoryId ( array $parts, string $cabin ) : integer
$parts array
$cabin string
return integer

getDirectoryTree() public method

Build a recursive directory tree
public getDirectoryTree ( string $cabin = '', string $rootDir = '', string $ignore = '', string $pieces = '' ) : array
$cabin string
$rootDir string
$ignore string
$pieces string
return array

getFileInfo() public method

Get detailed file information
public getFileInfo ( string $cabin = '', array $path = null, string $filename = '' ) : array
$cabin string
$path array
$filename string
return array

getFilesCabin() public method

Given a file ID, get its Cabin
public getFilesCabin ( integer $fileId ) : string
$fileId integer
return string

getFilesInDirectory() public method

Get all of the directories beneath the current one
public getFilesInDirectory ( null $directoryId = null, string $cabin = '' ) : array
$directoryId null
$cabin string
return array

getMimeType() public method

Get the MIME type for a given file.
public getMimeType ( string $filePath ) : string
$filePath string
return string

getUniqueFileName() protected method

Get a string that doesn't get exist in the DB
protected getUniqueFileName ( string $name, string $ext, integer | null $directoryId = null, string $cabin = '' ) : string
$name string
$ext string
$directoryId integer | null
$cabin string
return string

isValidName() public method

Does this file have a valid filename?
public isValidName ( string $name ) : boolean
$name string
return boolean

isolateFiles() public method

USAGE: $result = $this->isolateFiles($_FILES['some_index']);
public isolateFiles ( array $files = [] ) : array
$files array
return array

moveDir() public method

Move/rename a directory
public moveDir ( string $cabin, string $root, string $subdirectory, array $post = [] ) : boolean
$cabin string
$root string
$subdirectory string
$post array
return boolean

moveFile() public method

Move/rename a file
public moveFile ( array $fileInfo, array $post, string $cabin ) : boolean
$fileInfo array
$post array
$cabin string
return boolean

processUpload() public method

Process an upload. Either it returns an array with useful data, OR it throws an UploadError
public processUpload ( integer | null $directoryId = null, string $cabin = '', array $file = [], array $attribution = [] ) : array
$directoryId integer | null
$cabin string
$file array
$attribution array Who uploaded it?
return array

Property Details

$finfo protected property

protected finfo $finfo
return finfo