constructor __construct [line 104]
Console_Application_Abstract __construct(
string
$scriptname, [int
$maxExecTime = 60], [string
$memoryLimit = '128M'])
|
|
On construction time a sapiCheck is done for CLI sapi.
The php enviroment will be set and some default signal handlers are registered.
Throws a excpetion if the php enviroment ist not the command line.
Tags:
Parameters:
method echoMsg [line 456]
void echoMsg(
[string
$msg = ''])
|
|
Echoes a string appended with PHP_EOL.
If you call it without parameter it makes newlines ;-)
Tags:
Parameters:
method execute [line 204]
Template method. Try to run some method stubs in this order:
- Console_Application_Abstract::findConsoleParameters()
- Console_Application_Abstract::setUp()
- Console_Application_Abstract::run()
- Console_Application_Abstract::tearDown()
If Console_Application_Abstract::findConsoleParameters() returns true the script execution aborts imediately.
If in the templateed method structure any exception occures it is catched an the method Console_Application_Abstract::onError() is called. The exception object is passed to it.
After that procedure two additional tear down methods will be called:
- Console_Application_Abstract::setExecuted()
- Console_Application_Abstract::resetPhpEnviroment()
Tags:
Implementation of:
- Console_Application_Interface::execute()
- Executes the application object
method findConsoleParameters [line 284]
bool findConsoleParameters(
)
|
|
This method listens by default to the console parameters -v and -h.
By default -v enables the verbose mode (see Console_Application_Abstract::isVerbose()).
By default -h calls Console_Application_Abstract::printHelpMessage() and returns with false.
To retrieve custom options overwite this mithed. Call the method an checks against false. Then check your options. If a required option is not set you should throw an Console_Exception_MissingParameter. This errors are handled in an default way to the console user (see Console_Exception_MissingParameter::onError()).
Example implementation. Full example @see HelloWorldApplication
if (!parent::findConsoleParameters()) {
return false;
}
if (isset($options['n']) && !empty($options['n'])) {
$this->name = $options['n'];
}
if (isset($options['s']) && !empty($options['s'])) {
$this->sleep = (int)
$options['s'];
}
return true;
}
To brek the script if a user omitted a required console option you should implement it that way, because the onError() method handles Console_Exception_MissingParameter by default with nice user experience.
if (!parent::findConsoleParameters()) {
return false;
}
if (isset($options['n']) && !empty($options['n'])) {
$this->name = $options['n'];
} else {
}
return true;
}
For more details about getting options by getopt()
Tags:
Overridden in child classes as:
- Console_Application_Concrete::findConsoleParameters()
- HelloWorldApplication::findConsoleParameters()
method getHelpMessage [line 412]
string getHelpMessage(
[string
$author = ''], [string
$email = 'foo@bar.de'])
|
|
Returns a help message. Its called by default object behavier, if you suply -h to the script. By default it returns a line break formatted help message like:
This is a sample console application. It prints some hello world statements.
Usage: {$scriptName} [-h] [-v]
{$scriptName} -v : Sets the script in verbose mode.
{$scriptName} -h : prints this help message.
For bug reporting or issues contact: foo@bar.de
You can customize the help message your wy. See an example implementation (@see HelloWorldApplication)
$message = "This is a sample console application. It prints some ";
$message .= "hello world statements." . PHP_EOL . PHP_EOL;
$message .=
$this->getUsage() .
PHP_EOL;
$message .= "\t{$this->scriptname} -n : You can specify a name to ";
$message .= §be hellowed" . PHP_EOL;
$message .= "t{$this->scriptname} -
s :
You can specify the seconds ";
$message .= §to sleep between hello and name." . PHP_EOL;
$message .= parent::getHelpMessage($author, $email);
}
Tags:
Overridden in child classes as:
- HelloWorldApplication::getHelpMessage()
Parameters:
method getUsage [line 443]
string getUsage(
[string
$options = ''])
|
|
Returns a usage string like:
Usage: {$scriptName} {$options} [-h] [-v]
By example implementation (@see HelloWorldApplication) its:
Usage: helloworld.sh [-n] [-s] [-h] [-v]
Tags:
Overridden in child classes as:
- HelloWorldApplication::getUsage()
Parameters:
method iniSet [line 172]
mixed iniSet(
string
$name, mixed
$value)
|
|
This method wraps the php internal ini_set() that way, that it returns the old value.
Tags:
Parameters:
method isExecuted [line 138]
method isPcntlEnabled [line 503]
method isVerbose [line 150]
Returns whether the application object is verbose or not.
This is set by the comandline option -v (in Console_Application_Abstract::findConsoleParameters()).
Tags:
method onError [line 364]
void onError(
mixed
$errorData)
|
|
This method is called if in the three followed methods a exception was
throwed:
- Console_Application_Abstract::findConsoleParameters()
- Console_Application_Abstract::setUp()
- Console_Application_Abstract::run()
- Console_Application_Abstract::tearDown()
Exceptions of the (sub)type Console_Exception are handled by defaukt in a special way: <dl> <dt>Console_Exception_MissingParameter</dt> <dd>The exeption message and the return string of getUsage() will be echoed.</dd> <dt>Console_Exception</dt> <dd>The excpetion message will be echoed.</dd> </dl>
Tags:
Overridden in child classes as:
- Console_Application_Concrete::onError()
Parameters:
method registerSignalHandlers [line 481]
void registerSignalHandlers(
)
|
|
Registers some signal handlers:
<dl> <dd>SIGTERM</dd> <dt>Console_Application_Abstract::signalTerm()</dt> <dd>SIGINT</dd> <dt>Console_Application_Abstract::signalInt()</dt> <dd>SIGHUP</dd> <dt>Console_Application_Abstract::signalHangUp()</dt> </dl>
IS called on construction time. Overwrite this methid
Tags:
method run [line 324]
method setExecuted [line 159]
Sets object executed.
Tags:
method setPhpEnviroment [line 580]
void setPhpEnviroment(
string
$memoryLimit, int
$maxExecutionTime)
|
|
Sets the the php enviroment by ini settings to a proper default.
These are:
- memory_limit
- max_execution_time
- html_errors = false
- implicit_flush = true
The old values are stored in Console_Application_Abstract::iniSet array. So they can be restored by Console_Application_Abstract::resetPhpEnviroment().
If you wanne make some custom ini settings in your script overwrite this method this way:
Tags:
Parameters:
method setUp [line 311]
Template method stub. Overwrite this method to hook the set up phase of your script. This method is called after Console_Application_Abstract::findConsoleParameters(), unless it returns false. And before Console_Application_Abstract::run().
By default this method does nothing!
Return values are not evaluated.
Tags:
Overridden in child classes as:
- Console_Application_Concrete::setUp()
method signalHangUp [line 544]
void signalHangUp(
int
$signal)
|
|
Signal handler registered by Console_Application_Abstract::registerSignalHandlers().
By default it echoes a message and calls Console_Application_Abstract::tearDown().
Overwrite this method to react on SIGHUP.
Tags:
Overridden in child classes as:
- Console_Application_Concrete::signalHangUp()
Parameters:
method signalInt [line 530]
method signalTerm [line 516]
void signalTerm(
int
$signal)
|
|
Signal handler registered by Console_Application_Abstract::registerSignalHandlers().
By default it echoes a message and calls Console_Application_Abstract::tearDown().
Overwrite this method to react on SIGTERM.
Tags:
Overridden in child classes as:
- Console_Application_Concrete::signalTerm()
- Console_Deamon_Abstract::signalTerm()
- Bind the signal SIG_TERM to brek the loop.
Parameters:
method tearDown [line 337]
Template method stub. Overwrite this method to hook the tear down phase of your script. This method is called after Console_Application_Abstract::run(), unless any exception was throwed.
And before Console_Application_Abstract::setExecuted().
By default this method does nothing!
Return values are not evaluated.
Tags:
Overridden in child classes as:
- Console_Application_Concrete::tearDown()