/** * Handle web service request * * @param array|bool $request The request (Really only used for testing) * @param boolean $return Return the response or not (Really only used for testing) * @return void|string */ public function handle($request = false, $return = false) { try { // Set the request to our server's request if (is_array($request)) { $this->get_request()->setParams($request); } // Security checks $this->security(); // Server setup $this->server->setClass($this->serviceclass, '', array($this, $this->get_response())); $this->server->returnResponse(true); // Output buffer when not testing (ensures clean response) if (!PHPUNIT_TEST) { ob_start(); } // Run the server $response = $this->server->handle($request); // Close output buffer if needed if (!PHPUNIT_TEST) { ob_end_clean(); } // Allow response class to look at the response $response = $this->get_response()->post_handle($response); } catch (Exception $e) { $response = $this->fault($e->getMessage()); } if ($return) { return $response; } $this->send_headers(); echo $response; die; }
/** * Load server definition from a file * * Unserializes a stored server definition from $filename. Returns false if * it fails in any way, true on success. * * Useful to prevent needing to build the server definition on each * request. Sample usage: * * <code> * if (!Zend_Server_Cache::get($filename, $server)) { * require_once 'Some/Service/Class.php'; * require_once 'Another/Service/Class.php'; * * // Attach Some_Service_Class with namespace 'some' * $server->attach('Some_Service_Class', 'some'); * * // Attach Another_Service_Class with namespace 'another' * $server->attach('Another_Service_Class', 'another'); * * Zend_Server_Cache::save($filename, $server); * } * * $response = $server->handle(); * echo $response; * </code> * * @param string $filename * @param Zend_Server_Interface $server * @return bool */ public static function get($filename, Zend_Server_Interface $server) { if (!is_string($filename) || !file_exists($filename) || !is_readable($filename)) { return false; } if (false === ($dispatch = @file_get_contents($filename))) { return false; } if (false === ($dispatchArray = @unserialize($dispatch))) { return false; } $server->loadFunctions($dispatchArray); return true; }