PHP Class eZScript

By using this class for script execution startup, initializing and shutdown the amount code required to write a new script is reduced significantly. It is also recommended to use the eZCLI class in addition to this class. What this class will handle is: - Startup of database - Startup/shutdown of session - Debug initialize and display - Text codec initialize This class consists of the static functions startup(), initialize() and shutdown(). A typical usage: \code $script = eZScript::instance(); $script->startup(); Read arguments and modify script accordingly $script->initialize(); Do the actual script here $script->shutdown(); // Finish execution \endcode
Mostrar archivo Open project: ezsystems/ezpublish-legacy Class Usage Examples

Public Properties

Property Type Description
$DebugMessage
$ExitCode
$InitializationErrorMessage
$IsInitialized \privatesection
$IsQuiet
$ShowVerbose
$SiteAccess
$UseDebugOutput
$UseExtensions
$UseModules
$UseSession
$User

Public Methods

Method Description
__construct ( $settings = [] ) *! Constructor
currentOptionConfig ( ) *! \return the current option configuration, this will be a mix of the standard options and script specified.
currentOptions ( ) *! \return the currently set options if getOptions() has been run or \c false if no options are set.
exitCode ( )
getOptions ( $config = '', $argumentConfig = '', $optionHelp = false, $arguments = false, $useStandardOptions = true ) *! Parse command line into options array. If stanadrd options are in use, carry out the associated task (eg. switch siteaccess ir logged-in user) param $config see ezcli::parseOptionString param $argumentConfig see ezcli::getOptions (unused for now) param $optionHelp string echoed to screen when script invoked with -h/--help param $arguments array of arguments. If false, command line is parsed automatically param $useStandardOptions true or an array of standard options to be used.
initializationError ( )
initialize ( ) *! Initializes all settings which are required for the script to run, must be called after startup() and getOptions().
instance ( array $settings = [] ) : eZScript Returns a shared instance of the eZScript class.
isInitialized ( )
isLoud ( ) *! \return \c true if output is allowed.
isQuiet ( ) *! \return \c true if output is not allowed.
iterate ( $cli, $status, $text = false )
resetIteration ( $iterationMax = false, $startIndex )
setAllowedDebugLevels ( $allowedDebugLevels ) *! Sets which debug levels are to be shown on debug output, this must be an array with EZ_LEVEL_* definitions taken from eZDebug.
setDebugMessage ( $message ) *! Sets the text message which is shown before the debug list.
setExitCode ( $code = false ) *! Sets the current exit code which will be set with an exit() call in shutdown().
setIsInitialized ( $isInitialized )
setIsQuiet ( $isQuiet ) *! Sets whether any output should be used or not.
setIterationData ( $trueString, $falseString, $numericStrings = false, $wrapNumeric = false )
setShowVerboseOutput ( $verbose ) *! Controls whether verbose output is used or not, use \c false to turn it off, \c true to turn it on or a number to select the verbose level (\c true == 1).
setUseDebugAccumulators ( $useAccumulators ) *! Sets whether accumulators should be shown on debug output or not.
setUseDebugOutput ( $useDebug ) *! Sets whether debug output should be enabled or not.
setUseDebugTimingPoints ( $useTimingPoints ) *! Sets whether timing points should be shown on debug output or not.
setUseExtensions ( $useExtensions ) *! Sets whether extension support is to be added or not.
setUseIncludeFiles ( $useIncludeFiles ) *! Sets whether include files should be shown on debug output or not.
setUseModules ( $useModules )
setUseSession ( $useSession ) *! Sets whether session is to be used or not.
setUseSiteAccess ( $siteAccess ) *! Sets the current site access to \a $siteAccess.
setUser ( $userLogin, $userPassword )
showHelp ( $useStandardOptions = false, $optionConfig = false, $optionHelp = false, $argumentConfig = false, $arguments = false )
shutdown ( $exitCode = false, $exitText = false ) *! Shuts down the currently running script, the following things will be done: - Remove current session (if sessions are used) - Print debug messages (if debug is enabled) - Call cleanup function using eZExecution - Sets the clean exit flag, that way an exit, die or other stops will not issue an error
startup ( ) *! Checks if the script is run in CLI mode, if not it exits with a warning.
updateDebugSettings ( $useDebug = null ) *! \static Reads settings from site.ini and passes them to eZDebug.
updateTextCodecSettings ( ) *! \static Reads settings from i18n.ini and passes them to eZTextCodec.
usedSiteAccess ( ) *! \return the currently set siteaccess or \c false if none is set.
validateVersion ( ) *! Checks if the script is run on correct eZ Publish version.
verboseOutputLevel ( ) *! \return the verbosity level for the script, will be \c false or a number in the range 1 and up.

Private Methods

Method Description
updateSettings ( array $settings = [] ) Updates settings for current script.

Method Details

__construct() public method

*! Constructor
public __construct ( $settings = [] )

currentOptionConfig() public method

*! \return the current option configuration, this will be a mix of the standard options and script specified.
public currentOptionConfig ( )

currentOptions() public method

*! \return the currently set options if getOptions() has been run or \c false if no options are set.
public currentOptions ( )

exitCode() public method

public exitCode ( )

getOptions() public method

standard options are: 'debug', 'colors', 'log', 'siteaccess', 'verbose', 'user' (false), and can be set to false to be disabled
public getOptions ( $config = '', $argumentConfig = '', $optionHelp = false, $arguments = false, $useStandardOptions = true )

initializationError() public method

public initializationError ( )

initialize() public method

If you modify the eZScript object using the set* functions you must make sure that is done before this function is called.
public initialize ( )

instance() static public method

Returns a shared instance of the eZScript class.
static public instance ( array $settings = [] ) : eZScript
$settings array Used by the first generated instance, but ignored for subsequent calls.
return eZScript

isInitialized() public method

public isInitialized ( )

isLoud() public method

\sa isQuiet
public isLoud ( )

isQuiet() public method

\sa isLoud
public isQuiet ( )

iterate() public method

public iterate ( $cli, $status, $text = false )

resetIteration() public method

public resetIteration ( $iterationMax = false, $startIndex )

setAllowedDebugLevels() public method

\note This requires that setUseDebugOutput is set to true or that the user has enabled debug in the arguments.
public setAllowedDebugLevels ( $allowedDebugLevels )

setDebugMessage() public method

There will be a default message which should suit most scripts. \note This requires that setUseDebugOutput is set to true or that the user has enabled debug in the arguments.
public setDebugMessage ( $message )

setExitCode() public method

If you don't want shutdown() to exit automatically set it to \c false.
public setExitCode ( $code = false )

setIsInitialized() public method

public setIsInitialized ( $isInitialized )

setIsQuiet() public method

\sa isQuiet, isLoud \note it will also call eZCLI::setIsQuiet()
public setIsQuiet ( $isQuiet )

setIterationData() public method

public setIterationData ( $trueString, $falseString, $numericStrings = false, $wrapNumeric = false )

setShowVerboseOutput() public method

The actual behaviour of verbose output depends on the script, however enabling it will make sure iteration looping displays the iteration name instead of a dot.
public setShowVerboseOutput ( $verbose )

setUseDebugAccumulators() public method

\note This requires that setUseDebugOutput is set to true or that the user has enabled debug in the arguments.
public setUseDebugAccumulators ( $useAccumulators )

setUseDebugOutput() public method

\note This can also be called by the argument parser if the user specifies to show debug.
public setUseDebugOutput ( $useDebug )

setUseDebugTimingPoints() public method

\note This requires that setUseDebugOutput is set to true or that the user has enabled debug in the arguments.
public setUseDebugTimingPoints ( $useTimingPoints )

setUseExtensions() public method

\note This will only work if it is set before initialized() is called.
public setUseExtensions ( $useExtensions )

setUseIncludeFiles() public method

\note This requires that setUseDebugOutput is set to true or that the user has enabled debug in the arguments.
public setUseIncludeFiles ( $useIncludeFiles )

setUseModules() public method

public setUseModules ( $useModules )

setUseSession() public method

\note This will only work if it is set before initialized() is called. \note If session is enabled the current session data will be removed on shutdown().
public setUseSession ( $useSession )

setUseSiteAccess() public method

\note This will only work if it is set before initialized() is called. \note This will be filled in if getOptions() is used and the user specifices it in the arguments.
public setUseSiteAccess ( $siteAccess )

setUser() public method

public setUser ( $userLogin, $userPassword )

showHelp() public method

public showHelp ( $useStandardOptions = false, $optionConfig = false, $optionHelp = false, $argumentConfig = false, $arguments = false )

shutdown() public method

If an exit code is set, PHP will exit with that code set (this means that this function never returns), otherwise this function returns normally.
public shutdown ( $exitCode = false, $exitText = false )

startup() public method

The PHP local is also initialized if it is used. Call this at the very start of your script and always before getOptions() and initialize().
public startup ( )

updateDebugSettings() public method

*! \static Reads settings from site.ini and passes them to eZDebug.
public updateDebugSettings ( $useDebug = null )

updateTextCodecSettings() public method

*! \static Reads settings from i18n.ini and passes them to eZTextCodec.

usedSiteAccess() public method

*! \return the currently set siteaccess or \c false if none is set.
public usedSiteAccess ( )

validateVersion() public method

*! Checks if the script is run on correct eZ Publish version.
public validateVersion ( )

verboseOutputLevel() public method

*! \return the verbosity level for the script, will be \c false or a number in the range 1 and up.
public verboseOutputLevel ( )

Property Details

$DebugMessage public_oe property

public $DebugMessage

$ExitCode public_oe property

public $ExitCode

$InitializationErrorMessage public_oe property

public $InitializationErrorMessage

$IsInitialized public_oe property

\privatesection
public $IsInitialized

$IsQuiet public_oe property

public $IsQuiet

$ShowVerbose public_oe property

public $ShowVerbose

$SiteAccess public_oe property

public $SiteAccess

$UseDebugOutput public_oe property

public $UseDebugOutput

$UseExtensions public_oe property

public $UseExtensions

$UseModules public_oe property

public $UseModules

$UseSession public_oe property

public $UseSession

$User public_oe property

public $User