Esempio n. 1
0
	public function direct($data = null, $errors = null, $sendNow = true, $keepLayouts = false)
	{
		$resp = $this->_createResponseObject($data, $errors);
		if ($sendNow) {
            return $this->_json->sendJson($resp, $keepLayouts);
        }
        return $this->_json->encodeJson($resp, $keepLayouts);
	}
Esempio n. 2
0
 public function direct($arrayData)
 {
     header('Content-type: application/json');
     header("Access-Control-Allow-Origin: *");
     header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
     header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
     $json = new Zend_Controller_Action_Helper_Json();
     $json->sendJson($arrayData);
 }
Esempio n. 3
0
 /**
  * Encode JSON response and immediately send
  *
  * @param  mixed   $data
  * @param  boolean|array $keepLayouts
  * NOTE:   if boolean, establish $keepLayouts to true|false
  *         if array, admit params for Zend_Json::encode as enableJsonExprFinder=>true|false
  *         if $keepLayouts and parmas for Zend_Json::encode are required
  *         then, the array can contains a 'keepLayout'=>true|false
  *         that will not be passed to Zend_Json::encode method but will be passed
  *         to Zend_View_Helper_Json
  * @param  bool $wrap
  * @return string|void
  */
 public function sendJson($data, $keepLayouts = false, $wrap = true)
 {
     if (!is_array($data)) {
         return parent::sendJson($data, $keepLayouts);
     }
     if (isset($data['success']) && !is_bool($data['success'])) {
         $data['success'] = (bool) $data['success'];
     }
     if ($wrap) {
         $messages = Axis::message()->getAll();
         //            if (isset(false === $data['success']) && $data['success']) {
         //                unset($messages['success']);
         //            }
         $data = array_merge(array('messages' => $messages), $data);
     }
     if ($this->_data) {
         $data = array_merge_recursive($this->_data, $data);
     }
     $data = $this->encodeJson($data, $keepLayouts);
     $response = $this->getResponse();
     $response->setBody($data);
     if (!$this->suppressExit) {
         Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
         //Axis_FirePhp
         $response->sendResponse();
         exit;
     }
     return $data;
 }
Esempio n. 4
0
 public function dispatch()
 {
     $method = strtoupper($this->_request->getMethod());
     if ($method === 'POST' && null !== ($extraMethod = $this->_request->getParam('_method', null))) {
         $extraMethod = strtoupper(filter_var($extraMethod, FILTER_SANITIZE_STRING));
         if (in_array($extraMethod, array('PUT', 'DELETE'))) {
             $method = $extraMethod;
         }
     }
     $action = strtolower($method) . 'Action';
     $aclResource = strtolower(get_called_class() . '_' . $method);
     if (method_exists($this, $action)) {
         if (Tools_Security_Acl::isAllowed($aclResource)) {
             return $this->_jsonHelper->direct($this->{$action}());
         } else {
             $this->_error(null, self::REST_STATUS_FORBIDDEN);
         }
     } else {
         throw new Exceptions_SeotoasterPluginException(get_called_class() . ' doesn\'t have ' . $method . ' implemented');
     }
 }
 /**
  * Kick jobs
  * - server
  * - tube
  * - count : number of jobs to kick
  */
 public function kickAction()
 {
     $tube = $this->_getParam("tube");
     $count = $this->_getParam("count", 1);
     try {
         // Connect to the server
         $messageQueue = $this->getServer();
         $messageQueue->useTube($tube);
         $messageQueue->kick($count);
         $response = "";
     } catch (Exception $e) {
         $this->getResponse()->setHttpResponseCode(500);
         $response = $e->getMessage();
     }
     // Send Json response
     $this->jsonHelper->sendJson($response);
     $this->jsonHelper->getResponse()->sendResponse();
 }
Esempio n. 6
0
 /**
  * getResponse
  *
  * <p>convert the $_response array to json and set the application mine type json</p>
  */
 public function getResponse()
 {
     if (Zend_Registry::get('config')->kebab->logging->enable && Zend_Registry::get('config')->kebab->logging->firebug->enable) {
         Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
     }
     //KBBTODO We should write an adapter for array, xml in future
     $jsonHelper = new Zend_Controller_Action_Helper_Json();
     $jsonHelper->direct($this->_response);
 }