OpenMediaVault  3.0 (Erasmus)
The open network attached storage solution
Public Member Functions | Protected Member Functions | List of all members
OMV\Json\File Class Reference

Public Member Functions

 __construct ($filename)
 
 __destruct ()
 
 exists ()
 
 open ($accessMode="w+", $lockMode=LOCK_EX)
 
 isOpen ()
 
 isEmpty ()
 
 isValid ()
 
 close ()
 
 write ($data)
 
 getContents ()
 
 read ($decode=TRUE, $assoc=TRUE)
 
 truncate ($size)
 
 unlink ()
 

Protected Member Functions

 validate ($data)
 

Detailed Description

Read and write JSON encoded content to a file. The file is locked when it is opened and the lock is removed when it is closed.

Constructor & Destructor Documentation

OMV\Json\File::__construct (   $filename)

Constructor

Parameters
filenameThe name of the file.
OMV\Json\File::__destruct ( )

Destructor

Member Function Documentation

OMV\Json\File::close ( )

Close the file.

Returns
None.
Exceptions
OMV\Json\File::exists ( )

Checks whether the file exists.

Returns
Returns TRUE if the file exists, FALSE otherwise.
OMV\Json\File::getContents ( )

Reads entire file into a string.

Returns
The method returns the read data.
Exceptions
OMV\Json\File::isEmpty ( )

Is the file empty?

Returns
TRUE if the file is empty, otherwise FALSE.
Exceptions
OMV\Json\File::isOpen ( )

Is the file opened?

Returns
TRUE if the file is opened, otherwise FALSE.
OMV\Json\File::isValid ( )

Check if the JSON data is valid.

Returns
TRUE if the JSON data is valid, otherwise FALSE.
OMV\Json\File::open (   $accessMode = "w+",
  $lockMode = LOCK_EX 
)

Open the file.

Parameters
accessModeThe parameter specifies the type of access you require to the stream. Defaults to 'w+'.
lockModeThe lock mode. Defaults to LOCK_EX.
Returns
The file handle.
Exceptions
OMV\Json\File::read (   $decode = TRUE,
  $assoc = TRUE 
)

Read the JSON encoded data from the file.

Parameters
decodeSet to TRUE to decode the JSON content. Defaults to TRUE.
Returns
The content read from the file. If decode was set to TRUE the decoded content is returned.
Exceptions
OMV\Json\File::truncate (   $size)

Truncates the file to a given length.

Parameters
sizeThe size to truncate to.
Returns
None.
Exceptions
OMV\Json\File::unlink ( )

Unlink the given file.

Returns
Returns TRUE on success or FALSE on failure.
OMV\Json\File::validate (   $data)
protected

Validate the JSON data.

Parameters
dataThe JSON data to validate.
Returns
TRUE if the JSON data is valid, otherwise FALSE.
OMV\Json\File::write (   $data)

Write the given content as JSON encoded string to the file. The file will be truncated to zero length before the content is written.

Parameters
dataThe data to write.
Returns
Returns the JSON representation of the data which was written to the file.
Exceptions

The documentation for this class was generated from the following file: