*/ /** * [CLASS/FUNCTION INDEX of SCRIPT] * * * * 54: class tx_ter_pi1 extends tslib_pibase * 61: function main ($content, $conf) * * TOTAL FUNCTIONS: 1 * (This index is automatically created/updated by the extension "extdeveval") */ use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; use TYPO3\CMS\Frontend\Plugin\AbstractPlugin; require_once(ExtensionManagementUtility::extPath('ter') . 'class.tx_ter_api.php'); /** * TYPO3 Extension Repository, frontend plugin for SOAP service * * @author Robert Lemke */ class tx_ter_pi1 extends AbstractPlugin { public $cObj; // Standard cObj (parent) public $extensionsPID; // Start page for extension records public $wsdlNamespace; // Namespace public $repositoryDir; // Absolute path to extension repository directory public $conf; // The FE Plugin's TS configuration public function main($content, $conf) { global $TSFE; $this->pi_initPIflexForm(); $this->conf = $conf; $this->extensionsPID = $conf['pid']; $this->wsdlNamespace = $conf['wsdlNamespace']; $staticConfArr = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['ter']); if (is_array($staticConfArr)) { $this->repositoryDir = $staticConfArr['repositoryDir']; if (substr($this->repositoryDir, -1, 1) != '/') { $this->repositoryDir .= '/'; } } try { $server = new SoapServer(null, ['uri' => $this->wsdlNamespace, 'trace' => true, 'exceptions' => true]); $server->setClass(\tx_ter_api::class, $this); $server->handle(file_get_contents('php://input')); // Due to different behaviour on stage and prod server we need this exit to prevent wrong XML response exit(); } catch (\T3o\Ter\Exception\Exception $e) { /** * @author Christian Zenker * @see http://forge.typo3.org/issues/44135 * * SoapServer is a little nasty. When you throw a SoapFault (extends Exception) inside a soap call, * you won't have any possible chance of catching and handling that exception. SoapServer will instantly * return a 500 InternalServerError without any way of intervention. * * That's why there is an own set of exceptions defined that basically stand for a status code. */ $statusCode = 404; if ($e instanceof \T3o\Ter\Exception\UnauthorizedException) { $statusCode = 401; } elseif ($e instanceof \T3o\Ter\Exception\NotFoundException) { $statusCode = 404; } elseif ($e instanceof \T3o\Ter\Exception\FailedDependencyException) { $statusCode = 424; } elseif ($e instanceof \T3o\Ter\Exception\InternalServerErrorException) { $statusCode = 500; error_log(sprintf('TER Server internal error occurred. Error message is: "%s"', $e->getMessage())); } header(' ', true, $statusCode); /** * Using $server->fault will cause a http 500 status code to be sent which in turn * will trigger the web server's error page to be shown, instead of the SOAP XML * The header sent above will just be ignored. * Because of that, we forge a SOAP Fault XML ourselves and just echo it. * * flush() to prevent SoapServer to change the status code obviously also does not work * This fails when some other kind of output buffering is in place (e.g. for gzip compression) * in the web server. */ // flush to prevent Soap to change the status code (does not work) // flush(); // $server->fault($e->getCode(), $e->getMessage()); $faultStringXmlTemplate = ' %s %s '; echo sprintf($faultStringXmlTemplate, $e->getCode(), $e->getMessage()); exit; } return ''; } }