17 use Psr\Log\LoggerAwareInterface;
18 use Psr\Log\LoggerAwareTrait;
136 return $this->info[
'serviceKey'];
146 return $this->info[
'title'];
157 public function getServiceOption($optionName, $defaultValue =
'', $includeDefaultConfig =
true)
160 $serviceType = $this->info[
'serviceType'] ??
'';
161 $serviceKey = $this->info[
'serviceKey'] ??
'';
162 $svOptions =
$GLOBALS[
'TYPO3_CONF_VARS'][
'SVCONF'][$serviceType] ?? [];
163 if (isset($svOptions[$serviceKey][$optionName])) {
164 $config = $svOptions[$serviceKey][$optionName];
165 } elseif ($includeDefaultConfig && isset($svOptions[
'default'][$optionName])) {
166 $config = $svOptions[
'default'][$optionName];
168 if (!isset($config)) {
169 $config = $defaultValue;
187 public function devLog($msg, $severity = 0, $dataVar =
false)
189 trigger_error(
'AbstractService->devLog() will be removed with TYPO3 v10.0.', E_USER_DEPRECATED);
190 $this->logger->debug($this->info[
'serviceKey'] .
': ' . $msg, (array)$dataVar);
199 public function errorPush($errNum = self::ERROR_GENERAL, $errMsg =
'Unspecified error occurred')
201 $this->error[] = [
'nr' => $errNum,
'msg' => $errMsg];
203 $timeTracker = GeneralUtility::makeInstance(TimeTracker::class);
204 $timeTracker->setTSlogMessage($errMsg, 2);
212 array_pop($this->error);
224 if (!empty($this->error)) {
238 $lastErrorMessage =
'';
239 if (!empty($this->error)) {
243 return $lastErrorMessage;
254 if (!empty($this->error)) {
255 foreach ($this->error as
$error) {
269 return end($this->error);
294 $progList = GeneralUtility::trimExplode(
',', $progList,
true);
295 foreach ($progList as $prog) {
298 $this->
errorPush(self::ERROR_PROGRAM_NOT_FOUND,
'External program not found: ' . $prog);
326 $checkResult =
false;
327 if (GeneralUtility::isAllowedAbsPath($absFile) && @is_file($absFile)) {
328 if (@is_readable($absFile)) {
329 $checkResult = $absFile;
331 $this->
errorPush(self::ERROR_FILE_NOT_READABLE,
'File is not readable: ' . $absFile);
334 $this->
errorPush(self::ERROR_FILE_NOT_FOUND,
'File not found: ' . $absFile);
346 public function readFile($absFile, $length = 0)
350 $out = file_get_contents($absFile);
351 if (
$out ===
false) {
352 $this->
errorPush(self::ERROR_FILE_NOT_READABLE,
'Can not read from file: ' . $absFile);
365 public function writeFile($content, $absFile =
'')
368 $absFile = $this->
tempFile($this->prefixId);
370 if ($absFile && GeneralUtility::isAllowedAbsPath($absFile)) {
371 if ($fd = @fopen($absFile,
'wb')) {
372 @fwrite($fd, $content);
375 $this->
errorPush(self::ERROR_FILE_NOT_WRITEABLE,
'Can not write to file: ' . $absFile);
390 $absFile = GeneralUtility::tempnam($filePrefix);
396 $this->
errorPush(self::ERROR_FILE_NOT_WRITEABLE,
'Can not create temp file.');
408 if (!isset($this->shutdownRegistry[__METHOD__])) {
409 register_shutdown_function([$this,
'unlinkTempFiles']);
410 $this->shutdownRegistry[__METHOD__] =
true;
412 $this->tempFiles[] = $absFile;
420 foreach ($this->tempFiles as $absFile) {
421 GeneralUtility::unlink_tempfile($absFile);
423 $this->tempFiles = [];
437 public function setInput($content, $type =
'')
439 $this->inputContent = $content;
440 $this->inputFile =
'';
441 $this->inputType = $type;
452 $this->inputContent =
'';
453 $this->inputFile = $absFile;
454 $this->inputType = $type;
465 if ($this->inputContent ==
'') {
466 $this->inputContent = $this->
readFile($this->inputFile);
480 if ($this->inputFile) {
482 } elseif ($this->inputContent) {
483 $this->inputFile = $this->
writeFile($this->inputContent, $createFile);
500 $this->outputFile = $absFile;
510 if ($this->outputFile) {
511 $this->out = $this->
readFile($this->outputFile);
524 if (!$this->outputFile) {
525 $this->outputFile = $this->
writeFile($this->out, $absFile);
543 public function init()
548 if (trim($this->info[
'exec'])) {
563 $this->inputFile =
'';
564 $this->inputContent =
'';
565 $this->inputType =
'';
566 $this->outputFile =
'';