public function smdAction() { $class = 'Admin_Model_RPC'; $server = new Zend_Json_Server(); $server->getServiceMap()->setDojoCompatible(true); $server->getServiceMap()->setTransport('POST')->setTarget($this->getHelper('url')->url(array('action' => 'service')))->setId($this->getHelper('url')->url(array('action' => 'service'))); $server->setClass($class); $smd = $server->getServiceMap(); echo $smd; exit; }
public function indexAction() { $server = new Zend_Json_Server(); $x = new Agana_Service_Test(); $server->setClass('Agana_Service_Test'); echo $server->getServiceMap(); exit; }
/** * Cache a service map description (SMD) to a file * * Returns true on success, false on failure * * @param string $filename * @param Zend_Json_Server $server * @return boolean */ public static function saveSmd($filename, Zend_Json_Server $server) { if (!is_string($filename) || !file_exists($filename) && !is_writable(dirname($filename))) { return false; } if (0 === @file_put_contents($filename, $server->getServiceMap()->toJson())) { return false; } return true; }
/** * get json-api service map * * @return string */ public static function getServiceMap() { $server = new Zend_Json_Server(); $server->setClass('Setup_Frontend_Json', 'Setup'); $server->setClass('Tinebase_Frontend_Json', 'Tinebase'); $server->setTarget('setup.php')->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2); $smd = $server->getServiceMap(); $smdArray = $smd->toArray(); unset($smdArray['methods']); return $smdArray; }
public function jsonAction() { $server = new Zend_Json_Server(); $server->setClass('My_Server_Ventas'); if ('GET' == $_SERVER['REQUEST_METHOD']) { $server->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2); $smd = $server->getServiceMap(); //header('Content-Type: application/json'); echo $smd; return; } $server->handle(); }
/** * JSON SERVER */ public function jsonAction() { $server = new Zend_Json_Server(); $server->setClass('My_Application_Model_Data'); if ('GET' == $_SERVER['REQUEST_METHOD']) { $server->setTarget($this->_url)->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2); $smd = $server->getServiceMap(); header('Content-Type: application/json'); echo $smd; return; } echo $server->handle(); }
public function jsonAction() { $this->_helper->viewRenderer->setNoRender(); $server = new Zend_Json_Server(); $server->setClass('Application_Model_Data', 'cf'); if ('GET' == $_SERVER['REQUEST_METHOD']) { $server->setTarget('http://localhost/xmlrpc-test/public/server/json')->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2); $smd = $server->getServiceMap(); header('Content-Type: application/json'); echo $smd; return; } echo $server->handle(); }
/** * JSON-RPC controller * * @return void */ public function indexAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $server = new Zend_Json_Server(); $server->setClass('WorklogService'); if ('GET' == $_SERVER['REQUEST_METHOD']) { $server->setTarget('/rpc/index')->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2)->setDojoCompatible(true); $smd = $server->getServiceMap(); header('Content-Type: application/json'); echo $smd; return; } // Handle the request: $server->handle(); }
/** * JSON CLIENT */ public function jsonAction() { $server = new Zend_Json_Server(); $server->setClass('My_Application_Model_Data'); if ('GET' == $_SERVER['REQUEST_METHOD']) { $server->setTarget($this->_url)->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2); $smd = $server->getServiceMap(); if (isset($_GET['method'])) { //On recupere les methodes depuis le service map $arrSmd = Zend_Json::decode($smd); //Construction du tableau contenant les liens des methodes $links = '<h2>' . 'Liste des methodes JSON' . '</h2>' . '<table>' . '<tr>'; foreach ($arrSmd["services"] as $serv => $value) { $links .= '<td width="100px" align="center">' . '<a href="' . $this->_url . '?method=' . $serv . '">' . $serv . '</a>' . '</td>'; } $links .= '</tr>' . '</table>'; //Envoi du tableau a la vue $this->view->links = $links; //On recupere la methode appelee $method = $_GET['method']; $nbParam = 0; //Nombre de parametre de la methode //On cree un formulaire contenant les parametres $formtxt = '<form name="' . $method . '" method="post">' . '<table>'; foreach ($smd->getService($method)->getParams() as $param) { $formtxt .= '<tr>' . '<td>' . $param['name'] . ' (' . $param['type'] . ') :</td>' . '<td><input type=text name="' . $param['name'] . '"></td>' . '<tr>'; $nbParam++; } $formtxt .= '<tr>' . '<td></td>' . '<td><input type=submit value=Envoyer></td>' . '</tr>' . '</table>' . '</form>'; //On envoi le formulaire a la vue json client $this->view->form = $formtxt; //On envoi le nom de la methode traitee a la vue $this->view->method = $method; //On envoi le nombre de parametres du formulaire a la vue $this->view->nbParam = $nbParam; } else { $this->_helper->viewRenderer->setNoRender(true); header('Content-Type: application/json'); echo $smd; return; } } else { $this->_helper->viewRenderer->setNoRender(); echo $server->handle(); } }
public function indexAction() { // Instantiate server, etc. $server = new Zend_Json_Server(); Zend_Registry::set("fileserver_helper", $this->_fileHelper); $server->setClass('Admin_Model_FileServer'); if ('GET' == $_SERVER['REQUEST_METHOD']) { // Indicate the URL endpoint, and the JSON-RPC version used: $server->setTarget('/file-server/')->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2); // Grab the SMD $smd = $server->getServiceMap(); // Return the SMD to the client header('Content-Type: application/json'); echo $smd; die; } $server->handle(); die; }
require_once 'Zend/Loader/Autoloader.php'; $autoloader = Zend_Loader_Autoloader::getInstance(); /** * ================================================================== * Prepare environment and execute JSON calls * ================================================================== */ require APPLICATION_PATH . '/includes/classes/remote.class.php'; header('Access-Control-Allow-Origin: *'); $server = new Zend_Json_Server(); $server->setClass('Kimai_Remote_Api'); if ('GET' == $_SERVER['REQUEST_METHOD']) { // Indicate the URL endpoint, and the JSON-RPC version used: $server->setTarget('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'])->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2); // Grab the SMD $smd = $server->getServiceMap(); // Return the SMD to the client header('Content-Type: application/json'); echo $smd; return; } /** * http request will * - parse php://input * - json_decode it * - auto setOptions * therefore request should be a string e.g. {jsonrpc : '2.0', method: '<actionString>', params : [param1, param2], id : '<anyId>' } */ $request = new Zend_Json_Server_Request_Http(); $server->setRequest($request); $server->handle();
/** * JSON-RPC entrance. * * @return Void */ public function apiAction() { Zend_Registry::set('CMS', true); /** * Prepare the server. Zend_Json_Server cannot work with batched requests natively, * so that's taken care of customly here. Therefore, autoEmitResponse is set to false * so the server doesn't print the response directly. */ $server = new Zend_Json_Server(); $server->setClass('Garp_Content_Manager_Proxy'); $server->setAutoEmitResponse(false); if ($this->getRequest()->isPost()) { $post = $this->_getJsonRpcRequest(); $batch = false; $responses = array(); $requests = Zend_Json::decode($post, Zend_Json::TYPE_ARRAY); /** * Check if this was a batch request. In that case the array is a plain array of * arrays. If not, there will be a 'jsonrpc' key in the root of the array. */ $batch = !array_key_exists('jsonrpc', $requests); if (!$batch) { $requests = array($requests); } foreach ($requests as $i => $request) { $request = $this->_reformJsonRpcRequest($request); $requestJson = Zend_Json::encode($request); $requestObj = new Zend_Json_Server_Request(); $requestObj->loadJson($requestJson); $server->setRequest($requestObj); /** * Note; response gets returned by reference, resulting in a $responses array * containing all the same items. * That's why clone is used here. */ $response = clone $server->handle(); $responses[] = $response; } $response = $batch ? '[' . implode(',', $responses) . ']' : $responses[0]; } else { $response = $server->getServiceMap(); } $this->_helper->layout->setLayout('json'); // filter out escaped slashes, because they're annoying and not necessary. $response = str_replace('\\/', '/', $response); $this->view->response = $response; }
/** * Override of run method to provide JSON server interface * * @return void */ public function run() { if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') { // run Zend_Json_Server instead of the MVC stack $request = new Zend_Controller_Request_Http(); $info = explode('/', trim($request->getPathInfo(), '/')); $module = $info[0]; $service = $info[1]; // attach the service to the JSON-RPC server $service = $this->_loadService($module, $service); $server = new Zend_Json_Server(); $server->setClass($service); if ('GET' == $_SERVER['REQUEST_METHOD']) { // return the service map $server->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2); $smd = $server->getServiceMap(); header('Content-Type: application/json'); echo $smd; return; } $server->handle(); } else { parent::run(); } }
/** * return service map * * @return Zend_Json_Server_Smd */ public static function getServiceMap() { $server = new Zend_Json_Server(); $server->setClass('Tinebase_Frontend_Json', 'Tinebase'); $server->setClass('Tinebase_Frontend_Json_UserRegistration', 'Tinebase_UserRegistration'); if (Tinebase_Core::isRegistered(Tinebase_Core::USER)) { $server->setClass('Tinebase_Frontend_Json_Container', 'Tinebase_Container'); $server->setClass('Tinebase_Frontend_Json_PersistentFilter', 'Tinebase_PersistentFilter'); $userApplications = Tinebase_Core::getUser()->getApplications(TRUE); foreach ($userApplications as $application) { $jsonAppName = $application->name . '_Frontend_Json'; $server->setClass($jsonAppName, $application->name); } } $server->setTarget('index.php')->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2); $smd = $server->getServiceMap(); return $smd; }