Example #1
0
 public function testItGetsResponseData()
 {
     $expectedResponse = $this->createExpectedResponse('createContact');
     $result = new Response($expectedResponse);
     $this->assertInternalType('array', $result->getData());
     $this->assertNotEmpty($result);
 }
Example #2
0
 /**
  * Loads all data into the results object (initialisation)
  *
  * @param \Elastica\Response $response Response object
  */
 protected function _init(Response $response)
 {
     $this->_response = $response;
     $result = $response->getData();
     $this->_totalHits = isset($result['hits']['total']) ? $result['hits']['total'] : 0;
     $this->_took = isset($result['took']) ? $result['took'] : 0;
     if (isset($result['hits']['hits'])) {
         foreach ($result['hits']['hits'] as $hit) {
             $this->_results[] = new Result($hit);
         }
     }
 }
 /**
  * Loads all data into the results object (initialisation)
  *
  * @param \Elastica\Response $response Response object
  */
 protected function _init(Response $response)
 {
     $this->_response = $response;
     $result = $response->getData();
     $this->_totalHits = isset($result['hits']['total']) ? $result['hits']['total'] : 0;
     $this->_maxScore = isset($result['hits']['max_score']) ? $result['hits']['max_score'] : 0;
     $this->_took = isset($result['took']) ? $result['took'] : 0;
     $this->_timedOut = !empty($result['timed_out']);
     if (isset($result['hits']['hits'])) {
         foreach ($result['hits']['hits'] as $hit) {
             $this->_results[] = new Result($hit);
         }
     }
 }
Example #4
0
 public function run()
 {
     try {
         $request = $this->requestFactory->createRequest();
         $controller = $this->controllerFactory->create($request);
         $response = $controller->run($request);
     } catch (AuthorizationException $e) {
         $response = new Response(['message' => $e->getMessage()], 401);
     } catch (ApiException $e) {
         $response = new Response(['message' => $e->getMessage()], $e->getCode() ?: 400);
     }
     http_response_code($response->getCode());
     header('Content-Type: application/json');
     $body = json_encode($response->getData());
     header('X-Api-Signature: ' . hash_hmac('sha256', $body, $this->configuration->getPrivateKey()));
     echo $body;
 }
Example #5
0
 public function testGetData()
 {
     $response = new Response('response data', 1234);
     $this->assertSame('response data', $response->getData());
 }
 public function testGetDataSomeData()
 {
     $response = new Response();
     $response->setResponseData('{"result":true, "data": "some data"}');
     $this->assertEquals('some data', $response->getData());
 }
Example #7
0
 public function setResponse($outputHandle, Response $response)
 {
     $this->set($outputHandle, $response->getData());
 }
Example #8
0
<?php

include "./swoole_include.php";
$http = new swoole_http_server("0.0.0.0", 9501);
$http->on('request', function ($request, $response) {
    if ($request->server['request_uri'] !== '/favicon.ico') {
        //设置参数
        $req = new Request($request);
        //var_dump( $request );
        //获取类.方法.参数
        $rou = new Router($req);
        $class = $rou->getClass();
        $method = $rou->getMethod();
        $args = $rou->getArgs();
        //按需加载类文件
        $fileName = SWOOLE_MODEL_PATH . $class . '.class.php';
        if (is_file($fileName)) {
            require_once $fileName;
        } else {
            Log::write($class . ' is not found', 'EMERG', 3, 'swoole');
            $response->end('url is error, please check your url!');
        }
        //调用回调函数,获取数据
        $data = call_user_func_array(array($class, $method), $args);
        //返回处理信息
        $res = new Response($data);
        $response->end($res->getData());
    }
});
$http->start();