/** * Default amf gateway module */ public function executeService() { $this->setLayout(false); $gateway = new sfAmfGateway($this->context->getConfiguration()->getEventDispatcher(), $this->getResponse()); $gateway->handleRequest(); return sfView::NONE; }
public function index() { //加载amf插件 ob_clean(); import('@plugin.amf.sfAmfGateway'); //调用amf插件 $gateway = new sfAmfGateway(); //输出内容 $gateway->service();为返回内容 //handleRequest 中自动调用 header(SabreAMF_Const::MIMETYPE); //因为我不没有别的内容输出了所以直接输出内容 $gateway->handleRequest(); exit; return 'ajax'; }
/** * Executes index action * * @param sfWebRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $this->setLayout(false); $gateway = new sfAmfGateway($this->context->getConfiguration()->getEventDispatcher(), $this->getResponse()); $this->services_reflections = $gateway->parseAllServices(); $this->resp = null; $this->errors = array(); $this->method_name = null; $this->service_name = null; $this->service_method_name = null; if ($request->getParameter('method')) { $this->service_method_name = $request->getParameter('method'); list($this->package_name, $this->method_name) = explode('::', $this->service_method_name); $this->service_name = $this->services_reflections[$this->package_name]->getName(); $this->method_reflection = new ReflectionMethod($this->services_reflections[$this->package_name]->getName(), $this->method_name); if ($request->isMethod('post')) { $this->arguments = $request->getPostParameter('param', array()); foreach ($this->arguments as &$arg) { $arg = trim($arg); //-- JSON object if (substr($arg, 0, 1) == '[' or substr($arg, 0, 1) == '{') { $arg = json_decode($arg, true); if (is_null($arg)) { $this->errors[] = 'Bad-formatted JSON!'; } } elseif (substr($arg, 0, 1) == '"' and substr($arg, -1, 1) == '"') { $arg = substr($arg, 1, -1); } } if (!$this->errors) { $this->method_return_resp = $gateway->onDispatch($this->package_name, $this->method_name, $this->arguments); $this->amf_return_resp = $this->_makeAmfResponseFromMethodReturn($this->method_return_resp); } else { $this->method_return_resp = null; $this->amf_return_resp = null; } } } }