Library
Class

Library\Tool\FileRotator

class FileRotator

Rotate system for files

Constants

ROTATE_PERIODIC

Use this to make a rotation based on time

ROTATE_FILESIZE

Use it to make a rotation base on file size

Methods

__construct(string $file_path, int $flag = self::ROTATE_PERIODIC, array $user_options = array())

Creation of a new file rotator

bool write(string $content = '')

Write a string in the file

bool rotate(bool $force = false)

Rotate file if so

bool mustRotate()

Does the current file need to be rotated

string getFilename(string $file_name, int $rotation_index)

Get the name of a file to rotate

Details

at line 85
public __construct(string $file_path, int $flag = self::ROTATE_PERIODIC, array $user_options = array())

Creation of a new file rotator

Parameters

string $file_path Full path of concerned file
int $flag One of the class ROTATE_ constants
array $user_options A set of one shot options

Exceptions

InvalidArgumentException if no $file_path argument

at line 108
public bool write(string $content = '')

Write a string in the file

Parameters

string $content The content to add in the file

Return Value

bool

Exceptions

RuntimeException if an error occurred trying to rotate or write in file

at line 138
public bool rotate(bool $force = false)

Rotate file if so

Parameters

bool $force Force file rotation, even if mustRotate() is false

Return Value

bool

at line 170
public bool mustRotate()

Does the current file need to be rotated

Return Value

bool

at line 193
public string getFilename(string $file_name, int $rotation_index)

Get the name of a file to rotate

Parameters

string $file_name
int $rotation_index

Return Value

string