Use the elgg_* versions instead.
Since: 1.11.0
Exemplo n.º 1
0
 /**
  * Send system messages back with the response
  *
  * @param string       $hook     "ajax_response"
  * @param string       $type     "all"
  * @param AjaxResponse $response Ajax response
  * @param array        $params   Hook params
  *
  * @return AjaxResponse
  * @access private
  * @internal
  */
 public function appendMessages($hook, $type, $response, $params)
 {
     if (!$response instanceof AjaxResponse) {
         return;
     }
     $response->getData()->_elgg_msgs = (object) $this->msgs->dumpRegister();
     return $response;
 }
Exemplo n.º 2
0
 function testCanModifyRegisterSet()
 {
     $this->svc->addSuccessMessage(['s2', 's3']);
     $this->svc->addErrorMessage(['e1', 'e2', 'e3']);
     $set = $this->svc->loadRegisters();
     $this->assertEquals(['s2', 's3'], $set->success);
     $this->assertEquals(['e1', 'e2', 'e3'], $set->error);
     // will be filtered
     $set->success = ['', 's2'];
     $set->error = ['e1', false];
     $set->notice = ['n1', 'n2'];
     $set->invalid = true;
     $this->svc->saveRegisters($set);
     $this->assertEquals(['success' => ['s2']], $this->svc->dumpRegister('success'));
     $this->assertEquals(['error' => ['e1']], $this->svc->dumpRegister('error'));
     $this->assertEquals(['notice' => ['n1', 'n2']], $this->svc->dumpRegister());
 }
Exemplo n.º 3
0
 /**
  * Build a JsonResponse based on an API response object
  *
  * @param AjaxResponse $api_response           The API Response
  * @param bool         $allow_removing_headers Alter PHP's global headers to allow caching
  *
  * @return JsonResponse
  * @throws \RuntimeException
  */
 private function buildHttpResponse(AjaxResponse $api_response, $allow_removing_headers = true)
 {
     if ($api_response->isCancelled()) {
         return new JsonResponse(['error' => "The response was cancelled"], 400);
     }
     $response = new JsonResponse(['msgs' => (object) $this->msgs->dumpRegister(), 'data' => $api_response->getData()]);
     $ttl = $api_response->getTtl();
     if ($ttl > 0) {
         // Required to remove headers set by PHP session
         if ($allow_removing_headers) {
             header_remove('Expires');
             header_remove('Pragma');
             header_remove('Cache-Control');
         }
         // JsonRequest sets a default Cache-Control header we don't want
         $response->headers->remove('Cache-Control');
         $response->setClientTtl($ttl);
         // if we don't set Expires, Apache will add a far-off max-age and Expires for us.
         $response->headers->set('Expires', gmdate('D, d M Y H:i:s \\G\\M\\T', time() + $ttl));
     }
     return $response;
 }