/** * @covers WSManager::getConfigurations */ public function testGetConfigurations() { $this->manager->setPluginsDirectoryPath(dirname(__FILE__) . '/../../testPluginDirectoryStructure/'); $expected = array('methods' => array('methodA' => array('wrapper' => 'ClassA', 'group' => 'test1', 'type' => 'GET'), 'exampleMethod' => array('wrapper' => 'ExampleServiceWrapper', 'group' => 'test2', 'type' => 'GET'), 'methodC' => array('wrapper' => 'ClassC', 'group' => 'test1', 'type' => 'GET'), 'methodD' => array('wrapper' => 'ClassD', 'group' => 'test2', 'type' => 'GET'))); $result = $this->manager->getConfigurations(); $this->assertEquals($expected, $result); }
public function execute($request) { $logger = $this->getWebServiceLogger(); $wsHelper = new WSHelper(); $wsManager = new WSManager(); $result = ''; $status = 'INITIAL'; $contentType = 'text/plain'; $httpStatus = 200; $httpStatusText = null; try { $paramObj = $wsHelper->extractParameters($request); $isMethodAvailable = $wsManager->isMethodAvailable($paramObj->getMethod(), $paramObj->getRequestMethod()); $logger->debug(print_r($paramObj, true)); $logger->debug("MethodAvailable:" . $isMethodAvailable); if ($isMethodAvailable) { $isAuthenticated = $wsManager->isAuthenticated($paramObj); $isAuthorized = $wsManager->isAuthorized($paramObj); if ($isAuthenticated && $isAuthorized) { $result = $wsManager->callMethod($paramObj); $logger->debug(print_r($result, true)); $result = $wsHelper->formatResult($result, WSHelper::FORMAT_JSON); $logger->debug(print_r($result, true)); $status = 'SUCCESS'; $contentType = 'text/json'; } else { $result = 'NOT ALLOWED'; $status = 'ERROR'; $httpStatus = 401; } } else { $result = 'INVALID REQUEST'; $status = 'ERROR'; $httpStatus = 404; $httpStatusText = 'Webservice Method Not Found (' . $paramObj->getMethod() . ')'; } } catch (WebServiceException $e) { $result = $e->getCode() . ': ' . $e->getMessage(); $status = 'ERROR'; $httpStatus = $e->getCode(); $httpStatusText = $e->getMessage(); } catch (Exception $e) { $logger = $this->getWebServiceLogger(); $logger->info('Uncaught Exception: ' . $e->getMessage()); $result = $e->getMessage() . ' ' . $e->getCode(); $status = 'ERROR'; } $response = $this->getResponse(); $response->setContent($result); $response->setHttpHeader('Content-type', $contentType); $response->setHttpHeader('ohrm_ws_call_status', $status); $response->setStatusCode($httpStatus, $httpStatusText); return sfView::NONE; }
public function execute($request) { $wsHelper = new WSHelper(); $wsManager = new WSManager(); $result = ''; $status = 'INITIAL'; $contentType = 'text/plain'; try { $paramObj = $wsHelper->extractParamerts($request); $isMethodAvailable = $wsManager->isMethodAvailable($paramObj->getMethod()); if ($isMethodAvailable) { $isAuthenticated = $wsManager->isAuthenticated($paramObj); $isAuthorized = $wsManager->isAuthorized($paramObj); if ($isAuthenticated && $isAuthorized) { try { $result = $wsManager->callMethod($paramObj); $result = $wsHelper->formatResult($result, WSHelper::FORMAT_JSON); $status = 'SUCCESS'; $contentType = 'text/json'; } catch (Exception $e) { $logger = $this->getWebServiceLogger(); $logger->info('Uncaught Exception: ' . $e->getMessage()); $result = 'INTERNAL ERROR'; $status = 'ERROR'; } } else { $result = 'NOT ALLOWED'; $status = 'ERROR'; } } else { $result = 'INVALID REQUEST'; $status = 'ERROR'; } } catch (WebServiceException $e) { $result = $e->getCode() . ': ' . $e->getMessage(); $status = 'ERROR'; } $this->getResponse()->setContent($result); $this->getResponse()->setHttpHeader('Content-type', $contentType); $this->getResponse()->setHttpHeader('ohrm_ws_call_status', $status); return sfView::NONE; }
public static function setupBeforeClass() { WSManager::resetConfiguration(); }
/** * @return array */ public function getConfigurations() { if (!empty(self::$configurations) && is_array(self::$configurations)) { return self::$configurations; } $pluginsPath = $this->getPluginsDirectoryPath(); $directoryIterator = new DirectoryIterator($pluginsPath); self::$configurations = array(); foreach ($directoryIterator as $fileInfo) { if ($fileInfo->isDir()) { $pluginName = $fileInfo->getFilename(); $configuraitonPath = $pluginsPath . '/' . $pluginName . '/config/ws_config.yml'; if (is_file($configuraitonPath)) { $configuraiton = sfYaml::load($configuraitonPath); if (!is_array($configuraiton)) { continue; } foreach ($configuraiton as $configName => $configValue) { if (array_key_exists($configName, self::$configurations)) { self::$configurations[$configName] = self::$configurations[$configName] + $configValue; } else { self::$configurations[$configName] = $configValue; } } } } } return self::$configurations; }