PHP Класс 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
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$DebugMessage
$ExitCode
$InitializationErrorMessage
$IsInitialized \privatesection
$IsQuiet
$ShowVerbose
$SiteAccess
$UseDebugOutput
$UseExtensions
$UseModules
$UseSession
$User

Открытые методы

Метод Описание
__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.

Приватные методы

Метод Описание
updateSettings ( array $settings = [] ) Updates settings for current script.

Описание методов

__construct() публичный Метод

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

currentOptionConfig() публичный Метод

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

currentOptions() публичный Метод

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

exitCode() публичный Метод

public exitCode ( )

getOptions() публичный Метод

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 initializationError ( )

initialize() публичный Метод

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() статический публичный Метод

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.
Результат eZScript

isInitialized() публичный Метод

public isInitialized ( )

isLoud() публичный Метод

\sa isQuiet
public isLoud ( )

isQuiet() публичный Метод

\sa isLoud
public isQuiet ( )

iterate() публичный Метод

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

resetIteration() публичный Метод

public resetIteration ( $iterationMax = false, $startIndex )

setAllowedDebugLevels() публичный Метод

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

setDebugMessage() публичный Метод

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() публичный Метод

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

setIsInitialized() публичный Метод

public setIsInitialized ( $isInitialized )

setIsQuiet() публичный Метод

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

setIterationData() публичный Метод

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

setShowVerboseOutput() публичный Метод

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() публичный Метод

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

setUseDebugOutput() публичный Метод

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

setUseDebugTimingPoints() публичный Метод

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

setUseExtensions() публичный Метод

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

setUseIncludeFiles() публичный Метод

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

setUseModules() публичный Метод

public setUseModules ( $useModules )

setUseSession() публичный Метод

\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() публичный Метод

\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 setUser ( $userLogin, $userPassword )

showHelp() публичный Метод

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

shutdown() публичный Метод

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() публичный Метод

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() публичный Метод

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

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.
public usedSiteAccess ( )

validateVersion() публичный Метод

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

verboseOutputLevel() публичный Метод

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

Описание свойств

$DebugMessage публичное свойство

public $DebugMessage

$ExitCode публичное свойство

public $ExitCode

$InitializationErrorMessage публичное свойство

public $InitializationErrorMessage

$IsInitialized публичное свойство

\privatesection
public $IsInitialized

$IsQuiet публичное свойство

public $IsQuiet

$ShowVerbose публичное свойство

public $ShowVerbose

$SiteAccess публичное свойство

public $SiteAccess

$UseDebugOutput публичное свойство

public $UseDebugOutput

$UseExtensions публичное свойство

public $UseExtensions

$UseModules публичное свойство

public $UseModules

$UseSession публичное свойство

public $UseSession

$User публичное свойство

public $User