Commit c5a15264 authored by Benni Mack's avatar Benni Mack
Browse files

[TASK] Add Namespace to SOAP API handler class

With the recent changes, the SOAP API is pretty much isolated and only
called within one place now, so adding a proper PSR-4 namespace
is finally possible with only a few minor changes.
parent f9037696
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "beb332821650c92fae99c064d5f24889",
"content-hash": "fb5c8a93daadb2f64f4b3101ea1fc7ba",
"packages": [
{
"name": "adoy/fastcgi-client",
......@@ -4101,54 +4101,6 @@
"relative": true
}
},
{
"name": "t3o/ter-soap",
"version": "2.0.9",
"dist": {
"type": "path",
"url": "extensions/ter",
"reference": "2bf4b5ee6918d817b55e124f5857aa9e28d14fd5"
},
"require": {
"typo3/cms-core": "^8.7 || ^9.5"
},
"replace": {
"ter": "self.version"
},
"type": "typo3-cms-extension",
"autoload": {
"psr-4": {
"T3o\\Ter\\": "Classes/"
},
"classmap": [
"Classes",
"pi1",
"class.tx_ter_api.php"
]
},
"license": [
"GPL-2.0+"
],
"authors": [
{
"name": "t3o team",
"email": "maintenance@typo3.org"
}
],
"description": "This extension provides extension listing and detail view, plus management of extension keys",
"keywords": [
"Extensions",
"TER",
"TYPO3 CMS"
],
"support": {
"email": "maintenance@typo3.org",
"issues": "https://git-t3o.typo3.org/t3o/ter/issues"
},
"transport-options": {
"relative": true
}
},
{
"name": "typo3/class-alias-loader",
"version": "v1.1.3",
......
<?php
namespace T3o\Ter\Soap;
/*
* This file is part of the TYPO3 CMS project.
*
......@@ -12,15 +14,22 @@
* The TYPO3 project - inspiring people to share!
*/
/**
* SOAP server for the TYPO3 Extension Repository
*
* @author Robert Lemke <robert@typo3.org>
*/
use Psr\Log\LoggerAwareTrait;
use T3o\Ter\Api\ApiUser;
use T3o\Ter\Api\ExtensionKey;
use T3o\Ter\Api\ExtensionVersion;
use T3o\Ter\Api\ResultCodes;
use T3o\Ter\Exception\Exception;
use T3o\Ter\Exception\ExtensionKeyAlreadyInUseException;
use T3o\Ter\Exception\ExtensionKeyNotFoundException;
use T3o\Ter\Exception\InternalServerErrorException;
use T3o\Ter\Exception\InvalidExtensionKeyFormatException;
use T3o\Ter\Exception\NotFoundException;
use T3o\Ter\Exception\UnauthorizedException;
use T3o\Ter\Exception\UserNotFoundException;
use T3o\Ter\Exception\VersionExistsException;
use T3o\TerFe2\Service\ExtensionIndexService;
use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
......@@ -28,13 +37,13 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
*
* @author Robert Lemke <robert@typo3.org>
*/
class tx_ter_api
class TerSoapV1Handler
{
use \Psr\Log\LoggerAwareTrait;
use LoggerAwareTrait;
public function __construct()
{
$this->setLogger(GeneralUtility::makeInstance(\TYPO3\CMS\Core\Log\LogManager::class)->getLogger('TER\API\SOAP'));
$this->setLogger(GeneralUtility::makeInstance(LogManager::class)->getLogger('TER\API\SOAP'));
}
/*********************************************************
......@@ -71,7 +80,7 @@ class tx_ter_api
try {
$user = ApiUser::createFromSoapAccountData($accountData);
$user->authenticate();
} catch (\T3o\Ter\Exception\UnauthorizedException $e) {
} catch (UnauthorizedException $e) {
return false;
}
return $user->isAuthenticated();
......@@ -85,8 +94,8 @@ class tx_ter_api
* @param object $filesData : The array of file data objects as received by the SOAP server
*
* @return array|object uploadExtensionResult object if upload was successful, otherwise an exception is thrown.
* @throws \T3o\Ter\Exception\Exception
* @throws \T3o\Ter\Exception\VersionExistsException
* @throws Exception
* @throws VersionExistsException
* @access public
* @since 2.0.0
*/
......@@ -110,14 +119,14 @@ class tx_ter_api
$this->logger->info('Upload of extension ' . ((string)$extensionKey) . ' (' . $version->getVersion() . ') by user ' . $user->getUsername());
if ($version->doesExtensionVersionExist()) {
throw new \T3o\Ter\Exception\VersionExistsException(
throw new VersionExistsException(
'Version number ' . htmlspecialchars($version->getVersion()) . ' already exists in repository.',
ResultCodes::ERROR_UPLOADEXTENSION_EXTENSIONVERSIONEXISTS
);
}
if (!is_array($filesData->fileData)) {
throw new \T3o\Ter\Exception\NotFoundException('Extension contains no files.', ResultCodes::ERROR_GENERAL_EXTENSIONCONTAINSNOFILES);
throw new NotFoundException('Extension contains no files.', ResultCodes::ERROR_GENERAL_EXTENSIONCONTAINSNOFILES);
}
$version->upload($user, $extensionInfoData, $filesData->fileData);
$this->requestUpdateOfExtensionIndexFile();
......@@ -139,8 +148,8 @@ class tx_ter_api
* @param string $version : Version string of the extension version to delete
*
* @return array|object simpleResult object if extension could be deleted, otherwise an exception is thrown.
* @throws \T3o\Ter\Exception\UnauthorizedException
* @throws \T3o\Ter\Exception\NotFoundException
* @throws UnauthorizedException
* @throws NotFoundException
* @access public
* @since 2.0.1
*/
......@@ -153,7 +162,7 @@ class tx_ter_api
$extensionKeyObject = new ExtensionKey($extensionKey);
if (!$extensionKeyObject->isRegistered()) {
throw new \T3o\Ter\Exception\NotFoundException(
throw new NotFoundException(
'Extension does not exist.',
ResultCodes::ERROR_DELETEEXTENSION_EXTENSIONDOESNTEXIST
);
......@@ -211,13 +220,13 @@ class tx_ter_api
$registerExtensionKeyData->ownerUsername ?? $user->getUsername()
);
$resultCode = ResultCodes::RESULT_EXTENSIONKEYSUCCESSFULLYREGISTERED;
} catch (\T3o\Ter\Exception\InvalidExtensionKeyFormatException $e) {
} catch (InvalidExtensionKeyFormatException $e) {
$resultCode = ResultCodes::RESULT_EXTENSIONKEYNOTVALID;
} catch (\T3o\Ter\Exception\UnauthorizedException $e) {
} catch (UnauthorizedException $e) {
$resultCode = $e->getCode();
} catch (\T3o\Ter\Exception\UserNotFoundException $e) {
} catch (UserNotFoundException $e) {
$resultCode = ResultCodes::ERROR_GENERAL_USERNOTFOUND;
} catch (\T3o\Ter\Exception\ExtensionKeyAlreadyInUseException $e) {
} catch (ExtensionKeyAlreadyInUseException $e) {
$resultCode = ResultCodes::RESULT_EXTENSIONKEYALREADYEXISTS;
}
return $this->formatAsSimpleResult($resultCode);
......@@ -267,8 +276,8 @@ class tx_ter_api
* @return array|object simpleResponse-object. An exception is thrown if a fatal error occurred.
* @access public
* @since 2.0.0
* @throws \T3o\Ter\Exception\InternalServerErrorException
* @throws \T3o\Ter\Exception\UnauthorizedException
* @throws InternalServerErrorException
* @throws UnauthorizedException
*/
public function deleteExtensionKey($accountData, $extensionKey)
{
......@@ -280,7 +289,7 @@ class tx_ter_api
try {
$extensionKeyObject->unregister($user);
$resultCode = ResultCodes::RESULT_GENERAL_OK;
} catch (\T3o\Ter\Exception\VersionExistsException $e) {
} catch (VersionExistsException $e) {
$resultCode = ResultCodes::ERROR_DELETEEXTENSIONKEY_CANTDELETEBECAUSEVERSIONSEXIST;
}
} else {
......@@ -299,7 +308,7 @@ class tx_ter_api
* @return array|object simpleResponse-object. An exception is thrown if a fatal error occurred.
* @access public
* @since 2.0.0
* @throws \T3o\Ter\Exception\UnauthorizedException
* @throws UnauthorizedException
*/
public function modifyExtensionKey($accountData, $modifyExtensionKeyData)
{
......@@ -318,11 +327,11 @@ class tx_ter_api
);
$this->requestUpdateOfExtensionIndexFile();
$resultCode = ResultCodes::RESULT_GENERAL_OK;
} catch (\T3o\Ter\Exception\UnauthorizedException $e) {
throw new \T3o\Ter\Exception\UnauthorizedException('Access denied.', ResultCodes::ERROR_MODIFYEXTENSIONKEY_ACCESSDENIED);
} catch (\T3o\Ter\Exception\UserNotFoundException $e) {
} catch (UnauthorizedException $e) {
throw new UnauthorizedException('Access denied.', ResultCodes::ERROR_MODIFYEXTENSIONKEY_ACCESSDENIED);
} catch (UserNotFoundException $e) {
$resultCode = $e->getCode();
} catch (\T3o\Ter\Exception\ExtensionKeyNotFoundException $e) {
} catch (ExtensionKeyNotFoundException $e) {
$resultCode = $e->getCode();
}
}
......@@ -338,8 +347,8 @@ class tx_ter_api
*
* @return array simpleResponse-object. An exception is thrown if a fatal error occurred.
* @access public
* @throws \T3o\Ter\Exception\InternalServerErrorException
* @throws \T3o\Ter\Exception\UnauthorizedException
* @throws InternalServerErrorException
* @throws UnauthorizedException
* @since 2.0.0
*/
public function setReviewState($accountData, $setReviewStateData)
......@@ -379,7 +388,7 @@ class tx_ter_api
protected function requestUpdateOfExtensionIndexFile(): void
{
GeneralUtility::makeInstance(\T3o\TerFe2\Service\ExtensionIndexService::class)->requestUpdate();
GeneralUtility::makeInstance(ExtensionIndexService::class)->requestUpdate();
}
/**
......
{
"name": "t3o/ter-soap",
"type": "typo3-cms-extension",
"description": "This extension provides extension listing and detail view, plus management of extension keys",
"description": "This extension provides the SOAP Server API for dealing with extensions.typo3.org",
"keywords": [
"TYPO3 CMS",
"TER",
......@@ -17,10 +17,10 @@
"email": "maintenance@typo3.org",
"issues": "https://git-t3o.typo3.org/t3o/ter/issues"
},
"license": "GPL-2.0+",
"version": "2.0.9",
"license": ["GPL-2.0-or-later"],
"version": "2.1.0",
"require": {
"typo3/cms-core": "^8.7 || ^9.5"
"typo3/cms-core": "^9.5 || ^10.4"
},
"autoload": {
"psr-4": {
......@@ -28,11 +28,12 @@
},
"classmap": [
"Classes",
"pi1",
"class.tx_ter_api.php"
"pi1"
]
},
"replace": {
"ter": "self.version"
"extra": {
"typo3/cms": {
"extension-key": "ter"
}
}
}
......@@ -49,7 +49,7 @@ class tx_ter_pi1 extends AbstractPlugin
try {
$server = new \SoapServer(null, ['uri' => \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\T3o\Ter\Api\Configuration::class)->getWsdlNamespace(), 'trace' => true, 'exceptions' => true]);
$server->setClass(\tx_ter_api::class);
$server->setClass(\T3o\Ter\Soap\TerSoapV1Handler::class);
$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();
......
......@@ -15,6 +15,7 @@ namespace T3o\TerFe2\Service;
*/
use T3o\Ter\Api\ResultCodes;
use T3o\Ter\Soap\TerSoapV1Handler;
/**
* Service for TER operations
......@@ -28,7 +29,7 @@ class TerService
protected $userData;
/**
* @var \tx_ter_api
* @var TerSoapV1Handler
*/
protected $terApi;
......@@ -44,7 +45,7 @@ class TerService
$this->userData = new \stdClass();
$this->userData->username = $username;
$this->userData->password = $password;
$this->terApi = new \tx_ter_api($this);
$this->terApi = new TerSoapV1Handler();
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment