OpenMediaVault  0.6 (Kralizec)
The open network attached storage solution
 All Classes Functions Variables Groups Pages
Public Member Functions | List of all members
OMVJsonFile Class Reference
Inheritance diagram for OMVJsonFile:
OMVObject

Public Member Functions

 __construct ($filename)
 
 __destruct ()
 
 exists ()
 
 open ($accessMode="w+", $lockMode=LOCK_EX)
 
 isOpen ()
 
 isEmpty ()
 
 close ()
 
 write ($content)
 
 read ($decode=TRUE)
 
 truncate ($size)
 
 unlink ()
 
- Public Member Functions inherited from OMVObject
 __construct ()
 
 getLastError ()
 

Additional Inherited Members

- Protected Member Functions inherited from OMVObject
 setLastError ($error)
 
 debug ()
 

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

OMVJsonFile::__construct (   $filename)

Constructor

Parameters
filenameThe name of the file.
OMVJsonFile::__destruct ( )

Destructor

Member Function Documentation

OMVJsonFile::close ( )

Close the file.

Returns
None.
Exceptions
E_MISC_FAILURE
OMVJsonFile::exists ( )

Checks whether the file exists.

Returns
Returns TRUE if the file exists, FALSE otherwise.
OMVJsonFile::isEmpty ( )

Is the file empty?

Returns
TRUE if the file is empty, otherwise FALSE.
OMVJsonFile::isOpen ( )

Is the file opened?

Returns
TRUE if the file is opened, otherwise FALSE.
OMVJsonFile::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
E_MISC_FAILURE
OMVJsonFile::read (   $decode = 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
E_MISC_FAILURE
OMVJsonFile::truncate (   $size)

Truncates the file to a given length.

Parameters
sizeThe size to truncate to.
Returns
None.
Exceptions
E_MISC_FAILURE
OMVJsonFile::unlink ( )

Unlink the given file.

Returns
Returns TRUE on success or FALSE on failure.
OMVJsonFile::write (   $content)

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
contentThe content to be written.
Returns
Returns the JSON representation of the content which was written to the file.
Exceptions
E_MISC_FAILURE

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