class DaemonApplication extends CliApplication

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

Methods

__construct( Input $input = null, Registry $config = null, JEventDispatcher $dispatcher = null)

Class constructor.

mixed
getIdentity()

Get the application identity.

registerEvent( string $event, callable $handler)

Registers a handler to a particular event group.

array
triggerEvent( string $event, array $args = null)

Calls all handlers associated with an event group.

loadDispatcher( JEventDispatcher $dispatcher = null)

Allows the application to load a custom or default dispatcher.

loadIdentity( JUser $identity = null)

Allows the application to load a custom or default identity.

static  CliApplication
getInstance( string $name = null)

Returns a reference to the global CliApplication object, only creating it if it doesn't already exist.

void
execute()

Execute the daemon.

loadConfiguration( mixed $data)

Load an object or array into the application configuration object.

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

Write a string to standard output.

CliOutput
getOutput()

Get an output object.

setOutput( CliOutput $output)

Set an output object.

string
in()

Get a value from standard input.

static  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.

void
restart()

Restart daemon process.

void
stop()

Stop daemon process.

Details

__construct( Input $input = null, Registry $config = null, JEventDispatcher $dispatcher = null)

Class constructor.

Parameters

Input $input An optional argument to provide dependency injection for the application's input object. If the argument is a \JInput object that object will become the application's input object, otherwise a default input object is created.
Registry $config An optional argument to provide dependency injection for the application's config object. If the argument is a Registry object that object will become the application's config object, otherwise a default config object is created.
JEventDispatcher $dispatcher An optional argument to provide dependency injection for the application's event dispatcher. If the argument is a \JEventDispatcher object that object will become the application's event dispatcher, if it is null then the default event dispatcher will be created based on the application's loadDispatcher() method.

Exceptions

RuntimeException

mixed getIdentity()

Get the application identity.

Return Value

mixed A \JUser object or null.

BaseApplication registerEvent( string $event, callable $handler)

Registers a handler to a particular event group.

Parameters

string $event The event name.
callable $handler The handler, a function or an instance of an event object.

Return Value

BaseApplication The application to allow chaining.

array triggerEvent( string $event, array $args = null)

Calls all handlers associated with an event group.

Parameters

string $event The event name.
array $args An array of arguments (optional).

Return Value

array An array of results from each function call, or null if no dispatcher is defined.

BaseApplication loadDispatcher( JEventDispatcher $dispatcher = null)

Allows the application to load a custom or default dispatcher.

The logic and options for creating this object are adequately generic for default cases but for many applications it will make sense to override this method and create event dispatchers, if required, based on more specific needs.

Parameters

JEventDispatcher $dispatcher An optional dispatcher object. If omitted, the factory dispatcher is created.

Return Value

BaseApplication This method is chainable.

BaseApplication loadIdentity( JUser $identity = null)

Allows the application to load a custom or default identity.

The logic and options for creating this object are adequately generic for default cases but for many applications it will make sense to override this method and create an identity, if required, based on more specific needs.

Parameters

JUser $identity An optional identity object. If omitted, the factory user is created.

Return Value

BaseApplication This method is chainable.

static CliApplication getInstance( string $name = null)

Returns a reference to the global CliApplication object, only creating it if it doesn't already exist.

This method must be invoked as: $cli = CliApplication::getInstance();

Parameters

string $name The name (optional) of the JApplicationCli class to instantiate.

Return Value

CliApplication

void execute()

Execute the daemon.

Return Value

void

CliApplication 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

CliApplication Instance of $this to allow chaining.

CliApplication 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

CliApplication Instance of $this to allow chaining.

CliOutput getOutput()

Get an output object.

Return Value

CliOutput

CliApplication setOutput( CliOutput $output)

Set an output object.

Parameters

CliOutput $output CliOutput object

Return Value

CliApplication Instance of $this to allow chaining.

string in()

Get a value from standard input.

Return Value

string The input string from standard input.

static 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()

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.

void restart()

Restart daemon process.

Return Value

void

void stop()

Stop daemon process.

Return Value

void