コード例 #1
0
ファイル: ImageController.php プロジェクト: svycka/sv-images
 /**
  * Creates response object
  *
  * @param string $content
  * @param Result $result
  *
  * @return Response
  */
 protected function prepareResponse($content, Result $result)
 {
     $mimeType = $this->guessMimeType($result->getFilePath());
     if (function_exists('mb_strlen')) {
         $contentLength = mb_strlen($content, '8bit');
     } else {
         $contentLength = strlen($content);
     }
     /* @var $response Response */
     $response = $this->getResponse();
     $response->getHeaders()->addHeaderLine('Content-Transfer-Encoding', 'binary')->addHeaderLine('Content-Type', $mimeType)->addHeaderLine('Content-Length', $contentLength)->addHeaderLine('Cache-Control', 'max-age=31536000, public')->addHeaderLine('Expires', date_create('+1 years')->format('D, d M Y H:i:s') . ' GMT');
     $response->setContent($content);
     return $response;
 }
コード例 #2
0
ファイル: ImageService.php プロジェクト: svycka/sv-images
 /**
  * @param \SvImages\Parser\Result $parserResult
  *
  * @return false|string
  */
 public function generateImage(ParserResult $parserResult)
 {
     $path = $parserResult->getFilePath();
     $contents = $this->filesystem->read($path);
     if (false === $contents) {
         return false;
     }
     $transformers = $parserResult->getTransformers();
     foreach ($transformers as $item) {
         $transformer = $this->transformersManager->get($item['type']);
         if (!empty($item['defaults']) && is_array($item['defaults'])) {
             $transformer->setDefaults($item['defaults']);
         }
         $contents = $transformer->apply($contents, $item['options']);
     }
     return $contents;
 }