class AbstractDaemonApplication extends AbstractCliApplication implements LoggerAwareInterface (View source)

Class to turn Cli applications into daemons. It requires CLI and PCNTL support built into PHP.

Methods

__construct(IOInterface $io = null, Structure $config = null)

Class constructor.

void
close(integer|string $message)

Method to close the application.

mixed
execute()

Execute the daemon.

mixed
get(string $key, mixed $default = null)

Returns a property of the object or the default value if the property is not set.

LoggerInterface
getLogger()

Get the logger.

mixed
set(string $key, mixed $value = null)

Modifies a property of the object, creating it if it does not already exist.

setConfiguration(Structure $config)

Sets the configuration for the application.

setLogger(LoggerInterface $logger)

Set the logger.

mixed
__get($name)

is utilized for reading data from inaccessible members.

out(string $text = '', boolean $nl = true)

Write a string to standard output.

string
in()

Get a value from standard input.

getIO()

Get the IO object.

void
signal(integer $signal)

Method to handle POSIX signals.

boolean
isActive()

Check to see if the daemon is active. This does not assume that $this daemon is active, but only if an instance of the application is active as a daemon.

loadConfiguration(mixed $data)

Load an object or array into the application configuration object.

void
restart()

Restart daemon process.

void
stop()

Stop daemon process.

string
getName()

Get application name.

setName(string $name)

Set application name.

Details

at line line 114
__construct(IOInterface $io = null, Structure $config = null)

Class constructor.

Parameters

IOInterface $io An optional argument to provide dependency injection for the application's IO object.
Structure $config An optional argument to provide a Structure object to be config.

Exceptions

RuntimeException

void close(integer|string $message)

Method to close the application.

Parameters

integer|string $message The exit code (optional; default is 0).

Return Value

void

at line line 376
mixed execute()

Execute the daemon.

Return Value

mixed

mixed get(string $key, mixed $default = null)

Returns a property of the object or the default value if the property is not set.

Parameters

string $key The name of the property.
mixed $default The default value (optional) if none is set.

Return Value

mixed The value of the configuration.

LoggerInterface getLogger()

Get the logger.

Return Value

LoggerInterface

mixed set(string $key, mixed $value = null)

Modifies a property of the object, creating it if it does not already exist.

Parameters

string $key The name of the property.
mixed $value The value of the property to set (optional).

Return Value

mixed Previous value of the property

AbstractApplication setConfiguration(Structure $config)

Sets the configuration for the application.

Parameters

Structure $config A structure object holding the configuration.

Return Value

AbstractApplication Returns itself to support chaining.

AbstractApplication setLogger(LoggerInterface $logger)

Set the logger.

Parameters

LoggerInterface $logger The logger.

Return Value

AbstractApplication Returns itself to support chaining.

mixed __get($name)

is utilized for reading data from inaccessible members.

Parameters

$name string

Return Value

mixed

AbstractCliApplication out(string $text = '', boolean $nl = true)

Write a string to standard output.

Parameters

string $text The text to display.
boolean $nl True (default) to append a new line at the end of the output string.

Return Value

AbstractCliApplication Instance of $this to allow chaining.

string in()

Get a value from standard input.

Return Value

string The input string from standard input.

IOInterface getIO()

Get the IO object.

Return Value

IOInterface

AbstractCliApplication setIO(IOInterface $io)

Set the IO object.

Parameters

IOInterface $io The IO object.

Return Value

AbstractCliApplication Return self to support chaining.

at line line 161
void signal(integer $signal)

Method to handle POSIX signals.

Parameters

integer $signal The received POSIX signal.

Return Value

void

Exceptions

RuntimeException

See also

pcntl_signal()

at line line 235
boolean isActive()

Check to see if the daemon is active. This does not assume that $this daemon is active, but only if an instance of the application is active as a daemon.

Return Value

boolean True if daemon is active.

at line line 281
AbstractDaemonApplication loadConfiguration(mixed $data)

Load an object or array into the application configuration object.

Parameters

mixed $data Either an array or object to be loaded into the configuration object.

Return Value

AbstractDaemonApplication Instance of $this to allow chaining.

at line line 426
void restart()

Restart daemon process.

Return Value

void

at line line 441
void stop()

Stop daemon process.

Return Value

void

at line line 941
string getName()

Get application name.

Return Value

string Application name.

at line line 955
AbstractDaemonApplication setName(string $name)

Set application name.

Parameters

string $name Name of this application.

Return Value

AbstractDaemonApplication Return self to support chaining.