add Dependencies and Routes classes
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
c344dce8eb
commit
7cc2d40660
6 changed files with 288 additions and 12 deletions
29
src/Dependencies.php
Normal file
29
src/Dependencies.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace NoteCat;
|
||||
|
||||
use DI\Container;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class Dependencies
|
||||
{
|
||||
public static function createContainer(): Container
|
||||
{
|
||||
$container = new Container();
|
||||
|
||||
// Controllers
|
||||
$container->set(HelloWorldController::class, function (ContainerInterface $c) {
|
||||
return new HelloWorldController(
|
||||
$c->get(HelloWorld::class)
|
||||
);
|
||||
});
|
||||
|
||||
// Services
|
||||
$container->set(HelloWorld::class, function () {
|
||||
return new HelloWorld();
|
||||
});
|
||||
|
||||
return $container;
|
||||
}
|
||||
}
|
||||
23
src/HelloWorldController.php
Normal file
23
src/HelloWorldController.php
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace NoteCat;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
|
||||
class HelloWorldController
|
||||
{
|
||||
private HelloWorld $hello;
|
||||
|
||||
public function __construct(HelloWorld $hello)
|
||||
{
|
||||
$this->hello = $hello;
|
||||
}
|
||||
|
||||
public function hello(Request $request, Response $response): Response
|
||||
{
|
||||
$response->getBody()->write('<b>' . $this->hello->getHello() . "</b>\n");
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
15
src/Routes.php
Normal file
15
src/Routes.php
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace NoteCat;
|
||||
|
||||
use NoteCat\HelloWorldController;
|
||||
use Slim\App;
|
||||
|
||||
class Routes
|
||||
{
|
||||
public static function setRoutes(App $app): void
|
||||
{
|
||||
$app->get('/', HelloWorldController::class . ':hello');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue