Esempio n. 1
0
 /**
  * @param \Psr\Http\Message\ServerRequestInterface $request
  * @param \Slim\Http\Response                      $response
  *
  * @return \Slim\Http\Response
  * @throws \livetyping\hermitage\app\exceptions\BadRequestException
  */
 public function __invoke(Request $request, Response $response) : Response
 {
     $mime = (string) current($request->getHeader('Content-Type'));
     $binary = (string) $request->getBody();
     if (empty($mime) || empty($binary) || !in_array($mime, Util::supportedMimeTypes())) {
         throw new BadRequestException('Invalid mime-type or body.');
     }
     $command = new StoreImageCommand($mime, $binary);
     $this->bus->handle($command);
     return $response->withStatus(201)->withJson(['filename' => $command->getPath()]);
 }
Esempio n. 2
0
 /**
  * @param string $filename
  *
  * @throws \livetyping\hermitage\foundation\exceptions\ImageNotFoundException
  */
 protected function makeVersion(string $filename)
 {
     $original = Util::original($filename);
     $command = new MakeImageVersionCommand($original, Util::version($filename));
     $this->bus->handle($command);
 }
Esempio n. 3
0
 /**
  * @return string
  */
 public function getPath() : string
 {
     return Util::path((string) $this->dirname, (string) $this->name, (string) $this->extension, (string) $this->version);
 }