Console_Application
[
class tree: Console_Application
] [
index: Console_Application
] [
all elements
]
Todo List
Packages:
Console_Application
Console_Deamon
Console_Enviroment
Console_Exception
Example
Unittests
Source for file Abstract.php
Documentation is available at
Abstract.php
<?php
/**
* Console Library
*
* LICENSE
*
* "THE BEER-WARE LICENSE" (Revision 42):
* "Sven Strittmatter" <ausserirdisch@sven-space.de> wrote this file.
* As long as you retain this notice you can do whatever you want with
* this stuff. If we meet some day, and you think this stuff is worth it,
* you can buy me a beer in return.
*
* $Author$
* $Revision$
*
*
@category
Console
*
@package
Console_Application
*
@copyright
Copyright (c) 2009 Sven Strittmatter
*/
/**
* Console_Application_Abstract.
*
*
@see
Console_Application_Abstract
*/
require_once
(
'Console/Application/Abstract.php'
)
;
/**
* Console_Exception.
*
*
@see
Console_Exception
*/
require_once
(
'Console/Exception.php'
)
;
/**
* Class which is running in a loop.
*
*
@abstract
*
@category
Console
*
@package
Console_Deamon
*
@uses
Console_Application_Abstract
*
@uses
Console_Exception
*
@copyright
Copyright (c) 2009 Sven Strittmatter
*/
abstract
class
Console_Deamon_Abstract
extends
Console_Application_Abstract
{
/**
* Flag to signal to break the loop.
*
*
@access
private
*
@var
bool
*/
private
$breakLoop
;
/**
* Counts the executed loops.
*
*
@access
private
*
@var
int
*/
private
$counter
=
0
;
/**
* Template method from Console_Application_Abstract.
* This method runs the method doLoopCycle() which you must
* implement in your deamon class implementation.
*
*
@see
Console_Application_Abstract
*
*
@final
*
@access
protected
*/
final
protected
function
run
(
)
{
$this
->
onPreLoop
(
)
;
while
(
true
)
{
if
(
$this
->
breakLoop
)
{
$this
->
onBreakLoop
(
)
;
break
;
}
$this
->
doLoopCycle
(
)
;
$this
->
counter
++
;
}
$this
->
onPostLoop
(
)
;
}
/**
* Overwrite this method to hook the pre loop phase.
* This method is called first before the loop. But after
* Console_Application_Abstract::setUp().
*
*
@access
protected
*/
protected
function
onPreLoop
(
)
{
}
/**
* Overwrite this method to hook the moment the internal breakLoop flag
* is set true by the script.
*
*
@access
protected
*/
protected
function
onBreakLoop
(
)
{
}
/**
* Overwrite this method to hook the phase after the loop. This Method
* is called imediately after self::onBreakLoop(). But before
* Console_Application_Abstract::tearDown().
*
*
@access
protected
*/
protected
function
onPostLoop
(
)
{
}
/**
* You need to implement this method with your loop code.
* This method is called periodicly until self::breakLoop()
* is called.
*
* Important is, that after self::breakLoop() this method runs
* until it returns. If you want to break out from your loop
* method directly after setting the demaon to break the loop,
* you need to return:
*
* <code>
* protected function onPostLoop() {
* // some work ...
*
* if ($something) {
* // We break out imediately.
* // some other work will not be executed
* self::breakLoop();
* return;
* }
*
* if ($somethingElse) {
* // We only break the loop.
* // This method will not be executed anymore.
* // But some other work will be executed the last time!
* self::breakLoop();
* }
*
* // some other work ...
* }
* </code>
*/
protected
abstract
function
doLoopCycle
(
)
;
/**
* Signals the object to do no more loop cycles.
* After the actual call to self::doLoopCycle() has finished
* self::onBreakLoop() will be called.
*/
protected
function
breakLoop
(
)
{
$this
->
breakLoop
=
true
;
}
/**
* Bind the signal SIG_TERM to brek the loop.
*
*
@access
public
*
@param
int
$signal
*/
public
function
signalTerm
(
$signal
)
{
$this
->
breakLoop
(
)
;
}
/**
* Bind the signal SIG_INT to brek the loop.
*
*
@access
public
*
@param
int
$signal
*/
public
function
signalInt
(
$signal
)
{
$this
->
breakLoop
(
)
;
}
}
Documentation generated on Mon, 17 Aug 2009 15:51:54 +0200 by
phpDocumentor 1.4.2