File
File
Properties
source_file
public string $source_file
default_cipher
public string $default_cipher = 'aes-256-ctr'
default_key
public string $default_key = 'hazaar_secret_badass_key'
manager
protected Manager $manager
info
protected array $info
mimeContentType
public string $mimeContentType
contents
Any overridden file contents.
protected string $contents
This is normally used when performing operations on the file in memory, such as resizing an image.
csv_contents
public array $csv_contents
resource
protected mixed $resource
relative_path
public string $relative_path
stream
private mixed $stream
encrypted
private bool $encrypted
__media_url
public URL $__media_url
filters
Content filters.
private array $filters
Methods
__construct
public __construct(mixed $file, ?Manager $manager, ?string $relative_path): void
Parameters
Parameter | Type | Description |
---|---|---|
$file | mixed | |
$manager | Manager | |
$relative_path | string |
__toString
public __toString(): string
backend
public backend(): string
getManager
public getManager(): Manager
get
public get(string $url, ?Client $client): File
Parameters
Parameter | Type | Description |
---|---|---|
$url | string | |
$client | Client |
registerFilter
Content filters.
public registerFilter(int $type, string $callable): bool
Parameters
Parameter | Type | Description |
---|---|---|
$type | int | |
$callable | string |
setMeta
public setMeta(array $values): bool
Parameters
Parameter | Type | Description |
---|---|---|
$values | array |
getMeta
public getMeta(?string $key): mixed
Parameters
Parameter | Type | Description |
---|---|---|
$key | string |
toString
public toString(): string
basename
public basename(string $suffix = ''): string
Parameters
Parameter | Type | Description |
---|---|---|
$suffix | string |
dirname
public dirname(): string
name
public name(): string
fullpath
public fullpath(): string
relativepath
Get the relative path of the file.
public relativepath(NULL $path): void
If the file was returned from a Hazaar\File\Dir object, then it will have a stored relative path. Otherwise any file/path can be provided in the form of another Hazaar\File object, Hazaar\File\Dir object, or string path, and the relative path to the file will be returned.
Parameters
Parameter | Type | Description |
---|---|---|
$path | NULL | optional path to use as the relative path |
setRelativePath
public setRelativePath(string $path): void
Parameters
Parameter | Type | Description |
---|---|---|
$path | string |
extension
public extension(): string
size
public size(): ?int
exists
public exists(): bool
realpath
public realpath(): string
isReadable
public isReadable(): bool
isWritable
public isWritable(): bool
isFile
public isFile(): bool
isDir
public isDir(): bool
isLink
public isLink(): bool
dir
public dir(): ?Dir
parent
public parent(): Dir
type
public type(): ?string
ctime
public ctime(): ?int
mtime
public mtime(): ?int
touch
public touch(): bool
atime
public atime(): ?int
hasContents
public hasContents(): bool
getContents
Returns the current contents of the file.
public getContents(int $offset = -1, ?int $maxlen): string
Parameters
Parameter | Type | Description |
---|---|---|
$offset | int | |
$maxlen | int |
putContents
Put contents directly writes data to the storage backend without storing it in the file object itself.
public putContents(string $data, bool $overwrite = true): ?int
NOTE: This function is called internally to save data that has been updated in the file object.
Parameters
Parameter | Type | Description |
---|---|---|
$data | string | The data to write |
$overwrite | bool | Overwrite data if it exists |
setContents
Sets the current contents of the file in memory.
public setContents(?string $bytes): ?int
Calling this function does not directly update the content of the file "on disk". To do that you must call the File::save() method which will commit the data to storage.
Parameters
Parameter | Type | Description |
---|---|---|
$bytes | string | The data to set as the content |
setDecodedContents
Set the contents from an encoded string.
public setDecodedContents(string $bytes): bool
Currently this supports only data URI encoded strings. I have made this generic in case I come across other types of encodings that will work with this method.
Parameters
Parameter | Type | Description |
---|---|---|
$bytes | string |
getEncodedContents
Return the contents of the file as a data URI encoded string.
public getEncodedContents(): void
This function is basically the opposite of Hazaar\File::set_decoded_contents() and will generate a data URI based on the current MIME content type and the contents of the file.
save
Saves the current in-memory content to the storage backend.
public save(): ?int
Internally this calls File::putContents() to write the data to the backend.
saveAs
Saves this file objects content to another file name.
public saveAs(string $filename, bool $overwrite = false): ?int
Parameters
Parameter | Type | Description |
---|---|---|
$filename | string | The filename to save as |
$overwrite | bool | Boolean flag to indicate that the destination should be overwritten if it exists |
unlink
Deletes the file from storage.
public unlink(): bool
md5
Generate an MD5 checksum of the current file content.
public md5(): string
base64
Return the base64 encoded content.
public base64(): string
parseJSON
Returns the contents as decoded JSON.
public parseJSON(bool $assoc = false, \stdClass $): void
If the content is a JSON encoded string, this will decode the string and return it as a stdClass object, or an associative array if the $assoc parameter is TRUE.
If the content can not be decoded because it is not a valid JSON string, this method will return FALSE.
Parameters
Parameter | Type | Description |
---|---|---|
$assoc | bool | Return as an associative array. Default is to use stdClass. |
$ | \stdClass |
moveTo
public moveTo(string $destination, bool $overwrite = false, bool $create_dest = false, ?Manager $dstManager): File
Parameters
Parameter | Type | Description |
---|---|---|
$destination | string | |
$overwrite | bool | |
$create_dest | bool | |
$dstManager | Manager |
copyTo
Copy the file to another folder.
public copyTo(string $destination, bool $overwrite = false, bool $create_dest = false, ?Manager $dstManager): File
This differs to copy() which expects the target to be the full new file pathname.
Parameters
Parameter | Type | Description |
---|---|---|
$destination | string | The destination folder to copy the file into |
$overwrite | bool | overwrite the destination file if it exists |
$create_dest | bool | Flag that indicates if the destination folder should be created. If the destination does not exist an error will be thrown. |
$dstManager | Manager | The destination file manager. Defaults to the same manager as the source. |
copy
Copy the file to another folder and filename.
public copy(string $destination, boolean $overwrite = false, boolean $create_dest = false, NULL $dstManager): File
This differs from copyTo which expects the target to be a folder
Parameters
Parameter | Type | Description |
---|---|---|
$destination | string | The destination folder and file name to copy the file into |
$overwrite | boolean | overwrite the destination file if it exists |
$create_dest | boolean | Flag that indicates if the destination folder should be created. If the destination does not exist an error will be thrown. |
$dstManager | NULL | The destination file manager. Defaults to the same manager as the source. |
mimeContentType
public mimeContentType(): ?string
setMimeContentType
public setMimeContentType(string $type): void
Parameters
Parameter | Type | Description |
---|---|---|
$type | string |
thumbnailURL
public thumbnailURL(int $width = 100, int $height = 100, string $format = 'jpeg', array $params = []): ?string
Parameters
Parameter | Type | Description |
---|---|---|
$width | int | |
$height | int | |
$format | string | |
$params | array |
previewURL
public previewURL(array $params = []): ?string
Parameters
Parameter | Type | Description |
---|---|---|
$params | array |
directURL
public directURL(): ?string
mediaURL
public mediaURL(URL $set_path): URL
Parameters
Parameter | Type | Description |
---|---|---|
$set_path | URL |
toArray
public toArray(string $delimiter = '"\n"'): void
Parameters
Parameter | Type | Description |
---|---|---|
$delimiter | string |
readCSV
Return the CSV content as a parsed array.
public readCSV(bool $use_header_row = false): void
Parameters
Parameter | Type | Description |
---|---|---|
$use_header_row | bool | Indicates if a header row should be parsed and used to build an associative array. In this case the keys in the returned array will be the values from the first row, which is normally a header row. |
getcsv
Returns a line from the file pointer and parse for CSV fields.
public getcsv(int $length = 0, string $delimiter = ',', string $enclosure = '"', string $escape = '\\'): void
Parameters
Parameter | Type | Description |
---|---|---|
$length | int | Must be greater than the longest line (in characters) to be found in the CSV file (allowing for trailing line-end characters). Otherwise the line is split in chunks of length characters, unless the split would occur inside an enclosure. Omitting this parameter (or setting it to 0 in PHP 5.1.0 and later) the maximum line length is not limited, which is slightly slower. |
$delimiter | string | the optional delimiter parameter sets the field delimiter (one character only) |
$enclosure | string | the optional enclosure parameter sets the field enclosure character (one character only) |
$escape | string | the optional escape parameter sets the escape character (one character only) |
putcsv
Writes an array to the file in CSV format.
public putcsv(array $fields, string $delimiter = ',', string $enclosure = '"', string $escape = '\\'): void
Parameters
Parameter | Type | Description |
---|---|---|
$fields | array | Must be greater than the longest line (in characters) to be found in the CSV file (allowing for trailing line-end characters). Otherwise the line is split in chunks of length characters, unless the split would occur inside an enclosure. Omitting this parameter (or setting it to 0 in PHP 5.1.0 and later) the maximum line length is not limited, which is slightly slower. |
$delimiter | string | the optional delimiter parameter sets the field delimiter (one character only) |
$enclosure | string | the optional enclosure parameter sets the field enclosure character (one character only) |
$escape | string | the optional escape parameter sets the escape character (one character only) |
rename
Renames a file or directory.
public rename(string $newname): bool
NOTE: This will not work if the file is currently opened by another process.
Parameters
Parameter | Type | Description |
---|---|---|
$newname | string | The new name. Must not be an absolute/relative path. If you want to move the file use File::moveTo(). |
delete
public delete(string $path): bool
Parameters
Parameter | Type | Description |
---|---|---|
$path | string |
jsonSerialize
public jsonSerialize(): mixed
perms
public perms(): ?int
chmod
public chmod(int $mode): bool
Parameters
Parameter | Type | Description |
---|---|---|
$mode | int |
isEncrypted
Check if a file is encrypted using the built-in Hazaar encryption method.
public isEncrypted(): bool
encrypt
public encrypt(): bool
decrypt
public decrypt(): bool
isOpen
public isOpen(): bool
open
public open(string $mode): mixed
Parameters
Parameter | Type | Description |
---|---|---|
$mode | string |
read
public read(int $length): string
Parameters
Parameter | Type | Description |
---|---|---|
$length | int |
write
public write(string $bytes, int $length): int
Parameters
Parameter | Type | Description |
---|---|---|
$bytes | string | |
$length | int |
seek
public seek(int $offset, int $whence = 'SEEK_SET'): int
Parameters
Parameter | Type | Description |
---|---|---|
$offset | int | |
$whence | int |
tell
public tell(): int
eof
public eof(): bool
truncate
public truncate(int $size): bool
Parameters
Parameter | Type | Description |
---|---|---|
$size | int |
lock
public lock(int $operation, ?int $wouldblock): bool
Parameters
Parameter | Type | Description |
---|---|---|
$operation | int | |
$wouldblock | int |
flush
public flush(): bool
gets
public gets(?int $length): string
Parameters
Parameter | Type | Description |
---|---|---|
$length | int |
close
public close(): bool
filterIn
Internal content filter.
protected filterIn(string $content): bool
Checks if the content is modified in some way using a BOM mask. Currently this is used to determine if a file is encrypted and automatically decrypts it if an encryption key is available.
Parameters
Parameter | Type | Description |
---|---|---|
$content | string |
filterOut
Internal content filter.
protected filterOut(string $content): bool
Checks if the content is modified in some way using a BOM mask. Currently this is used to determine if a file is encrypted and automatically decrypts it if an encryption key is available.
Parameters
Parameter | Type | Description |
---|---|---|
$content | string |
getEncryptionKey
private getEncryptionKey(): string
Generated by Hazaar API Doc Generator