'application/x-amf') * @param String $contentType */ const FILTER_HEADERS = 'FILTER_HEADERS'; /** * filter Vo Converter * note: this has nothing to do with the gateway. Filter definitions should one day be centralized in an independant place. * @param Amfphp_Core_Common_IVoConverter */ const FILTER_VO_CONVERTER = 'FILTER_VO_CONVERTER'; /** * config. * @var Amfphp_Core_Config */ protected $config; /** * typically the $_GET array. * @var array */ protected $getData; /** * typically the $_POST array. * @var array */ protected $postData; /** * the content type. For example for amf, application/x-amf * @var String */ protected $contentType; /** * the serialized request * @var String */ protected $rawInputData; /** * the serialized response * @var String */ protected $rawOutputData; /** * */ /** * constructor * @param array $getData typically the $_GET array. * @param array $postData typically the $_POST array. * @param String $rawInputData * @param String $contentType * @param Amfphp_Core_Config $config optional. The default config object will be used if null */ public function __construct(array $getData, array $postData, $rawInputData, $contentType, Amfphp_Core_Config $config = null) { $this->getData = $getData; $this->postData = $postData; $this->rawInputData = $rawInputData; $this->contentType = $contentType; if ($config) { $this->config = $config; } else { $this->config = new Amfphp_Core_Config(); } //check for deprecated config settings. replace "true" by "false" if you want to keep this around, or simply delete once your upgrade works if (true) { if (isset($this->config->serviceFolderPaths)) { throw new Exception('In the Amfphp config, serviceFolderPaths have been renamed to serviceFolders. See http://www.silexlabs.org/amfphp/documentation/upgrading-from-2-0-x-and-2-1-x-to-2-2/'); } if (isset($this->config->pluginsConfig['AmfphpCustomClassConverter'])) { throw new Exception('The AmfphpCustomClassConverter has been renamed to AmfphpVoConverter. Please update your config accordingly. See http://www.silexlabs.org/amfphp/documentation/upgrading-from-2-0-x-and-2-1-x-to-2-2/'); } if (isset($this->config->pluginsConfig['AmfphpVoConverter'])) { $voConverterConfig = $this->config->pluginsConfig['AmfphpVoConverter']; if (isset($voConverterConfig['customClassFolderPaths']) || isset($voConverterConfig['voFolderPaths'])) { throw new Exception('The AmfphpVoConverter folder info is to be set in "voFolderPaths" . Please update your config accordingly. See http://www.silexlabs.org/amfphp/documentation/upgrading-from-2-0-x-and-2-1-x-to-2-2/'); } } } } /** * The service method runs the gateway application. It deserializes the raw data passed into the constructor as an Amfphp_Core_Amf_Packet, handles the headers, * handles the messages as requests to services, and returns the responses from the services * It does not however handle output headers, gzip compression, etc. that is the job of the calling script * * @return the serialized data */ public function service() { $filterManager = Amfphp_Core_FilterManager::getInstance(); $deserializedResponse = null; try { Amfphp_Core_PluginManager::getInstance()->loadPlugins($this->config->pluginsFolders, $this->config->pluginsConfig, $this->config->sharedConfig, $this->config->disabledPlugins); $defaultHandler = new Amfphp_Core_Amf_Handler($this->config->sharedConfig); //filter service folder paths $this->config->serviceFolders = $filterManager->callFilters(self::FILTER_SERVICE_FOLDER_PATHS, $this->config->serviceFolders); //filter service names 2 class find info $this->config->serviceNames2ClassFindInfo = $filterManager->callFilters(self::FILTER_SERVICE_NAMES_2_CLASS_FIND_INFO, $this->config->serviceNames2ClassFindInfo); //filter serialized request $this->rawInputData = $filterManager->callFilters(self::FILTER_SERIALIZED_REQUEST, $this->rawInputData); //filter deserializer $deserializer = $filterManager->callFilters(self::FILTER_DESERIALIZER, $defaultHandler, $this->contentType); //deserialize $deserializedRequest = $deserializer->deserialize($this->getData, $this->postData, $this->rawInputData); //filter deserialized request $deserializedRequest = $filterManager->callFilters(self::FILTER_DESERIALIZED_REQUEST, $deserializedRequest); //create service router $serviceRouter = new Amfphp_Core_Common_ServiceRouter($this->config->serviceFolders, $this->config->serviceNames2ClassFindInfo, $this->config->checkArgumentCount); //filter deserialized request handler $deserializedRequestHandler = $filterManager->callFilters(self::FILTER_DESERIALIZED_REQUEST_HANDLER, $defaultHandler, $this->contentType); //handle request $deserializedResponse = $deserializedRequestHandler->handleDeserializedRequest($deserializedRequest, $serviceRouter); } catch (Exception $exception) { //filter exception handler $exceptionHandler = $filterManager->callFilters(self::FILTER_EXCEPTION_HANDLER, $defaultHandler, $this->contentType); //handle exception $deserializedResponse = $exceptionHandler->handleException($exception); } //filter deserialized response $deserializedResponse = $filterManager->callFilters(self::FILTER_DESERIALIZED_RESPONSE, $deserializedResponse); //filter serializer $serializer = $filterManager->callFilters(self::FILTER_SERIALIZER, $defaultHandler, $this->contentType); //serialize $this->rawOutputData = $serializer->serialize($deserializedResponse); //filter serialized response $this->rawOutputData = $filterManager->callFilters(self::FILTER_SERIALIZED_RESPONSE, $this->rawOutputData); return $this->rawOutputData; } /** * get the response headers. Creates an associative array of headers, then filters them, then returns an array of strings * @return array */ public function getResponseHeaders() { $filterManager = Amfphp_Core_FilterManager::getInstance(); $headers = array('Content-Type' => $this->contentType); $headers = $filterManager->callFilters(self::FILTER_HEADERS, $headers, $this->contentType); $ret = array(); foreach ($headers as $key => $value) { $ret[] = $key . ': ' . $value; } return $ret; } /** * helper function for sending gateway data to output stream */ public function output() { $responseHeaders = $this->getResponseHeaders(); foreach ($responseHeaders as $header) { header($header); } echo $this->rawOutputData; return $this->rawOutputData; } }