Skip to content

Commit

Permalink
Merge pull request #12 from AuroraLumina/feat/services-n-configuration
Browse files Browse the repository at this point in the history
Feat/services n configuration
  • Loading branch information
thalysmarciobn committed Jun 3, 2024
2 parents 2e4f3fb + 8da4033 commit 0a78d38
Show file tree
Hide file tree
Showing 7 changed files with 280 additions and 130 deletions.
60 changes: 42 additions & 18 deletions src/Aurora/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@
use Psr\Http\Server\MiddlewareInterface;

use AuroraLumina\Interface\RouterInterface;
use AuroraLumina\Interface\ServiceInterface;
use AuroraLumina\Factory\ServerRequestFactory;
use AuroraLumina\Interface\ContainerInterface;
use AuroraLumina\Interface\RouterRequestInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use AuroraLumina\Interface\MiddlewareDispatcherInterface;

/**
* Application class for handling HTTP requests.
*/
class Application implements RouterInterface
{

/**
* Dependency injection container.
*
* @var Container
* @var ContainerInterface
*/
protected ContainerInterface $container;

Expand All @@ -41,8 +43,8 @@ class Application implements RouterInterface
/**
* Creates a new application instance.
*
* @param ContainerInterface $container The dependency injection container.
* @param RouterRequestInterface $routerRequest The router request instance.
* @param ContainerInterface $container The dependency injection container.
* @param RouterRequestInterface $routerRequest The router request instance.
* @param MiddlewareDispatcherInterface $middlewareDispatcher The middleware dispatcher instance.
*/
public function __construct(ContainerInterface $container, RouterRequestInterface $routerRequest, MiddlewareDispatcherInterface $middlewareDispatcher)
Expand All @@ -55,8 +57,9 @@ public function __construct(ContainerInterface $container, RouterRequestInterfac
/**
* Add a GET route to the application.
*
* @param string $path The route path
* @param mixed $action The route action
* @param string $path The route path.
* @param mixed $action The route action.
*
* @return void
*/
public function get(string $path, mixed $action): void
Expand All @@ -67,8 +70,9 @@ public function get(string $path, mixed $action): void
/**
* Add a POST route to the application.
*
* @param string $path The route path
* @param mixed $action The route action
* @param string $path The route path.
* @param mixed $action The route action.
*
* @return void
*/
public function post(string $path, mixed $action): void
Expand All @@ -79,29 +83,46 @@ public function post(string $path, mixed $action): void
/**
* Binds a service to the container.
*
* @param ServiceInterface $service The service to be bound.
* @param object $service The service to be bound.
*
* @return void
*/
public function bind(ServiceInterface $service): void
public function bind(object $service): void
{
$this->container->bind($service);
}

/**
* Binds a scoped service to the container.
*
* @param ServiceInterface $service The service to be bound.
* @param string $service The service to be bound.
*
* @return void
*/
public function bindScoped(string $service): void
{
$this->container->bind($service);
$this->container->bindScoped($service);
}

/**
* Bind a configuration object.
*
* @param object $data The configuration object to bind.
*
* @return void
*
* @throws Exception If the provided configuration is not a valid class instance or if it is an instance of stdClass.
*/
public function configuration(object $data): void
{
$this->container->configuration($data);
}

/**
* Adds a middleware to the middleware chain.
*
* @param MiddlewareInterface $middleware The middleware to be added.
*
* @return void
*/
public function addMiddleware(MiddlewareInterface $middleware): void
Expand All @@ -112,8 +133,9 @@ public function addMiddleware(MiddlewareInterface $middleware): void
/**
* Handle the incoming request and return a response.
*
* @param Request $request The incoming HTTP request
* @return Response The HTTP response
* @param Request $request The incoming HTTP request.
*
* @return Response The HTTP response.
*/
public function handle(Request $request): Response
{
Expand All @@ -124,7 +146,8 @@ public function handle(Request $request): Response
/**
* Run the application.
*
* @param bool $cleanDebuff Clear output
* @param bool $cleanDebuff Clear output.
*
* @return void
*/
public function run(bool $cleanDebuff = true): void
Expand All @@ -137,12 +160,13 @@ public function run(bool $cleanDebuff = true): void
/**
* Emit the HTTP response.
*
* @param Response $response The HTTP response to emit
* @param bool $cleanDebuff Clear output
* @param Response $response The HTTP response to emit.
* @param bool $cleanDebuff Clear output.
*
* @return void
*/
protected function emitResponse(Response $response, bool $cleanDebuff): void
{
(new Emitter())->emit($response, $cleanDebuff);
}
}
}
Loading

0 comments on commit 0a78d38

Please sign in to comment.