/**
  * Deals with multipart requests.
  * @return ['content' => $content, 'attachments' => $attachments].
  */
 private function getParts()
 {
     $content = \LockerRequest::getContent();
     $contentType = \LockerRequest::header('Content-Type');
     $types = explode(';', $contentType, 2);
     $mimeType = count($types) >= 1 ? $types[0] : $types;
     if ($mimeType == 'multipart/mixed') {
         $components = Attachments::setAttachments($contentType, $content);
         // Returns 'formatting' error.
         if (empty($components)) {
             throw new Exceptions\Exception('There is a problem with the formatting of your submitted content.');
         }
         // Returns 'no attachment' error.
         if (!isset($components['attachments'])) {
             throw new Exceptions\Exception('There were no attachments.');
         }
         $content = $components['body'];
         $attachments = $components['attachments'];
     } else {
         $attachments = [];
     }
     return ['content' => $content, 'attachments' => $attachments];
 }
示例#2
0
 /**
  * Get all of the input and files for the request and store them in params.
  *
  */
 public function setParameters()
 {
     $this->params = \LockerRequest::all();
     $this->params['content'] = \LockerRequest::getContent();
 }
 /**
  * Checks for files, then retrieves the stored param.
  * @param String $name Field name
  * @return Array
  */
 public function getPostContent($name)
 {
     if (\Input::hasFile($name)) {
         $content = \Input::file($name);
         $contentType = $content->getClientMimeType();
     } else {
         if (\LockerRequest::getContent()) {
             $content = \LockerRequest::getContent();
             $contentType = \LockerRequest::header('Content-Type');
             $isForm = $this->checkFormContentType($contentType);
             if (!$contentType || $isForm) {
                 $contentType = is_object(json_decode($content)) ? 'application/json' : 'text/plain';
             }
         } else {
             \App::abort(400, sprintf('`%s` was not sent in this request', $name));
         }
     }
     return ['content' => $content, 'contentType' => $contentType];
 }