Skip to content

Commit

Permalink
feat: adds flysystem and tests for file uploading
Browse files Browse the repository at this point in the history
  • Loading branch information
davisenra committed Mar 27, 2024
1 parent 9dba808 commit 095e504
Show file tree
Hide file tree
Showing 8 changed files with 397 additions and 8 deletions.
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@
"symfony/dotenv": "^7.0",
"guzzlehttp/guzzle": "^7.8",
"symfony/console": "^7.0",
"doctrine/migrations": "^3.7"
"doctrine/migrations": "^3.7",
"league/flysystem": "^3.0"
},
"require-dev": {
"symfony/var-dumper": "^7.0",
"phpunit/phpunit": "^11.0",
"phpstan/phpstan": "^1.10",
"friendsofphp/php-cs-fixer": "^3.52",
"robiningelbrecht/phpunit-pretty-print": "^1.3"
"robiningelbrecht/phpunit-pretty-print": "^1.3",
"league/flysystem-memory": "^3.0"
}
}
265 changes: 264 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 40 additions & 4 deletions config/container.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@
use Doctrine\ORM\ORMSetup;
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemAdapter;
use League\Flysystem\Local\LocalFilesystemAdapter;
use Monolog\Handler\HandlerInterface;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Level;
use Monolog\Logger;
use Nyholm\Psr7\Factory\Psr17Factory;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ServerRequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\UploadedFileFactoryInterface;
use Psr\Http\Message\UriFactoryInterface;
use Psr\Log\LoggerInterface;
use Slim\App;
use Slim\Factory\AppFactory;
Expand Down Expand Up @@ -71,6 +78,26 @@
return $app;
},

ResponseFactoryInterface::class => function (Container $container) {
return $container->get(Psr17Factory::class);
},

ServerRequestFactoryInterface::class => function (Container $container) {
return $container->get(Psr17Factory::class);
},

StreamFactoryInterface::class => function (Container $container) {
return $container->get(Psr17Factory::class);
},

UploadedFileFactoryInterface::class => function (Container $container) {
return $container->get(Psr17Factory::class);
},

UriFactoryInterface::class => function (Container $container) {
return $container->get(Psr17Factory::class);
},

Application::class => function (Container $container) {
$cli = new Application();
$cli->setCatchExceptions(true);
Expand Down Expand Up @@ -125,10 +152,6 @@
return $cli;
},

ServerRequestFactoryInterface::class => function (Container $container) {
return $container->get(Psr17Factory::class);
},

LoggerInterface::class => function () {
/** @var HandlerInterface[] $handlers */
$handlers = [];
Expand Down Expand Up @@ -159,4 +182,17 @@
return new EntityManager($connection, $config);
},

Filesystem::class => function (Container $container) {
$adapter = $container->get(FilesystemAdapter::class);

return new Filesystem($adapter);
},

FilesystemAdapter::class => function () {
$storagePath = __DIR__ . '/../var/';
// TODO: return an adapter based on environment variable

return new LocalFilesystemAdapter($storagePath);
},

];
2 changes: 2 additions & 0 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

declare(strict_types=1);

use App\Controller\FileUploadController;
use App\Controller\HealthCheckController;
use Nyholm\Psr7\Response;
use Slim\App;

return function (App $app) {
$app->get('/healthcheck', HealthCheckController::class);
$app->post('/upload', FileUploadController::class);

$app->options('/{routes:.+}', fn ($request, $response) => $response);

Expand Down
Loading

0 comments on commit 095e504

Please sign in to comment.