Index: t3lib/class.t3lib_svbase.php =================================================================== --- t3lib/class.t3lib_svbase.php (revision 9595) +++ t3lib/class.t3lib_svbase.php (working copy) @@ -115,44 +115,43 @@ abstract class t3lib_svbase { /** - * service description array + * @var array service description array */ var $info = array(); /** - * error stack + * @var array error stack */ var $error = array(); /** - * Defines if debug messages should be written with t3lib_div::devLog + * @var bool Defines if debug messages should be written with t3lib_div::devLog */ var $writeDevLog = FALSE; /** - * The output content. - * That's what the services produced as result. + * @var string The output content. That's what the services produced as result. */ var $out = ''; /** - * The file that should be processed. + * @var string The file that should be processed. */ var $inputFile = ''; /** - * The content that should be processed. + * @var string The content that should be processed. */ var $inputContent = ''; /** - * The type of the input content (or file). Might be the same as the service subtypes. + * @var string The type of the input content (or file). Might be the same as the service subtypes. */ var $inputType = ''; /** - * The file where the output should be written to. + * @var string The file where the output should be written to. */ var $outputFile = ''; @@ -164,6 +163,8 @@ */ var $tempFiles = array(); + /** @var string Prefix for temporary files */ + protected $prefixId = ''; /*************************************** * @@ -206,8 +207,8 @@ * Returns service configuration values from the $TYPO3_CONF_VARS['SVCONF'] array * * @param string Name of the config option - * @param boolean If set the 'default' config will be return if no special config for this service is available (default: true) - * @param [type] $includeDefaultConfig: ... + * @param mixed Default configuration if no special config is available + * @param bool If set the 'default' config will be returned if no special config for this service is available (default: true) * @return mixed configuration value for the service */ function getServiceOption($optionName, $defaultValue = '', $includeDefaultConfig = TRUE) { @@ -239,7 +240,7 @@ * * @param string Debug message * @param integer Severity: 0 is info, 1 is notice, 2 is warning, 3 is fatal error, -1 is "OK" message - * @param array Additional data you want to pass to the logger. + * @param array|bool Additional data you want to pass to the logger. * @return void */ function devLog($msg, $severity = 0, $dataVar = FALSE) { @@ -252,8 +253,8 @@ /** * Puts an error on the error stack. Calling without parameter adds a general error. * + * @param integer error number (see T3_ERR_SV_* constants) * @param string error message - * @param string error number (see T3_ERR_SV_* constants) * @return void */ function errorPush($errNum = T3_ERR_SV_GENERAL, $errMsg = 'Unspecified error occured') { @@ -281,15 +282,15 @@ /** * Returns the last error number from the error stack. * - * @return string error number + * @return int|bool error number (or TRUE if no error) */ function getLastError() { + $lastError = TRUE; // means all is ok - no error if (count($this->error)) { $error = end($this->error); - return $error['nr']; - } else { - return TRUE; // means all is ok - no error + $lastError = $error['nr']; } + return $lastError; } @@ -299,12 +300,12 @@ * @return string error message */ function getLastErrorMsg() { + $lastErrorMessage = ''; if (count($this->error)) { $error = end($this->error); - return $error['msg']; - } else { - return ''; + $lastErrorMessage = $error['msg']; } + return $lastErrorMessage; } @@ -317,7 +318,6 @@ $errArr = array(); if (count($this->error)) { - reset($this->error); foreach ($this->error as $error) { $errArr[] = $error['msg']; } @@ -365,7 +365,7 @@ foreach ($progList as $prog) { if (!t3lib_exec::checkCommand($prog)) { // program not found - $this->errorPush('External program not found: ' . $prog, T3_ERR_SV_PROG_NOT_FOUND); + $this->errorPush(T3_ERR_SV_PROG_NOT_FOUND, 'External program not found: ' . $prog); $ret = FALSE; } } @@ -394,19 +394,20 @@ * Check if a file exists and is readable. * * @param string File name with absolute path. - * @return string File name or FALSE. + * @return string|bool File name or FALSE. */ function checkInputFile($absFile) { + $checkResult = FALSE; if (t3lib_div::isAllowedAbsPath($absFile) && @is_file($absFile)) { if (@is_readable($absFile)) { - return $absFile; + $checkResult = $absFile; } else { $this->errorPush(T3_ERR_SV_FILE_READ, 'File is not readable: ' . $absFile); } } else { $this->errorPush(T3_ERR_SV_FILE_NOT_FOUND, 'File not found: ' . $absFile); } - return FALSE; + return $checkResult; } @@ -415,7 +416,7 @@ * * @param string File name to read from. * @param integer Maximum length to read. If empty the whole file will be read. - * @return string $content or FALSE + * @return string|bool $content or FALSE */ function readFile($absFile, $length = 0) { $out = FALSE; @@ -435,11 +436,9 @@ * * @param string Content to write to the file * @param string File name to write into. If empty a temp file will be created. - * @return string File name or FALSE + * @return string|bool File name or FALSE */ function writeFile($content, $absFile = '') { - $ret = TRUE; - if (!$absFile) { $absFile = $this->tempFile($this->prefixId); } @@ -461,18 +460,18 @@ * Create a temporary file. * * @param string File prefix. - * @return string File name or FALSE + * @return string|bool File name or FALSE */ function tempFile($filePrefix) { $absFile = t3lib_div::tempnam($filePrefix); if ($absFile) { - $ret = TRUE; + $ret = $absFile; $this->registerTempFile($absFile); } else { $ret = FALSE; $this->errorPush(T3_ERR_SV_FILE_WRITE, 'Can not create temp file.'); } - return ($ret ? $absFile : FALSE); + return $ret; } /** @@ -626,6 +625,7 @@ */ function init() { // do not work :-( but will not hurt + // use it as inspiration for a service based on this class register_shutdown_function(array(&$this, '__destruct')); // look in makeInstanceService() @@ -660,6 +660,7 @@ /** * Clean up the service. + * Child classes should explicitly call parent::__destruct() in their destructors for this to work * * @return void */ @@ -667,19 +668,7 @@ $this->unlinkTempFiles(); } - - /* every service type has it's own API - function process($content='', $type='', $conf=array()) { // - } - */ - } -/** -// Does not make sense, because this class is always extended by the service classes.. -if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["t3lib/class.t3lib_svbase.php"]) { -include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["t3lib/class.t3lib_svbase.php"]); -} - */ - +// XCLASS handling does not make sense, because this class is always extended by the service classes.. ?> \ No newline at end of file