Commit b68f3b40 authored by speedprogs_de's avatar speedprogs_de

added soap extension provider, moved soap utility to services

git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/terfe/branches/ter_fe2@51513 735d13b6-9817-0410-8766-e36946ffe9aa
parent 126f5ace
......@@ -62,10 +62,10 @@
}
// Get repository for extension manager cache entries
$this->extensionRepository = t3lib_div::makeInstance('Tx_TerFe2_Domain_Repository_ExtensionManagerCacheEntryRepository');
$this->extensionRepository = $this->objectManager->get('Tx_TerFe2_Domain_Repository_ExtensionManagerCacheEntryRepository');
// Get mirror service
$this->mirrorService = t3lib_div::makeInstance('Tx_TerFe2_Service_Mirror');
$this->mirrorService = $this->objectManager->get('Tx_TerFe2_Service_Mirror');
$this->mirrorService->setRepositoryId($this->repositoryId);
}
......
......@@ -126,7 +126,7 @@
/**
* Generates the name of an extension related file
*
*
* @param string $extension Extension key
* @param string $version Version string
* @param string $fileType File type
......@@ -144,7 +144,7 @@
/**
* Parse compressed extension list file and return updated extensions
*
*
* @param string $filename File name
* @param integer $lastRun Timestamp of last update
* @param integer $offset Offset to start with
......@@ -256,7 +256,7 @@
/**
* Returns the content of an ext_emconf.php file
*
*
* @param string $extension Extension key
* @param string $version Version string
* @return array Extension info array
......
......@@ -28,6 +28,59 @@
*/
class Tx_TerFe2_ExtensionProvider_SoapProvider extends Tx_TerFe2_ExtensionProvider_AbstractProvider {
/**
* @var string
*/
protected $getExtensionsFunc;
/**
* @var string
*/
protected $getFileUrlFunc;
/**
* @var string
*/
protected $getFileNameFunc;
/**
* @var Tx_TerFe2_Service_Soap
*/
protected $soapService;
/**
* Initialize provider
*
* @return void
*/
public function initializeProvider() {
if (empty($this->configuration['wsdlUrl'])) {
throw new Exception('No wsdl url configured');
}
$username = (empty($this->configuration['username']) ? $this->configuration['username'] : '');
$password = (empty($this->configuration['password']) ? $this->configuration['password'] : '');
$this->soapService = $this->objectManager->get('Tx_TerFe2_Service_Soap');
$this->soapService->connect($this->configuration['wsdlUrl'], $username, $password);
// Set getExtensionsFunc
if (!empty($this->configuration['getExtensionsFunc'])) {
$this->getExtensionsFunc = $this->configuration['getExtensionsFunc'];
}
// Set getFileUrlFunc
if (!empty($this->configuration['getFileUrlFunc'])) {
$this->getFileUrlFunc = $this->configuration['getFileUrlFunc'];
}
// Set getFileNameFunc
if (!empty($this->configuration['getFileNameFunc'])) {
$this->getFileNameFunc = $this->configuration['getFileNameFunc'];
}
}
/**
* Returns all extensions since last run
*
......@@ -37,7 +90,16 @@
* @return array Extension rows
*/
public function getExtensions($lastRun, $offset, $count) {
if (empty($this->getExtensionsFunc)) {
throw new Exception('No configuration for "getExtensionsFunc" found');
}
$parameters = array(
'lastRun' => (int) $lastRun,
'offset' => (int) $offset,
'count' => (int) $count,
);
$result = $this->soapService->call($this->getExtensionsFunc, $parameters);
return (!empty($result['extensions']) ? $result['extensions'] : array());
}
......@@ -49,7 +111,19 @@
* @return string Url to file
*/
public function getFileUrl(Tx_TerFe2_Domain_Model_Version $version, $fileType) {
if (empty($this->getFileUrlFunc)) {
throw new Exception('No configuration for "getFileUrlFunc" found');
}
$parameters = array(
'extension' => (string) $version->getExtension()->getExtKey(),
'version' => (string) $version->getVersionString(),
'fileType' => (string) $fileType,
);
$result = $this->soapService->call($this->getFileUrlFunc, $parameters);
if (empty($result['url'])) {
throw new Exception('Could not get url to file from soap server');
}
return (string) $result['url'];
}
......@@ -61,7 +135,19 @@
* @return string File name
*/
public function getFileName(Tx_TerFe2_Domain_Model_Version $version, $fileType) {
if (empty($this->getFileNameFunc)) {
throw new Exception('No configuration for "getFileNameFunc" found');
}
$parameters = array(
'extension' => (string) $version->getExtension()->getExtKey(),
'version' => (string) $version->getVersionString(),
'fileType' => (string) $fileType,
);
$result = $this->soapService->call($this->getFileNameFunc, $parameters);
if (empty($result['filename'])) {
throw new Exception('Could not get filename from soap server');
}
return (string) $result['filename'];
}
}
......
......@@ -51,7 +51,7 @@
/**
* Setter for maxAttempts
*
*
* @param integer $maxAttempts Maximal count of attemts to connect
* @return void
*/
......@@ -62,7 +62,7 @@
/**
* Getter for maxAttempts
*
*
* @return integer Maximal count of attemts to connect
*/
public function getMaxAttempts() {
......@@ -72,7 +72,7 @@
/**
* Setter for protocol
*
*
* @param string $protocol Url protocol
* @return void
*/
......@@ -83,7 +83,7 @@
/**
* Getter for protocol
*
*
* @return string Url protocol
*/
public function getProtocol() {
......@@ -93,7 +93,7 @@
/**
* Setter for repositoryId
*
*
* @param integer $repositoryId Repository id
* @return void
*/
......@@ -104,7 +104,7 @@
/**
* Getter for repositoryId
*
*
* @return integer Repository id
*/
public function getRepositoryId() {
......@@ -200,7 +200,7 @@
/**
* Fetch a file from mirror server
*
*
* @param string $filename File name to fetch
* @return string File content
*/
......
......@@ -24,30 +24,30 @@
******************************************************************/
/**
* Utilities to manage SOAP requests
* Service to handle soap requests
*/
class Tx_TerFe2_Utility_Soap {
class Tx_TerFe2_Service_Soap {
/**
* @var SoapClient
*/
static protected $soapConnection;
protected $soapConnection;
/**
* @var SoapHeader
*/
static protected $authenticationHeader;
protected $authenticationHeader;
/**
* Load connection
* Open connection
*
* @param string $wsdlUrl URL of the wsdl
* @param string $username Login with this username
* @param string $password Login with this password
* @return void
*/
static public function connect($wsdlUrl, $username = '', $password = '') {
public function connect($wsdlUrl, $username = '', $password = '') {
if (empty($wsdlUrl)) {
throw new Exception('No valid wsdl URL given');
}
......@@ -57,7 +57,7 @@
}
// Create connection
self::$soapConnection = new SoapClient($wsdlUrl, array(
$this->soapConnection = new SoapClient($wsdlUrl, array(
'trace' => 1,
'exceptions' => 0,
));
......@@ -65,7 +65,7 @@
// Get authentication header
if (!empty($username) && !empty($password)) {
$headerData = array('username' => $username, 'password' => $password);
self::$authenticationHeader = new SoapHeader('', 'HeaderLogin', (object) $headerData, TRUE);
$this->authenticationHeader = new SoapHeader('', 'HeaderLogin', (object) $headerData, TRUE);
}
}
......@@ -77,26 +77,26 @@
* @param array $params Parameters
* @return array Result of the SOAP call
*/
static public function call($methodName, array $params = array()) {
public function call($methodName, array $params = array()) {
// Check for existing connection
if (empty(self::$soapConnection)) {
if (empty($this->soapConnection)) {
throw new Exception('Create SOAP connection first');
}
// Call given method
$response = self::$soapConnection->__soapCall(
$response = $this->soapConnection->__soapCall(
$methodName,
$params,
NULL,
self::$authenticationHeader
$this->authenticationHeader
);
// Check for errors
if (is_soap_fault($response)) {
return array();
throw new Exception('Could not call function "' . $methodName . '" on soap server');
}
return self::convertObjectToArray($response);
return $this->convertObjectToArray($response);
}
......@@ -106,16 +106,26 @@
* @param object $object Object to convert
* @return array Converted object
*/
static protected function convertObjectToArray($object) {
protected function convertObjectToArray($object) {
if (is_object($object) || is_array($object)) {
$object = (array) $object;
foreach ($object as $key => $value) {
$object[$key] = self::convertObjectToArray($value);
$object[$key] = $this->convertObjectToArray($value);
}
}
return $object;
}
/**
* Close connection
*
* @return void
*/
public function disconnect() {
unset($this->soapConnection, $this->authenticationHeader);
}
}
?>
\ No newline at end of file
......@@ -31,12 +31,12 @@
/**
* @var tslib_cObj
*/
static protected $contentObject;
protected static $contentObject;
/**
* @var Tx_Extbase_Configuration_ConfigurationManager
*/
static protected $configurationManager;
protected static $configurationManager;
/**
......@@ -44,7 +44,7 @@
*
* @return void
*/
static protected function initialize() {
protected static function initialize() {
// Get configuration manager
$objectManager = t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager');
self::$configurationManager = $objectManager->get('Tx_Extbase_Configuration_ConfigurationManager');
......@@ -79,7 +79,7 @@
*
* @return array TypoScript setup
*/
static public function getSetup() {
public static function getSetup() {
if (empty(self::$configurationManager)) {
self::initialize();
}
......@@ -103,7 +103,7 @@
* @param boolean $isPlain Is a plain "Fluid like" configuration array
* @return array Parsed configuration
*/
static public function parse(array $configuration, $isPlain = TRUE) {
public static function parse(array $configuration, $isPlain = TRUE) {
if (empty(self::$contentObject)) {
self::initialize();
}
......@@ -127,7 +127,7 @@
* @param array $configuration TypoScript configuration
* @return array Parsed configuration
*/
static protected function parseTypoScriptArray(array $configuration) {
protected static function parseTypoScriptArray(array $configuration) {
$typoScriptArray = array();
foreach ($configuration as $key => $value) {
......
......@@ -28,7 +28,7 @@
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$_EXTKEY]['extensionProviders']['extensionmanager'] = array(
'class' => 'Tx_TerFe2_ExtensionProvider_ExtensionManagerProvider',
'configuration' => array(
'repositoryId' => 1,
'repositoryId' => 1,
),
);
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$_EXTKEY]['extensionProviders']['file'] = array(
......@@ -41,7 +41,12 @@
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$_EXTKEY]['extensionProviders']['soap'] = array(
'class' => 'Tx_TerFe2_ExtensionProvider_SoapProvider',
'configuration' => array(
'wsdlUrl' => '',
'username' => '',
'password' => '',
'getExtensionsFunc' => 'getExtensions',
'getFileUrlFunc' => 'getFileUrl',
'getFileNameFunc' => 'getFileName',
),
);
......
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