class FileMonitor (View source)

A monitor which detects changes in directories or files

Properties

protected string $identifier
protected ChangeDetectionStrategyInterface $changeDetectionStrategy
protected Dispatcher $signalDispatcher
protected LoggerInterface $logger
protected StringFrontend $cache
protected array $monitoredFiles
protected array $monitoredDirectories
protected array $changedFiles

Changed files for this monitor

protected array $changedPaths

The changed paths for this monitor

protected array $directoriesAndFiles

Array of directories and files that were cached on the last run.

Methods

__construct(string $identifier)

Constructs this file monitor

static FileMonitor
createFileMonitorAtBoot(string $identifier, Bootstrap $bootstrap)

Helper method to create a FileMonitor instance during boot sequence as injections have to be done manually.

void
injectChangeDetectionStrategy(ChangeDetectionStrategyInterface $changeDetectionStrategy)

Injects the Change Detection Strategy

void
injectSignalDispatcher(Dispatcher $signalDispatcher)

Injects the Singal Slot Dispatcher because classes of the Monitor subpackage cannot be proxied by the AOP framework because it is not initialized at the time the monitoring is used.

void
injectLogger(LoggerInterface $logger)

Injects the (system) logger based on PSR-3.

void
injectCache(StringFrontend $cache)

Injects the Flow_Monitor cache

string
getIdentifier()

Returns the identifier of this monitor

void
monitorFile(string $pathAndFilename)

Adds the specified file to the list of files to be monitored.

void
monitorDirectory(string $path, string $filenamePattern = null)

Adds the specified directory to the list of directories to be monitored.

array
getMonitoredFiles()

Returns a list of all monitored files

array
getMonitoredDirectories()

Returns a list of all monitored directories

void
detectChanges()

Detects changes of the files and directories to be monitored and emits signals accordingly.

bool
detectChangesOnPath(string $path, string $filenamePattern)

Detect changes for one of the monitored paths.

Generator<string>
readMonitoredDirectoryRecursively(string $path, string $filenamePattern)

Read a monitored directory recursively, taking into account filename patterns

void
loadDetectedDirectoriesAndFiles()

Loads the last detected files for this monitor.

void
saveDetectedDirectoriesAndFiles()

Store the changed directories and files back to the cache.

void
setDetectedFilesForPath(string $path, array $files)

No description

array
detectChangedFiles(array $pathAndFilenames)

Detects changes in the given list of files and emits signals if necessary.

void
emitFilesHaveChanged(string $monitorIdentifier, array $changedFiles)

Signalizes that the specified file has changed

void
emitDirectoriesHaveChanged(string $monitorIdentifier, array $changedDirectories)

Signalizes that the specified directory has changed

void
shutdownObject()

Caches the directories and their files

Details

__construct(string $identifier)

Constructs this file monitor

Parameters

string $identifier

Name of this specific file monitor - will be used in the signals emitted by this monitor.

static FileMonitor createFileMonitorAtBoot(string $identifier, Bootstrap $bootstrap)

Helper method to create a FileMonitor instance during boot sequence as injections have to be done manually.

Parameters

string $identifier
Bootstrap $bootstrap

Return Value

FileMonitor

void injectChangeDetectionStrategy(ChangeDetectionStrategyInterface $changeDetectionStrategy)

Injects the Change Detection Strategy

Parameters

ChangeDetectionStrategyInterface $changeDetectionStrategy

The strategy to use for detecting changes

Return Value

void

void injectSignalDispatcher(Dispatcher $signalDispatcher)

Injects the Singal Slot Dispatcher because classes of the Monitor subpackage cannot be proxied by the AOP framework because it is not initialized at the time the monitoring is used.

Parameters

Dispatcher $signalDispatcher

The Signal Slot Dispatcher

Return Value

void

void injectLogger(LoggerInterface $logger)

Injects the (system) logger based on PSR-3.

Parameters

LoggerInterface $logger

Return Value

void

void injectCache(StringFrontend $cache)

Injects the Flow_Monitor cache

Parameters

StringFrontend $cache

Return Value

void

string getIdentifier()

Returns the identifier of this monitor

Return Value

string

void monitorFile(string $pathAndFilename)

Adds the specified file to the list of files to be monitored.

The file in question does not necessarily have to exist.

Parameters

string $pathAndFilename

Absolute path and filename of the file to monitor

Return Value

void

Exceptions

InvalidArgumentException

void monitorDirectory(string $path, string $filenamePattern = null)

Adds the specified directory to the list of directories to be monitored.

All files in these directories will be monitored too.

Parameters

string $path

Absolute path of the directory to monitor

string $filenamePattern

A pattern for filenames to consider for file monitoring (regular expression)

Return Value

void

Exceptions

InvalidArgumentException

array getMonitoredFiles()

Returns a list of all monitored files

Return Value

array

A list of paths and filenames of monitored files

array getMonitoredDirectories()

Returns a list of all monitored directories

Return Value

array

A list of paths of monitored directories

void detectChanges()

Detects changes of the files and directories to be monitored and emits signals accordingly.

Return Value

void

protected bool detectChangesOnPath(string $path, string $filenamePattern)

Detect changes for one of the monitored paths.

Parameters

string $path
string $filenamePattern

Return Value

bool

true if any changes were detected in this path

protected Generator<string> readMonitoredDirectoryRecursively(string $path, string $filenamePattern)

Read a monitored directory recursively, taking into account filename patterns

Parameters

string $path

The path of a monitored directory

string $filenamePattern

Return Value

Generator<string>

A generator returning filenames with full path

protected void loadDetectedDirectoriesAndFiles()

Loads the last detected files for this monitor.

Return Value

void

protected void saveDetectedDirectoriesAndFiles()

Store the changed directories and files back to the cache.

Return Value

void

protected void setDetectedFilesForPath(string $path, array $files)

No description

Parameters

string $path
array $files

Return Value

void

protected array detectChangedFiles(array $pathAndFilenames)

Detects changes in the given list of files and emits signals if necessary.

Parameters

array $pathAndFilenames

A list of full path and filenames of files to check

Return Value

array

An array of changed files (key = path and filenmae) and their status (value)

protected void emitFilesHaveChanged(string $monitorIdentifier, array $changedFiles)

Signalizes that the specified file has changed

Parameters

string $monitorIdentifier

Name of the monitor which detected the change

array $changedFiles

An array of changed files (key = path and filename) and their status (value)

Return Value

void

protected void emitDirectoriesHaveChanged(string $monitorIdentifier, array $changedDirectories)

Signalizes that the specified directory has changed

Parameters

string $monitorIdentifier

Name of the monitor which detected the change

array $changedDirectories

An array of changed directories (key = path) and their status (value)

Return Value

void

void shutdownObject()

Caches the directories and their files

Return Value

void