Main Page | Directories | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages | Examples

t3lib_svbase Class Reference

Inherited by tx_sv_authbase.

List of all members.

Public Member Functions

 getServiceInfo ()
 getServiceKey ()
 getServiceTitle ()
 getServiceOption ($optionName, $defaultValue='', $includeDefaultConfig=TRUE)
 Returns service configuration values from the $TYPO3_CONF_VARS['SVCONF'] array.
 devLog ($msg, $severity=0, $dataVar=FALSE)
 Logs debug messages to t3lib_div::devLog().
 errorPush ($errNum=T3_ERR_SV_GENERAL, $errMsg='Unspecified error occured')
 Puts an error on the error stack.
 errorPull ()
 Removes the last error from the error stack.
 getLastError ()
 Returns the last error number from the error stack.
 getLastErrorMsg ()
 Returns the last message from the error stack.
 getErrorMsgArray ()
 Returns all error messages as array.
 getLastErrorArray ()
 Returns the last array from the error stack.
 resetErrors ()
 Reset the error stack.
 checkExec ($progList)
 check the availability of external programs
 deactivateService ()
 Deactivate the service.
 checkInputFile ($absFile)
 Check if a file exists and is readable.
 readFile ($absFile, $length=0)
 Read content from a file a file.
 writeFile ($content, $absFile='')
 Write content to a file.
 tempFile ($filePrefix)
 Create a temporary file.
 registerTempFile ($absFile)
 Register file which should be deleted afterwards.
 unlinkTempFiles ()
 Delete registered temporary files.
 setInput ($content, $type='')
 Set the input content for service processing.
 setInputFile ($absFile, $type='')
 Set the input file name for service processing.
 getInput ()
 Get the input content.
 getInputFile ($createFile='')
 Get the input file name.
 setOutputFile ($absFile)
 Set the output file name.
 getOutput ()
 Get the output content.
 getOutputFile ($absFile='')
 Get the output file name.
 init ()
 Initialization of the service.
 reset ()
 Resets the service.
 __destruct ()
 Clean up the service.

Public Attributes

 $info = array()
 service description array
 $error = array()
 error stack
 $writeDevLog = false
 Defines if debug messages should be written with t3lib_div::devLog.
 $out = ''
 The output content.
 $inputFile = ''
 The file that should be processed.
 $inputContent = ''
 The content that should be processed.
 $inputType = ''
 The type of the input content (or file).
 $outputFile = ''
 The file where the output should be written to.


Member Function Documentation

t3lib_svbase::__destruct  ) 
 

Clean up the service.

Returns:
void

Definition at line 715 of file class.t3lib_svbase.php.

References unlinkTempFiles().

Referenced by init().

00715                          {
00716       $this->unlinkTempFiles();
00717    }

t3lib_svbase::checkExec progList  ) 
 

check the availability of external programs

Parameters:
string comma list of programs 'perl,python,pdftotext'
Returns:
boolean return FALSE if one program was not found

Definition at line 373 of file class.t3lib_svbase.php.

References t3lib_exec::checkCommand(), errorPush(), PATH_t3lib, and T3_ERR_SV_PROG_NOT_FOUND.

Referenced by init().

00373                                  {
00374       $ret = TRUE;
00375 
00376       require_once(PATH_t3lib.'class.t3lib_exec.php');
00377 
00378       $progList = t3lib_div::trimExplode(',', $progList, 1);
00379       foreach($progList as $prog) {
00380          if (!t3lib_exec::checkCommand($prog)) {
00381                // program not found
00382             $this->errorPush('External program not found: '.$prog, T3_ERR_SV_PROG_NOT_FOUND);
00383             $ret = FALSE;
00384          }
00385       }
00386       return $ret;
00387    }

t3lib_svbase::checkInputFile absFile  ) 
 

Check if a file exists and is readable.

Parameters:
string File name with absolute path.
Returns:
string File name or FALSE.

Definition at line 439 of file class.t3lib_svbase.php.

References errorPush(), T3_ERR_SV_FILE_NOT_FOUND, and T3_ERR_SV_FILE_READ.

Referenced by getInputFile(), and readFile().

00439                                        {
00440       if(@is_file($absFile)) {
00441          if(@is_readable($absFile)) {
00442             return $absFile;
00443          } else {
00444             $this->errorPush(T3_ERR_SV_FILE_READ, 'File is not readable: '.$absFile);
00445          }
00446       } else {
00447          $this->errorPush(T3_ERR_SV_FILE_NOT_FOUND, 'File not found: '.$absFile);
00448       }
00449       return FALSE;
00450    }

t3lib_svbase::deactivateService  ) 
 

Deactivate the service.

Use this if the service fails at runtime and will not be available.

Returns:
void

Definition at line 395 of file class.t3lib_svbase.php.

References t3lib_extMgm::deactivateService().

00395                                 {
00396       t3lib_extMgm::deactivateService($this->info['serviceType'], $this->info['serviceKey']);
00397    }

t3lib_svbase::devLog msg,
severity = 0,
dataVar = FALSE
 

Logs debug messages to t3lib_div::devLog().

Parameters:
string Debug message
integer Severity: 0 is info, 1 is notice, 2 is warning, 3 is fatal error, -1 is "OK" message
array Additional data you want to pass to the logger.
Returns:
void

Definition at line 255 of file class.t3lib_svbase.php.

00255                                                       {
00256       if($this->writeDevLog) {
00257          t3lib_div::devLog($msg, $this->info['serviceKey'], $severity, $dataVar);
00258       }
00259    }

t3lib_svbase::errorPull  ) 
 

Removes the last error from the error stack.

Returns:
void

Definition at line 284 of file class.t3lib_svbase.php.

00284                         {
00285       array_pop($this->error);
00286 
00287       // pop for $GLOBALS['TT']->setTSlogMessage is not supported
00288    }

t3lib_svbase::errorPush errNum = T3_ERR_SV_GENERAL,
errMsg = 'Unspecified error occured'
 

Puts an error on the error stack.

Calling without parameter adds a general error.

Parameters:
string error message
string error number (see T3_ERR_SV_* constants)
Returns:
void

Definition at line 269 of file class.t3lib_svbase.php.

Referenced by checkExec(), checkInputFile(), readFile(), tempFile(), and writeFile().

00269                                                                                       {
00270       array_push($this->error, array('nr'=>$errNum, 'msg'=>$errMsg));
00271 
00272       if (is_object($GLOBALS["TT"])) {
00273          $GLOBALS['TT']->setTSlogMessage($errMsg,2);
00274       }
00275 
00276    }

t3lib_svbase::getErrorMsgArray  ) 
 

Returns all error messages as array.

Returns:
array error messages

Definition at line 326 of file class.t3lib_svbase.php.

References $error, error(), and reset().

00326                                {
00327       $errArr = array();
00328 
00329       if(count($this->error)) {
00330          reset($this->error);
00331          foreach($this->error as $error) {
00332             $errArr[] = $error['msg'];
00333          }
00334       }
00335       return $errArr;
00336    }

t3lib_svbase::getInput  ) 
 

Get the input content.

Will be read from input file if needed.

Returns:
mixed

Definition at line 588 of file class.t3lib_svbase.php.

References readFile().

00588                         {
00589       if ($this->inputContent=='') {
00590          $this->inputContent = $this->readFile($this->inputFile);
00591       }
00592       return $this->inputContent;
00593    }

t3lib_svbase::getInputFile createFile = ''  ) 
 

Get the input file name.

If the content was set by setContent a file will be created.

Parameters:
string File name. If empty a temp file will be created.
Returns:
string File name or FALSE if no input or file error.

Definition at line 603 of file class.t3lib_svbase.php.

References checkInputFile(), and writeFile().

00603                                           {
00604       if($this->inputFile) {
00605          $this->inputFile = $this->checkInputFile($this->inputFile);
00606       } elseif ($this->inputContent) {
00607          $this->inputFile = $this->writeFile($this->inputContent, $createFile);
00608       }
00609       return $this->inputFile;
00610    }

t3lib_svbase::getLastError  ) 
 

Returns the last error number from the error stack.

Returns:
string error number

Definition at line 296 of file class.t3lib_svbase.php.

References $error.

Referenced by init().

00296                            {
00297       if(count($this->error)) {
00298          $error = end($this->error);
00299          return $error['nr'];
00300       } else {
00301          return TRUE; // means all is ok - no error
00302       }
00303    }

t3lib_svbase::getLastErrorArray  ) 
 

Returns the last array from the error stack.

Returns:
array error nr and message

Definition at line 344 of file class.t3lib_svbase.php.

00344                                 {
00345       return end($this->error);
00346    }

t3lib_svbase::getLastErrorMsg  ) 
 

Returns the last message from the error stack.

Returns:
string error message

Definition at line 311 of file class.t3lib_svbase.php.

References $error.

00311                               {
00312       if(count($this->error)) {
00313          $error = end($this->error);
00314          return $error['msg'];
00315       } else {
00316          return '';
00317       }
00318    }

t3lib_svbase::getOutput  ) 
 

Get the output content.

Returns:
mixed

Definition at line 638 of file class.t3lib_svbase.php.

References readFile().

00638                          {
00639       if ($this->outputFile) {
00640          $this->out = $this->readFile($this->outputFile);
00641       }
00642       return $this->out;
00643    }

t3lib_svbase::getOutputFile absFile = ''  ) 
 

Get the output file name.

Parameters:
[type] $absFile: ...
Returns:
mixed

Definition at line 652 of file class.t3lib_svbase.php.

References writeFile().

00652                                         {
00653       if (!$this->outputFile) {
00654          $this->outputFile = $this->writeFile($this->out, $absFile);
00655       }
00656       return $this->outputFile;
00657    }

t3lib_svbase::getServiceInfo  ) 
 

Returns:
array service description array

Definition at line 191 of file class.t3lib_svbase.php.

00191                              {
00192       return $this->info;
00193    }

t3lib_svbase::getServiceKey  ) 
 

Returns:
string service key

Definition at line 199 of file class.t3lib_svbase.php.

00199                             {
00200       return $this->info['serviceKey'];
00201    }

t3lib_svbase::getServiceOption optionName,
defaultValue = '',
includeDefaultConfig = TRUE
 

Returns service configuration values from the $TYPO3_CONF_VARS['SVCONF'] array.

Parameters:
string Name of the config option
boolean If set the 'default' config will be return if no special config for this service is available (default: true)
[type] $includeDefaultConfig: ...
Returns:
mixed configuration value for the service

Definition at line 220 of file class.t3lib_svbase.php.

References $TYPO3_CONF_VARS.

Referenced by tx_sv_authbase::initAuth().

00220                                                                                         {
00221       global $TYPO3_CONF_VARS;
00222 
00223       $config = NULL;
00224 
00225       $svOptions = $TYPO3_CONF_VARS['SVCONF'][$this->info['serviceType']];
00226 
00227       if(isset($svOptions[$this->info['serviceKey']][$optionName])) {
00228          $config = $svOptions['default'][$optionName];
00229       } elseif($includeDefaultConfig AND isset($svOptions['default'][$optionName])) {
00230          $config = $svOptions['default'][$optionName];
00231       }
00232       if(!isset($config)) {
00233          $config = $defaultValue;
00234       }
00235       return $config;
00236    }

t3lib_svbase::getServiceTitle  ) 
 

Returns:
string service title

Definition at line 207 of file class.t3lib_svbase.php.

00207                               {
00208       return $this->info['title'];
00209    }

t3lib_svbase::init  ) 
 

Initialization of the service.

The class have to do a strict check if the service is available. example: check if the perl interpreter is available which is needed to run an extern perl script.

Returns:
boolean TRUE if the service is available

Definition at line 676 of file class.t3lib_svbase.php.

References __destruct(), checkExec(), getLastError(), and reset().

00676                      {
00677       // do not work :-(  but will not hurt
00678       register_shutdown_function(array(&$this, '__destruct'));
00679       // look in makeInstanceService()
00680 
00681       $this->reset();
00682 
00683          // check for external programs which are defined by $info['exec']
00684       if (trim($this->info['exec'])) {
00685          if (!$this->checkExec($this->info['exec'])) {
00686             // nothing todo here or?
00687          }
00688       }
00689 
00690       return $this->getLastError();
00691    }

t3lib_svbase::readFile absFile,
length = 0
 

Read content from a file a file.

Parameters:
string File name to read from.
integer Maximum length to read. If empty the whole file will be read.
Returns:
string $content or FALSE

Definition at line 460 of file class.t3lib_svbase.php.

References $out, checkInputFile(), errorPush(), and T3_ERR_SV_FILE_READ.

Referenced by getInput(), and getOutput().

00460                                              {
00461       $out = FALSE;
00462 
00463       if ($this->checkInputFile ($absFile)) {
00464          if ($fd = fopen ($absFile, 'rb')) {
00465             $length = intval($length) ? intval($length) : filesize ($absFile);
00466             if ($length > 0) {
00467                $out = fread ($fd, $length);
00468             }
00469             fclose ($fd);
00470          } else {
00471             $this->errorPush(T3_ERR_SV_FILE_READ, 'Can not read from file: '.$absFile);
00472          }
00473       }
00474       return $out;
00475    }

t3lib_svbase::registerTempFile absFile  ) 
 

Register file which should be deleted afterwards.

Parameters:
string File name with absolute path.
Returns:
void

Definition at line 529 of file class.t3lib_svbase.php.

Referenced by tempFile().

00529                                           {
00530       $this->tempFiles[] = $absFile;
00531    }

t3lib_svbase::reset  ) 
 

Resets the service.

Will be called by init(). Should be used before every use if a service instance is used multiple times.

Returns:
void

Definition at line 700 of file class.t3lib_svbase.php.

References resetErrors(), and unlinkTempFiles().

Referenced by getErrorMsgArray(), and init().

00700                      {
00701       $this->unlinkTempFiles();
00702       $this->resetErrors();
00703       $this->out = '';
00704       $this->inputFile = '';
00705       $this->inputContent = '';
00706       $this->inputType = '';
00707       $this->outputFile = '';
00708    }

t3lib_svbase::resetErrors  ) 
 

Reset the error stack.

Returns:
void

Definition at line 353 of file class.t3lib_svbase.php.

References error().

Referenced by reset().

00353                           {
00354       $this->error=array();
00355    }

t3lib_svbase::setInput content,
type = ''
 

Set the input content for service processing.

Parameters:
mixed 
[type] $type: ...
Returns:
[type] ...

Definition at line 561 of file class.t3lib_svbase.php.

00561                                           {
00562       $this->inputContent = $content;
00563       $this->inputFile = '';
00564       $this->inputType = $type;
00565    }

t3lib_svbase::setInputFile absFile,
type = ''
 

Set the input file name for service processing.

Parameters:
string file name
[type] $type: ...
Returns:
[type] ...

Definition at line 575 of file class.t3lib_svbase.php.

00575                                               {
00576       $this->inputContent = '';
00577       $this->inputFile = $absFile;
00578       $this->inputType = $type;
00579    }

t3lib_svbase::setOutputFile absFile  ) 
 

Set the output file name.

Parameters:
string file name
Returns:
[type] ...

Definition at line 628 of file class.t3lib_svbase.php.

00628                                      {
00629       $this->outputFile = $absFile;
00630    }

t3lib_svbase::tempFile filePrefix  ) 
 

Create a temporary file.

Parameters:
string File prefix.
Returns:
string File name or FALSE

Definition at line 511 of file class.t3lib_svbase.php.

References errorPush(), registerTempFile(), and T3_ERR_SV_FILE_WRITE.

Referenced by writeFile().

00511                                     {
00512       $absFile = t3lib_div::tempnam($filePrefix);
00513       if($absFile) {
00514          $ret = TRUE;
00515          $this->registerTempFile ($absFile);
00516       } else {
00517          $ret = FALSE;
00518          $this->errorPush(T3_ERR_SV_FILE_WRITE, 'Can not create temp file.');
00519       }
00520       return ($ret ? $absFile : FALSE);
00521    }

t3lib_svbase::unlinkTempFiles  ) 
 

Delete registered temporary files.

Parameters:
string File name with absolute path.
Returns:
void

Definition at line 539 of file class.t3lib_svbase.php.

Referenced by __destruct(), and reset().

00539                                  {
00540       foreach ($this->tempFiles as $absFile) {
00541          t3lib_div::unlink_tempfile($absFile);
00542       }
00543       $this->tempFiles = array();
00544    }

t3lib_svbase::writeFile content,
absFile = ''
 

Write content to a file.

Parameters:
string Content to write to the file
string File name to write into. If empty a temp file will be created.
Returns:
string File name or FALSE

Definition at line 485 of file class.t3lib_svbase.php.

References errorPush(), T3_ERR_SV_FILE_WRITE, and tempFile().

Referenced by getInputFile(), and getOutputFile().

00485                                                 {
00486       $ret = TRUE;
00487 
00488       if (!$absFile) {
00489          $absFile = $this->tempFile($this->prefixId);
00490       }
00491 
00492       if($absFile) {
00493          if ($fd = @fopen($absFile,'wb')) {
00494             @fwrite($fd, $content);
00495             @fclose($fd);
00496          } else {
00497             $this->errorPush(T3_ERR_SV_FILE_WRITE, 'Can not write to file: '.$absFile);
00498             $absFile = FALSE;
00499          }
00500       }
00501 
00502       return $absFile;
00503    }


Member Data Documentation

t3lib_svbase::$error = array()
 

error stack

Definition at line 137 of file class.t3lib_svbase.php.

Referenced by getErrorMsgArray(), getLastError(), and getLastErrorMsg().

t3lib_svbase::$info = array()
 

service description array

Reimplemented in tx_sv_authbase.

Definition at line 132 of file class.t3lib_svbase.php.

t3lib_svbase::$inputContent = ''
 

The content that should be processed.

Definition at line 159 of file class.t3lib_svbase.php.

t3lib_svbase::$inputFile = ''
 

The file that should be processed.

Definition at line 154 of file class.t3lib_svbase.php.

t3lib_svbase::$inputType = ''
 

The type of the input content (or file).

Might be the same as the service subtypes.

Definition at line 164 of file class.t3lib_svbase.php.

t3lib_svbase::$out = ''
 

The output content.

That's what the services produced as result.

Definition at line 149 of file class.t3lib_svbase.php.

Referenced by readFile().

t3lib_svbase::$outputFile = ''
 

The file where the output should be written to.

Definition at line 169 of file class.t3lib_svbase.php.

t3lib_svbase::$writeDevLog = false
 

Defines if debug messages should be written with t3lib_div::devLog.

Definition at line 142 of file class.t3lib_svbase.php.


The documentation for this class was generated from the following file:
Generated on Sun Oct 3 01:07:15 2004 for TYPO3core 3.7.0 dev by  doxygen 1.3.8-20040913