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
Afficher le fichier Open project: ezsystems/ezpublish-legacy Class Usage Examples

Méthodes publiques

Свойство Type Description
$DebugMessage
$ExitCode
$InitializationErrorMessage
$IsInitialized \privatesection
$IsQuiet
$ShowVerbose
$SiteAccess
$UseDebugOutput
$UseExtensions
$UseModules
$UseSession
$User

Méthodes publiques

Méthode 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

Méthode Description
updateSettings ( array $settings = [] ) Updates settings for current script.

Method Details

__construct() public méthode

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

currentOptionConfig() public méthode

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

currentOptions() public méthode

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

exitCode() public méthode

public exitCode ( )

getOptions() public méthode

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 méthode

public initializationError ( )

initialize() public méthode

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 méthode

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.
Résultat eZScript

isInitialized() public méthode

public isInitialized ( )

isLoud() public méthode

\sa isQuiet
public isLoud ( )

isQuiet() public méthode

\sa isLoud
public isQuiet ( )

iterate() public méthode

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

resetIteration() public méthode

public resetIteration ( $iterationMax = false, $startIndex )

setAllowedDebugLevels() public méthode

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

setDebugMessage() public méthode

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 méthode

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

setIsInitialized() public méthode

public setIsInitialized ( $isInitialized )

setIsQuiet() public méthode

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

setIterationData() public méthode

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

setShowVerboseOutput() public méthode

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 méthode

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

setUseDebugOutput() public méthode

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

setUseDebugTimingPoints() public méthode

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

setUseExtensions() public méthode

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

setUseIncludeFiles() public méthode

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

setUseModules() public méthode

public setUseModules ( $useModules )

setUseSession() public méthode

\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 méthode

\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 méthode

public setUser ( $userLogin, $userPassword )

showHelp() public méthode

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

shutdown() public méthode

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 méthode

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 méthode

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

updateTextCodecSettings() public méthode

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

usedSiteAccess() public méthode

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

validateVersion() public méthode

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

verboseOutputLevel() public méthode

*! \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