示例#1
0
 /**
  * Returns the request
  *
  * @return \Cundd\Rest\Request
  */
 public function getRequest()
 {
     if (!$this->request) {
         $uri = $this->getUri();
         /*
          * Transform Document URLs
          * @Todo: Make this more flexible
          */
         if ($this->stringHasPrefix($uri, Request::API_PATH_DOCUMENT . '/')) {
             $documentApiPathLength = strlen(Request::API_PATH_DOCUMENT) + 1;
             $uri = Request::API_PATH_DOCUMENT . '-' . substr($uri, $documentApiPathLength);
         }
         list($uri, $originalPath, $path) = $this->getRequestPathAndUriForUri($uri);
         $this->request = new Request(NULL, $uri);
         $this->request->initWithPathAndOriginalPath($path, $originalPath);
         $this->request->injectConfigurationProvider($this->configurationProvider);
         if ($this->format) {
             $this->request->format($this->format);
         }
         //            fwrite(STDOUT, PHP_EOL . '-> ' . spl_object_hash($this) . ' ' . $uri . ' - ' . $this->getArgument('u', FILTER_SANITIZE_URL) . PHP_EOL);
         //        } else {
         //            fwrite(STDOUT, PHP_EOL . '<- ' . spl_object_hash($this) . ' ' . $this->getUri() . PHP_EOL);
     }
     return $this->request;
 }
示例#2
0
 /**
  * @param string $method
  * @param string $url
  * @param array $params
  * @param array $headers
  * @param mixed $rawBody
  * @return Request
  */
 protected function buildTestRequest($method = null, $url = null, array $params = array(), array $headers = array(), $rawBody = null)
 {
     $path = strtok($url, '/');
     $request = new \Cundd\Rest\Request($method, $url, $params, $headers, $rawBody);
     $request->initWithPathAndOriginalPath($path, $path);
     return $request;
 }
 /**
  * @test
  */
 public function getConfigurationForPathWithWildcardTest()
 {
     $uri = 'my_secondext-my_model/34/';
     $request = new Request(NULL, $uri);
     $testConfiguration = array('path' => 'my_secondext-*', 'read' => 'deny', 'write' => 'allow');
     $configuration = $this->fixture->getConfigurationForPath($request->path());
     $this->assertEquals($testConfiguration, $configuration);
 }
示例#4
0
 /**
  * Returns the request
  *
  * @return \Cundd\Rest\Request
  */
 public function getRequest()
 {
     if (!$this->request) {
         $format = '';
         $uri = $this->getUri($format);
         /*
          * Transform Document URLs
          * @Todo: Make this better
          */
         if (substr($uri, 0, 9) === 'Document/') {
             $uri = 'Document-' . substr($uri, 9);
         }
         $this->request = new Request(NULL, $uri);
         $this->request->injectConfigurationProvider($this->objectManager->getConfigurationProvider());
         if ($format) {
             $this->request->format($format);
         }
     }
     return $this->request;
 }
示例#5
0
文件: Server.php 项目: tritumRz/rest
 /**
  * Handles the requests
  *
  * @param \React\Http\Request $request Request to handle
  * @param \React\Http\Response $response Prebuilt response object
  */
 public function serverCallback($request, $response)
 {
     // Currently the PHP server is readonly
     if (!in_array(strtoupper($request->getMethod()), array('GET', 'HEAD'))) {
         $response->writeHead(405, array('Content-type' => 'text/plain'));
         $response->end('Writing is currently not supported');
         return;
     }
     $requestPath = $this->sanitizePath($request->getPath());
     $requestPath = substr($requestPath, 5);
     /** @var Request $restRequest */
     $restRequest = new Request($request->getMethod(), $requestPath, $request->getQuery(), $request->getHeaders());
     $path = '' . strtok($requestPath, '/');
     $restRequest->initWithPathAndOriginalPath($path, $path);
     $this->setServerGlobals($request);
     /** @var \Bullet\Response $restResponse */
     $restResponse = NULL;
     ob_start();
     $this->dispatcher->dispatch($restRequest, $restResponse);
     $responseString = ob_get_clean();
     if (!$restResponse) {
         $response->writeHead(200);
         $response->end($responseString);
     } else {
         $response->writeHead($restResponse->status(), $this->getHeadersFromResponse($restResponse));
         $response->end($restResponse->content());
     }
     unset($restRequest);
     unset($restResponse);
 }
示例#6
0
文件: Cache.php 项目: tritumRz/rest
 /**
  * Returns the cache key for the current request
  *
  * @return string
  */
 protected function _getCacheKey()
 {
     return sha1($this->currentRequest->url() . '_' . $this->currentRequest->format() . '_' . $this->currentRequest->method());
 }