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; }
/** * 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)); }