FileManager
in package
implements
IFileManager
Tool for reading and writing text files
Table of Contents
Interfaces
- IFileManager
- File manager interface
Properties
- $commandExecutor : CommandExecutor
- $directory : string
Methods
- __construct() : mixed
- Constructor
- chmod() : void
- Changes the permissions of a file or directory
- 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
- 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
- fixPermissions() : void
- Fixes the permissions
- getRealPath() : string
- Returns the real path
Properties
$commandExecutor read-only
private
CommandExecutor
$commandExecutor
$directory read-only
private
string
$directory
Methods
__construct()
Constructor
public
__construct(string $directory, CommandExecutor $commandExecutor) : mixed
Parameters
- $directory : string
-
Directory with files
- $commandExecutor : CommandExecutor
-
Command executor
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
createSymLink()
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
isSymLink()
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
write()
Writes into the file
public
write(string $fileName, mixed $content) : void
Parameters
- $fileName : string
-
File name
- $content : mixed
-
File content
writeIni()
Encodes content from array into INI and writes to file
public
writeIni(string $fileName, array<string|int, mixed> $content) : void
Parameters
- $fileName : string
-
File name
- $content : array<string|int, mixed>
-
Array to encode
writeJson()
Encodes content from array into JSON and writes to file
public
writeJson(string $fileName, mixed $content) : void
Parameters
- $fileName : string
-
File name
- $content : mixed
-
JSON data to encode
writeNeon()
Encodes content from array into NEON and writes to file
public
writeNeon(string $fileName, mixed $content) : void
Parameters
- $fileName : string
-
File name
- $content : mixed
-
NEON data to encode
fixPermissions()
Fixes the permissions
private
fixPermissions(string $fileName) : void
Parameters
- $fileName : string
-
File name
getRealPath()
Returns the real path
private
getRealPath([string|null $subdirectory = null ]) : string
Parameters
- $subdirectory : string|null = null
-
Relative path to subdirectory
Tags
Return values
string —Real path