Skip to content

Commit

Permalink
Create FileProvider.php
Browse files Browse the repository at this point in the history
  • Loading branch information
peldax authored Oct 19, 2020
1 parent c2c479c commit a6bf548
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/FileProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types = 1);

namespace Graphpinator\Nette;

final class FileProvider implements \Graphpinator\Module\Upload\FileProvider
{
use \Nette\SmartObject;

private \Nette\Http\Request $request;

public function __construct(\Nette\Http\Request $request)
{
$this->request = $request;
}

public function getMap() : \Graphpinator\Json
{
return $this->request->getPost('map');
}

public function getFile(string $key) : \Psr\Http\Message\UploadedFileInterface
{
$file = $this->request->getFile($key);

return new \GuzzleHttp\Psr7\UploadedFile(
$file->getTemporaryFile(),
$file->getSize(),
$file->getError(),
$file->getName(),
$_FILES[$key]['type'],
);
}
}

0 comments on commit a6bf548

Please sign in to comment.