PHP Class Brotzka\DotenvEditor\DotenvEditor

显示文件 Open project: brotzka/laravel-dotenv-editor Class Usage Examples

Public Methods

Method Description
AutoBackupEnabled ( ) : boolean Checks, if Autobackup is enabled
__construct ( ) DotenvEditor constructor
addData ( array $data = [] ) : boolean Add data to the current env file.
changeEnv ( array $data = [] ) : boolean Change the given values of the current env file.
createBackup ( ) : boolean Used to create a backup of the current .env.
deleteBackup ( $timestamp ) Delete the given backup-file
deleteData ( array $data = [] ) : boolean Delete one or more entries from the env file.
getAsJson ( null $timestamp = NULL ) : string Returns the given .env as JSON array containing all entries as object with key and value
getBackupFile ( $timestamp ) : string Returns filename and path for the given timestamp
getBackupPath ( ) : mixed Returns the current backup-path
getBackupVersions ( ) : array Returns an array with all available backups.
getContent ( null $timestamp = NULL ) : array Returns the content of a given backup file or the content of the current env file.
getValue ( $key ) : mixed Returns the value matching to a given key.
keyExists ( $key ) : boolean Checks, if a given key exists in your .env-file.
restoreBackup ( null $timestamp = NULL ) : string Restores the latest backup or a backup from a given timestamp.
setAutoBackup ( $onOff ) Activate or deactivate the AutoBackup-Functionality
setBackupPath ( $path ) : boolean Set a new backup-path.

Protected Methods

Method Description
envToArray ( $file ) : array Writes the content of a env file to an array.
getFile ( $timestamp ) : string Returns the file for the given backup-timestamp
getLatestBackup ( ) : integer | mixed Returns the timestamp of the latest version.
save ( $array ) : boolean Saves the given data to the .env-file

Private Methods

Method Description
envToJson ( array $file = [] ) : string Converts the given .env-array to JSON

Method Details

AutoBackupEnabled() public method

Checks, if Autobackup is enabled
public AutoBackupEnabled ( ) : boolean
return boolean

__construct() public method

DotenvEditor constructor
public __construct ( )

addData() public method

Data will be placed at the end.
public addData ( array $data = [] ) : boolean
$data array
return boolean

changeEnv() public method

If the given key(s) is/are not found, nothing happens.
public changeEnv ( array $data = [] ) : boolean
$data array
return boolean

createBackup() public method

Will be assigned with the current timestamp.
public createBackup ( ) : boolean
return boolean

deleteBackup() public method

Delete the given backup-file
public deleteBackup ( $timestamp )
$timestamp

deleteData() public method

Delete one or more entries from the env file.
public deleteData ( array $data = [] ) : boolean
$data array
return boolean

envToArray() protected method

Writes the content of a env file to an array.
protected envToArray ( $file ) : array
$file
return array

getAsJson() public method

Returns the given .env as JSON array containing all entries as object with key and value
public getAsJson ( null $timestamp = NULL ) : string
$timestamp null
return string

getBackupFile() public method

Returns filename and path for the given timestamp
public getBackupFile ( $timestamp ) : string
$timestamp
return string

getBackupPath() public method

Returns the current backup-path
public getBackupPath ( ) : mixed
return mixed

getBackupVersions() public method

Array contains the formatted and unformatted version of each backup. Throws exception, if no backups were found.
public getBackupVersions ( ) : array
return array

getContent() public method

Returns the content of a given backup file or the content of the current env file.
public getContent ( null $timestamp = NULL ) : array
$timestamp null
return array

getFile() protected method

Returns the file for the given backup-timestamp
protected getFile ( $timestamp ) : string
$timestamp
return string

getLatestBackup() protected method

Returns the timestamp of the latest version.
protected getLatestBackup ( ) : integer | mixed
return integer | mixed

getValue() public method

Returns false, if key does not exist.
public getValue ( $key ) : mixed
$key
return mixed

keyExists() public method

Returns false or true
public keyExists ( $key ) : boolean
$key
return boolean

restoreBackup() public method

Restores the latest version when no timestamp is given.
public restoreBackup ( null $timestamp = NULL ) : string
$timestamp null
return string

save() protected method

Saves the given data to the .env-file
protected save ( $array ) : boolean
$array
return boolean

setAutoBackup() public method

Activate or deactivate the AutoBackup-Functionality
public setAutoBackup ( $onOff )
$onOff

setBackupPath() public method

The new directory will be created if it doesn't exist
public setBackupPath ( $path ) : boolean
$path
return boolean