Skip to content

Commit

Permalink
Replace swagger docs with welcome page
Browse files Browse the repository at this point in the history
  • Loading branch information
odan committed Jul 31, 2022
1 parent fac8c83 commit dda1d9c
Show file tree
Hide file tree
Showing 11 changed files with 9 additions and 187 deletions.
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
"nyholm/psr7-server": "^1.0",
"php-di/php-di": "^6 || ^7",
"selective/basepath": "^2",
"slim/php-view": "^3.0",
"slim/slim": "^4",
"symfony/uid": "^6",
"symfony/validator": "^6",
"symfony/yaml": "^6"
"symfony/validator": "^6"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3",
Expand Down
10 changes: 0 additions & 10 deletions config/container.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
use Slim\Factory\AppFactory;
use Slim\Interfaces\RouteParserInterface;
use Slim\Middleware\ErrorMiddleware;
use Slim\Views\PhpRenderer;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputOption;
use Tuupola\Middleware\HttpBasicAuthentication;

return [
// Application settings
Expand Down Expand Up @@ -121,12 +119,4 @@

return $application;
},

PhpRenderer::class => function (ContainerInterface $container) {
return new PhpRenderer($container->get('settings')['template']);
},

HttpBasicAuthentication::class => function (ContainerInterface $container) {
return new HttpBasicAuthentication($container->get('settings')['api_auth']);
},
];
6 changes: 0 additions & 6 deletions config/defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
// Environment
$settings['env'] = $_ENV['APP_ENV'] ?? $_SERVER['APP_ENV'] ?? 'dev';

// Path settings
$settings['root'] = dirname(__DIR__);
$settings['temp'] = __DIR__ . '/../tmp';
$settings['public'] = __DIR__ . '/../public';
$settings['template'] = __DIR__ . '/../templates';

// Error handler
$settings['error'] = [
// Should be set to false for the production environment
Expand Down
3 changes: 0 additions & 3 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
// Redirect to Swagger documentation
$app->get('/', \App\Action\Home\HomeAction::class)->setName('home');

// Swagger API documentation
$app->get('/docs/v1', \App\Action\OpenApi\Version1DocAction::class)->setName('docs');

// API
$app->group(
'/api',
Expand Down
9 changes: 3 additions & 6 deletions docs/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ parent: Advanced

All templates are stored in the directory: `templates/`

This project come with the [slim/php-view](https://github.com/slimphp/PHP-View)
to render PHP view scripts into a PSR-7 Response object.

Read more about [PHP Templates with Slim](https://odan.github.io/2020/12/09/slim4-php-view.html).

If you want to install Twig, please read these tutorials:
## Read more

* [PHP Templates with Slim](https://odan.github.io/2020/12/09/slim4-php-view.html)
* [The slim/php-view package](https://github.com/slimphp/PHP-View)
* [Slim 4 - Twig](https://ko-fi.com/s/5f182b4b22)
* [Slim 4 - Webpack](https://odan.github.io/2019/09/21/slim4-compiling-assets-with-webpack.html)
* [Webpack - Bootstrap Icons](https://odan.github.io/2021/01/07/webpack-bootstrap-icons.html)
12 changes: 3 additions & 9 deletions src/Action/Home/HomeAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@

namespace App\Action\Home;

use App\Renderer\RedirectRenderer;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

final class HomeAction
{
private RedirectRenderer $redirectRenderer;

public function __construct(RedirectRenderer $renderer)
{
$this->redirectRenderer = $renderer;
}

public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
return $this->redirectRenderer->redirectFor($response, 'docs');
$response->getBody()->write('Welcome!');

return $response;
}
}
32 changes: 0 additions & 32 deletions src/Action/OpenApi/Version1DocAction.php

This file was deleted.

38 changes: 0 additions & 38 deletions src/Renderer/TemplateRenderer.php

This file was deleted.

51 changes: 0 additions & 51 deletions templates/doc/swagger.php

This file was deleted.

5 changes: 2 additions & 3 deletions tests/TestCase/Action/Home/HomeActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ public function testAction(): void
$request = $this->createRequest('GET', '/');
$response = $this->app->handle($request);

// Assert: Redirect
$this->assertSame(StatusCodeInterface::STATUS_FOUND, $response->getStatusCode());
$this->assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
$this->assertResponseContains($response, 'Welcome!');
}

public function testPageNotFound(): void
{
$request = $this->createRequest('GET', '/nada');
$response = $this->app->handle($request);

// Assert: Not found
$this->assertSame(StatusCodeInterface::STATUS_NOT_FOUND, $response->getStatusCode());
}
}
26 changes: 0 additions & 26 deletions tests/TestCase/Action/OpenApi/Version1DocActionTest.php

This file was deleted.

0 comments on commit dda1d9c

Please sign in to comment.