Aerys\Request::getBody PHP Method

getBody() public method

Note that the returned Body instance may change between calls, the contents not explicitly fetched through its valid() / consume() API, will be moved to the new instance though. No need to buffer and concatenate manually in this case.
public getBody ( integer $bodySize ) : Body
$bodySize integer maximum body size
return Body
    public function getBody(int $bodySize = -1) : Body;

Usage Example

Example #1
0
 /**
  * @param Request $req
  * @param array $options available options are:
  *                       - size (default: 131072)
  *                       - input_vars (default: 200)
  *                       - field_len (default: 16384)
  */
 public function __construct(Request $req, array $options = [])
 {
     $this->req = $req;
     $type = $req->getHeader("content-type");
     $this->body = $req->getBody($this->totalSize = $this->size = $options["size"] ?? 131072);
     $this->maxFieldLen = $options["field_len"] ?? 16384;
     $this->maxInputVars = $options["input_vars"] ?? 200;
     if ($type !== null && strncmp($type, "application/x-www-form-urlencoded", \strlen("application/x-www-form-urlencoded"))) {
         if (!preg_match('#^\\s*multipart/(?:form-data|mixed)(?:\\s*;\\s*boundary\\s*=\\s*("?)([^"]*)\\1)?$#', $type, $m)) {
             $this->req = null;
             $this->parsing = true;
             $this->result = new ParsedBody([]);
             return;
         }
         $this->boundary = $m[2];
     }
     $this->body->when(function ($e, $data) {
         $this->req = null;
         \Amp\immediately(function () use($e, $data) {
             if ($e) {
                 if ($e instanceof ClientSizeException) {
                     $e = new ClientException("", 0, $e);
                 }
                 $this->error = $e;
             } else {
                 $this->result = $this->end($data);
             }
             if (!$this->parsing) {
                 $this->parsing = true;
                 foreach ($this->result->getNames() as $field) {
                     foreach ($this->result->getArray($field) as $_) {
                         foreach ($this->watchers as list($cb, $cbData)) {
                             $cb($field, $cbData);
                         }
                     }
                 }
             }
             $this->parsing = true;
             foreach ($this->whens as list($cb, $cbData)) {
                 $cb($this->error, $this->result, $cbData);
             }
             $this->whens = $this->watchers = [];
         });
     });
 }
All Usage Examples Of Aerys\Request::getBody