/**
  * Get the body of a POST or PUT.
  *
  * Used for fetching the post parameters and to calculate the body signature.
  *
  * @return string		null when no body present (or wrong content type for body)
  */
 public function getRequestBody()
 {
     if ($this->_rawBody === null) {
         $body = null;
         if ($this->getContentType() == 'multipart/form-data') {
             $body = \function_exists("http_get_request_body") ? http_get_request_body() : @$_POST[0];
         } else {
             if ($this->request->getMethod() == 'POST' || $this->request->getMethod() == 'PUT') {
                 $body = '';
                 $fh = @fopen('php://input', 'r');
                 if ($fh) {
                     while (!feof($fh)) {
                         $s = fread($fh, 1024);
                         if (is_string($s)) {
                             $body .= $s;
                         }
                     }
                     fclose($fh);
                 }
             }
         }
         $this->_rawBody = $body;
     }
     return $this->_rawBody;
 }
Esempio n. 2
0
 /**
  * Get the HTTP Method
  *
  * @return string
  */
 public function getMethod()
 {
     if (isset($_GET['method'])) {
         return $_GET['method'];
     }
     $method = parent::getMethod();
     return $method;
 }
Esempio n. 3
0
 /**
  * I fetch a value from pathparams and request
  * @todo wrap pathparams and request in a composite
  * @param $pathParams
  * @param Request $Request
  * @return bool
  * @throws \Exception
  */
 public function fetch($pathParams, Request $Request)
 {
     $this->value = null;
     $this->_hasFetched = false;
     $filters = [];
     $name = $this->_data->name;
     switch ($this->_data->in) {
         case 'path':
             if (array_key_exists($name, $pathParams)) {
                 $this->_hasFetched = true;
                 $this->setValue($pathParams[$name]);
             }
             break;
         case 'query':
             $this->_hasFetched = $Request->hasQuery($name);
             $this->setValue($Request->getQuery($name, $filters, null));
             break;
         case 'header':
             // this syntax won't work... yet???
             //$value = $Request->getHeader($name, $filters, null);
             $nameWithHttpPrefix = strtoupper(str_replace('-', '_', $name));
             if ($Request->hasServer($name) || $Request->hasServer($nameWithHttpPrefix)) {
                 $this->setValue($Request->getHeader($name));
                 $this->_hasFetched = true;
             }
             break;
         case 'formData':
             switch (strtolower($Request->getMethod())) {
                 case 'post':
                     if ($Request->hasPost($name)) {
                         $this->_hasFetched = true;
                         $this->setValue($Request->getPost($name, $filters, null));
                     }
                     break;
                 case 'put':
                     if ($Request->hasPut($name)) {
                         $this->_hasFetched = true;
                         $this->setValue($Request->getPut($name, $filters, null));
                     }
                     break;
                     // parameters on delete request not supported yet
                 // parameters on delete request not supported yet
                 case 'delete':
                 default:
                     throw new \Exception('TBI: ' . $Request->getMethod());
             }
             break;
         case 'body':
             throw new \Exception('TBI');
             break;
         default:
             throw new \Exception('invalid or not implemented "in" value: ' . $this->_data->in);
     }
     return $this->_hasFetched;
 }