Example
[
class tree: Example
] [
index: Example
] [
all elements
]
Todo List
Packages:
Console_Application
Console_Deamon
Console_Enviroment
Console_Exception
Example
Unittests
Source for file HelloWorldApplication.php
Documentation is available at
HelloWorldApplication.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$
* $Revisio$
*
*
@category
Console
*
@package
Example
*
@copyright
Copyright (c) 2009 Sven Strittmatter
*/
/**
*
@see
Console_Application_Abstract
*/
require_once
(
'Console/Application/Abstract.php'
)
;
/**
*
@see
Console_Exception
*/
require_once
(
'Console/Exception.php'
)
;
/*
* Neccessary for the signal handler
*/
declare
(
ticks
=
1
)
;
/**
* Template method class for CLI commands.
*
*
@see
HelloWorldApplication for an example implementation.
*
*
@abstract
*
@category
Console
*
@package
Example
*
@uses
Console_Application_Abstract
*
@uses
Console_Exception
*
@copyright
Copyright (c) 2009 Sven Strittmatter
*/
class
HelloWorldApplication
extends
Console_Application_Abstract
{
/**
*
@access
protected
*
@var
string
*/
protected
$name
=
'world'
;
/**
*
@access
protected
*
@var
int
*/
protected
$sleep
=
0
;
/**
*
@see
Console_Application_Abstract::run()
*/
protected
function
run
(
)
{
// if this constant is defined, then this script runs in an unit test.
// there we wont echo some messages to cli.
$quiet
=
defined
(
'TESTS_CONSOLE_APPLICATION_LOCATION'
)
;
if
(
!
$quiet
)
{
echo
"Hello"
;
sleep
(
$this
->
sleep
)
;
echo
"
{
$this
->
name
}
!\n
"
;
}
}
/**
* @see Console_Application_Abstract::signalInt()
*/
public
function
signalInt
(
$signal
)
{
throw
new
Console_Exception
(
'bye bye'
)
;
}
/**
* @see Console_Application_Abstract::findConsoleParameters()
*/
protected
function
findConsoleParameters
(
)
{
$options
=
getopt
(
'n:s:'
)
;
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
;
}
/**
* @see Console_Application_Abstract::getUsage()
*/
public
function
getUsage
(
$options
=
null
)
{
return
parent
::
getUsage
(
'[-n name] [-s seconds]'
)
;
}
/**
* @see Console_Application_Abstract::getHelpMessage()
*/
public
function
getHelpMessage
(
$author
=
'Sven Strittmatter'
,
$email
=
'ich@weltraumschaf.de'
)
{
$message
=
"This is a sample console application. It prints some hello world statements."
.
PHP_EOL
.
PHP_EOL
;
$message
.=
$this
->
getUsage
(
)
.
PHP_EOL
;
$message
.=
"
\t{
$this
->
scriptname
}
-n : You can specify a name to be hellowed
"
.
PHP_EOL
;
$message
.=
"
\t{
$this
->
scriptname
}
-s : You can specify the seconds to sleep between hello and name.
"
.
PHP_EOL
;
$message
.=
parent
::
getHelpMessage
(
$author
,
$email
)
;
throw
new
Console_Exception
(
$message
)
;
}
Documentation generated on Mon, 17 Aug 2009 15:52:39 +0200 by
phpDocumentor 1.4.2