Example #1
0
 public function getPut($name = null, $filters = null, $defaultValue = null, $notAllowEmpty = false, $noRecursive = false)
 {
     if ($this->isJson()) {
         $put = $this->getJsonRawBody();
         if ($name) {
             return isset($put[$name]) ? $put[$name] : null;
         }
         return $put;
     }
     return parent::getPut($name, $filters, $defaultValue, $notAllowEmpty, $noRecursive);
 }
 /**
  * extend to hook up possible case conversion
  *
  * @param string $name            
  * @param string $filters            
  * @param string $defaultValue            
  * @return multiple
  */
 public function getPut($name = NULL, $filters = NULL, $defaultValue = NULL, $notAllowEmpty = NULL, $noRecursive = NULL)
 {
     // perform parent function
     $request = parent::getPut($name, $filters, $defaultValue);
     // special handling for array requests, for individual inputs return what is request
     if (is_array($request) and $this->defaultCaseFormat != false) {
         return $this->convertCase($request);
     } else {
         return $request;
     }
 }
 /**
  * Get the body of a POST with multipart/form-data by Edison tsai on 16:52 2010/09/16
  *
  * 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 getRequestBodyOfMultipart()
 {
     $body = null;
     $requestMethod = $this->request->getMethod();
     if ($requestMethod == 'POST' || $requestMethod == 'PUT') {
         $body = '';
         $requestData = $requestMethod == 'PUT' ? $this->request->getPut() : $this->request->getPost();
         foreach ($requestData as $k => $v) {
             $body .= $this->encodeUrlParam($k, $v);
         }
         #end foreach
         if (substr($body, -1) == '&') {
             $body = substr($body, 0, strlen($body) - 1);
         }
         #end if
     }
     #end if
     return $body;
 }
 /**
  * @param \Phalcon\Http\Request $request
  * @return array All request params (GET, POST, PUT, RawJsonBody)
  */
 public static function getMergeParams(Request $request)
 {
     $jsonRawBody = (array) $request->getJsonRawBody(true);
     $params = array_merge((array) $request->get(), (array) $request->getPost(), (array) $request->getPut(), $jsonRawBody);
     return self::convertDate($params, $request->getDI());
 }
Example #5
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;
 }