IQRF PHP file manager

FileManager
in package
implements IFileManager

Tool for reading and writing text files

Table of Contents

Interfaces

IFileManager
File manager interface

Properties

$directory  : string

Methods

__construct()  : mixed
Constructor
chmod()  : void
Changes the permissions of a file or directory
createDirectory()  : void
Creates a directory (including missing parent directories)
createSymLink()  : void
Creates the symbolic link
delete()  : void
Deletes the file
exists()  : bool
Checks if the file exists
getBasePath()  : string
Returns Base directory path
isSymLink()  : bool
Checks if the file is symbolic link
listDirectories()  : array<string|int, string>
Returns list of subdirectories in directory
listFiles()  : array<string|int, string>
Returns list of files in directory
read()  : string
Reads the file
readIni()  : array<string, mixed>
Reads an INI file and decodes contents to array
readJson()  : mixed
Reads a JSON file and decode contents to array
readNeon()  : mixed
Reads a NEON file and decodes contents to array
readStream()  : resource
Opens the file for reading as a stream
write()  : void
Writes into the file
writeIni()  : void
Encodes content from array into INI and writes to file
writeJson()  : void
Encodes content from array into JSON and writes to file
writeNeon()  : void
Encodes content from array into NEON and writes to file
writeStream()  : void
Writes a stream into the file
changeMode()  : void
Changes the mode of a file or directory
getExistingMode()  : int|null
Returns the mode of the existing file, which has to be preserved when the file is replaced
getRealPath()  : string
Returns the real path

Properties

Methods

__construct()

Constructor

public __construct(string $directory) : mixed
Parameters
$directory : string

Directory with files

chmod()

Changes the permissions of a file or directory

public chmod(string|null $path, int $mode[, bool $recursive = false ]) : void
Parameters
$path : string|null

Path to the file or directory

$mode : int

File mode

$recursive : bool = false

Indicates whether the mode should be changed recursively

createDirectory()

Creates a directory (including missing parent directories)

public createDirectory(string $directory[, int|null $mode = null ]) : void
Parameters
$directory : string

Relative path to the directory

$mode : int|null = null

Directory mode (permissions) applied to the directory, null to keep the default

Creates the symbolic link

public createSymLink(string $target, string $link) : void
Parameters
$target : string

Target of the symbolic link

$link : string

Symbolic link name

delete()

Deletes the file

public delete(string $fileName) : void
Parameters
$fileName : string

File name

exists()

Checks if the file exists

public exists(string $fileName) : bool
Parameters
$fileName : string

File name

Return values
bool —

Is file exists?

getBasePath()

Returns Base directory path

public getBasePath() : string
Return values
string —

Base directory path

Checks if the file is symbolic link

public isSymLink(string $fileName) : bool
Parameters
$fileName : string

File name

Return values
bool —

Is symbolic link?

listDirectories()

Returns list of subdirectories in directory

public listDirectories([string|null $subdirectory = null ]) : array<string|int, string>
Parameters
$subdirectory : string|null = null

Relative path to subdirectory

Return values
array<string|int, string> —

List of directories

listFiles()

Returns list of files in directory

public listFiles([string|null $subdirectory = null ]) : array<string|int, string>
Parameters
$subdirectory : string|null = null

Relative path to subdirectory

Return values
array<string|int, string> —

List of files

read()

Reads the file

public read(string $fileName) : string
Parameters
$fileName : string

File name

Return values
string —

File content

readIni()

Reads an INI file and decodes contents to array

public readIni(string $fileName) : array<string, mixed>
Parameters
$fileName : string

File name

Return values
array<string, mixed> —

Decoded INI file

readJson()

Reads a JSON file and decode contents to array

public readJson(string $fileName[, bool $forceArray = true ]) : mixed
Parameters
$fileName : string

File name

$forceArray : bool = true

Force object to array conversion

Return values
mixed —

Decoded JSON data

readNeon()

Reads a NEON file and decodes contents to array

public readNeon(string $fileName) : mixed
Parameters
$fileName : string

File name

Return values
mixed —

Decoded NEON file

readStream()

Opens the file for reading as a stream

public readStream(string $fileName) : resource
Parameters
$fileName : string

File name

Return values
resource —

Readable stream, the caller is responsible for closing it

write()

Writes into the file

public write(string $fileName, mixed $content[, int|null $mode = null ]) : void
Parameters
$fileName : string

File name

$content : mixed

File content

$mode : int|null = null

File mode (permissions), null to keep the default

writeIni()

Encodes content from array into INI and writes to file

public writeIni(string $fileName, array<string|int, mixed> $content[, int|null $mode = null ]) : void
Parameters
$fileName : string

File name

$content : array<string|int, mixed>

Array to encode

$mode : int|null = null

File mode (permissions), null to keep the default

writeJson()

Encodes content from array into JSON and writes to file

public writeJson(string $fileName, mixed $content[, int|null $mode = null ]) : void
Parameters
$fileName : string

File name

$content : mixed

JSON data to encode

$mode : int|null = null

File mode (permissions), null to keep the default

writeNeon()

Encodes content from array into NEON and writes to file

public writeNeon(string $fileName, mixed $content[, int|null $mode = null ]) : void
Parameters
$fileName : string

File name

$content : mixed

NEON data to encode

$mode : int|null = null

File mode (permissions), null to keep the default

writeStream()

Writes a stream into the file

public writeStream(string $fileName, mixed $stream[, int|null $mode = null ]) : void
Parameters
$fileName : string

File name

$stream : mixed

Readable stream with the file content, it is not closed

$mode : int|null = null

File mode (permissions), null to keep the default

changeMode()

Changes the mode of a file or directory

private changeMode(string $path, int $mode) : void
Parameters
$path : string

Path to the file or directory

$mode : int

File mode

Tags
throws
IOException

getExistingMode()

Returns the mode of the existing file, which has to be preserved when the file is replaced

private getExistingMode(string $path) : int|null
Parameters
$path : string

Path to the file

Return values
int|null —

File mode, null if the file does not exist

getRealPath()

Returns the real path

private getRealPath([string|null $subdirectory = null ]) : string
Parameters
$subdirectory : string|null = null

Relative path to subdirectory

Tags
throws
IOException

Directory not found

Return values
string —

Real path


        
On this page

Search results