Example #1
21
 public function serve(ConnectionInterface $conn, RequestInterface $request = null, array $parameters)
 {
     try {
         $path = $this->assets->get($parameters['asset'])->getFullPath();
         if (!file_exists($path)) {
             throw new FileNotFoundException($path);
         }
         $response = new Response(200, array('Content-Type' => Mimetypes::getInstance()->fromFilename($path)), file_get_contents($path));
         $conn->send((string) $response);
         $conn->close();
     } catch (AssetNotFoundException $e) {
         $response = new Response(404, null, '');
         $conn->send((string) $response);
         $conn->close();
     } catch (FileNotFoundException $e) {
         $response = new Response(404, null, '');
         $conn->send((string) $response);
         $conn->close();
     } catch (\Exception $e) {
         $response = new Response(500, null, '');
         $conn->send((string) $response);
         $conn->close();
     }
 }
 public function setBody($body, $contentType = null)
 {
     $this->body = EntityBody::factory($body);
     // Auto detect the Content-Type from the path of the request if possible
     if ($contentType === null && !$this->hasHeader('Content-Type')) {
         $contentType = $this->body->getContentType() ?: Mimetypes::getInstance()->fromFilename($this->getPath());
     }
     if ($contentType) {
         $this->setHeader('Content-Type', $contentType);
     }
     // Always add the Expect 100-Continue header if the body cannot be rewound. This helps with redirects.
     if (!$this->body->isSeekable() && $this->expectCutoff !== false) {
         $this->setHeader('Expect', '100-Continue');
     }
     // Set the Content-Length header if it can be determined
     $size = $this->body->getContentLength();
     if ($size !== null && $size !== false) {
         $this->setHeader('Content-Length', $size);
         if ($size > $this->expectCutoff) {
             $this->setHeader('Expect', '100-Continue');
         }
     } elseif (!$this->hasHeader('Content-Length')) {
         if ('1.1' == $this->protocolVersion) {
             $this->setHeader('Transfer-Encoding', 'chunked');
         } else {
             throw new RequestException('Cannot determine Content-Length and cannot use chunked Transfer-Encoding when using HTTP/1.0');
         }
     }
     return $this;
 }
 /**
  * Upload a new document to an application
  *
  * Example arguments
  * <code>
  * Array (
  *     applicationUuId: 36481551-45bd-1b81-8145-c20c6a260004
  *     file: /tmp/file
  *     fileName: document.pdf
  *     description: My lovely document
  *     categoryId: 1
  * )
  * </code>
  *
  * For categoryId, please refer to @see Barbondev\IRISSDK\Common\EnumerationDocumentCategoryOptions
  *
  * @param array $args
  * @return \Guzzle\Http\Message\Response
  */
 public function uploadDocument(array $args = array())
 {
     $request = $this->post(sprintf('/referencing/v1/system/application/%s/document/upload', $args['referencingApplicationUuId']));
     $request->setPostField('fileName', $args['fileName']);
     $request->setPostField('description', $args['description']);
     $request->setPostField('category', $args['categoryId']);
     $request->addPostFile('file', $args['file'], Mimetypes::getInstance()->fromFilename(basename($args['file'])));
     return $request->send();
 }
 /**
  * Update an agent branch brand logo
  *
  * Example arguments
  * <code>
  * Array (
  *     agentBranchUuId: 1053a4b8-bfa5-94af-bf1b-d842d44f8
  *     file: /tmp/file
  *     fileName: image.jpeg
  *     description: My lovely picture
  * )
  * </code>
  *
  * @param array $args
  * @return \Guzzle\Http\Message\Response
  */
 public function updateAgentBranchBrandLogo(array $args = array())
 {
     $request = $this->put(sprintf('/referencing/v1/agent/branch/%s/brand/logo', $args['agentBranchUuId']));
     $request->setPostField('fileName', $args['fileName']);
     $request->setPostField('description', $args['description']);
     $request->setPostField('category', '4');
     // todo: Change with API spec, see TBL (being removed)
     $request->addPostFile('file', $args['file'], Mimetypes::getInstance()->fromFilename(basename($args['file'])));
     return $request->send();
 }
Example #5
0
 protected function guessContentType()
 {
     return Mimetypes::getInstance()->fromFilename($this->filename) ?: 'application/octet-stream';
 }
Example #6
0
 /**
  * @return bool
  */
 public function stream_flush()
 {
     if ($this->mode == 'r') {
         return false;
     }
     $this->body->rewind();
     $params = $this->params;
     $params['Body'] = $this->body;
     // Attempt to guess the ContentType of the upload based on the
     // file extension of the key
     if (!isset($params['ContentType']) && ($type = Mimetypes::getInstance()->fromFilename($params['Key']))) {
         $params['ContentType'] = $type;
     }
     try {
         static::$client->putObject($params);
         $this->clearStatInfo('s3://' . $params['Bucket'] . '/' . $params['Key']);
         return true;
     } catch (\Exception $e) {
         return $this->triggerError($e->getMessage());
     }
 }
 /**
  * Gets the correct content-type.
  *
  * @param string $filename
  *
  * @return array
  */
 protected function getContentType($filename)
 {
     $extension = pathinfo($filename, PATHINFO_EXTENSION);
     $contentType = Mimetypes::getInstance()->fromExtension($extension);
     return array('contentType' => $contentType);
 }
Example #8
0
 public function getContentType()
 {
     return $this->getUri() ? Mimetypes::getInstance()->fromFilename($this->getUri()) : null;
 }
 public function testReturnsNullWhenNoMatchFound()
 {
     $this->assertNull(Mimetypes::getInstance()->fromExtension('foobar'));
 }