AppserverIo\Appserver\ServletEngine\Http\Part::fromHttpRequest PHP Method

fromHttpRequest() public static method

Creates a new servlet part instance with the data from the HTTP part.
public static fromHttpRequest ( AppserverIo\Psr\HttpMessage\PartInterface $httpPart ) : Part
$httpPart AppserverIo\Psr\HttpMessage\PartInterface The HTTP part we want to copy
return Part The initialized servlet part
    public static function fromHttpRequest(PartInterface $httpPart)
    {
        // create a temporary filename
        $httpPart->write($tmpFilename = tempnam(ini_get('upload_tmp_dir'), 'tmp_'));
        // initialize the servlet part instance
        $servletPart = new Part();
        $servletPart->setName($httpPart->getName());
        $servletPart->setFilename($httpPart->getFilename());
        $servletPart->setTmpFilename($tmpFilename);
        // return the servlet part instance
        return $servletPart;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Initializes the servlet request with the data from the injected HTTP request instance.
  *
  * @return void
  */
 public function init()
 {
     // reset the servlet request
     $httpRequest = $this->getHttpRequest();
     // initialize the parts
     foreach ($httpRequest->getParts() as $part) {
         $this->addPart(Part::fromHttpRequest($part));
     }
     // set the body content if we can find one
     if ($httpRequest->getHeader(HttpProtocol::HEADER_CONTENT_LENGTH) > 0) {
         $this->setBodyStream($httpRequest->getBodyContent());
     }
     // copy server variables to members
     $this->setServerName($this->getServerVar(ServerVars::SERVER_NAME));
     $this->setQueryString($this->getServerVar(ServerVars::QUERY_STRING));
     $this->setRequestUri($this->getServerVar(ServerVars::X_REQUEST_URI));
     $this->setDocumentRoot($this->getServerVar(ServerVars::DOCUMENT_ROOT));
     $this->setRequestUrl($this->getServerVar(ServerVars::HTTP_HOST) . $this->getServerVar(ServerVars::X_REQUEST_URI));
 }
All Usage Examples Of AppserverIo\Appserver\ServletEngine\Http\Part::fromHttpRequest