public function testConvert()
 {
     $uri = '/foo';
     $method = 'POST';
     $parameters = array('a' => 1, 'b' => 2);
     $headers = array('c' => 3, 'd' => 4);
     $content = 'ups';
     $request = new Request($method, $uri);
     $request->setParameters($parameters);
     $request->setHeaders($headers);
     $request->setContent($content);
     $cookies = array();
     $files = array();
     $server = array('HTTP_c' => 3, 'HTTP_d' => 4);
     $symfonyRequest = SymfonyRequest::create($uri, $method, $parameters, $cookies, $files, $server, $content);
     $converter = new SymfonyHttpFoundationRequestConverter();
     $this->assertEquals($symfonyRequest, $converter->convert($request));
 }
Пример #2
0
 /**
  * @return Http\Response
  */
 public function request(Request $request)
 {
     $uri = $request->getUri();
     $requestConverter = new SymfonyHttpFoundationRequestConverter();
     $symfonyRequest = $requestConverter->convert($request);
     if ($uri === '/oauth/token') {
         $response = $this->server->token($symfonyRequest);
     } elseif ($uri === '/resource') {
         $response = $this->server->resource($symfonyRequest, function () {
             $response = new Response();
             $response->headers->set('content-type', 'text/plain');
             $response->setContent('My resource!');
             return $response;
         });
     } else {
         throw new \Exception('Invalid request.');
     }
     $responseConverter = new SymfonyHttpFoundationResponseConverter();
     return $responseConverter->convert($response);
 }