Skip to content
This repository was archived by the owner on Apr 29, 2025. It is now read-only.

Commit b496f20

Browse files
author
Jędrzej
authored
Better exception marking (#2)
1 parent c77b039 commit b496f20

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/App.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@
55
namespace Depth\Techno;
66

77
use Depth\Techno\Exceptions\EnvNotFoundException;
8+
use Depth\Techno\Exceptions\RouteNotFoundException;
9+
use Depth\Techno\Exceptions\RouterException;
10+
use Depth\Techno\Exceptions\ServiceNotFoundException;
811
use M1\Env\Parser;
12+
use ReflectionException;
913

1014
final readonly class App
1115
{
1216
private Container $container;
1317

18+
/**
19+
* @throws EnvNotFoundException
20+
*/
1421
public function __construct(
1522
string $env_path = __DIR__.'/.env',
1623
private string $router_path = __DIR__.'/routes.php',
@@ -21,6 +28,12 @@ public function __construct(
2128
$this->container = new Container();
2229
}
2330

31+
/**
32+
* @throws ServiceNotFoundException
33+
* @throws RouterException
34+
* @throws ReflectionException
35+
* @throws RouteNotFoundException
36+
*/
2437
public function run(): void
2538
{
2639
if ($_ENV['DEBUG'] ?? false) {
@@ -32,6 +45,9 @@ public function run(): void
3245
$router->resolve($this->router_path)->send();
3346
}
3447

48+
/**
49+
* @throws EnvNotFoundException
50+
*/
3551
private function loadEnv(string $env_path): void
3652
{
3753
$contents = file_get_contents($env_path);

src/Container.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ final class Container implements ContainerInterface
2121

2222
/**
2323
* @param class-string $id
24+
*
25+
* @throws ServiceNotFoundException
26+
* @throws ReflectionException
2427
*/
2528
public function get(string $id): object
2629
{
@@ -62,6 +65,8 @@ public function set(string $id, object $value): self
6265

6366
/**
6467
* @param class-string $id
68+
*
69+
* @throws ServiceNotFoundException
6570
*/
6671
private function resolve(string $id): object
6772
{
@@ -83,6 +88,9 @@ private function resolve(string $id): object
8388

8489
/**
8590
* @param ReflectionClass<object> $item
91+
*
92+
* @throws ServiceNotFoundException
93+
* @throws ReflectionException
8694
*/
8795
private function getInstance(ReflectionClass $item): object
8896
{

src/Router.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use Depth\Techno\Exceptions\RouteNotFoundException;
88
use Depth\Techno\Exceptions\RouterException;
9+
use Depth\Techno\Exceptions\ServiceNotFoundException;
10+
use ReflectionException;
911
use Symfony\Component\HttpFoundation\Response;
1012

1113
use function array_key_exists;
@@ -18,12 +20,21 @@
1820
public function __construct(
1921
private Container $container,
2022
) {
21-
$this->path = explode('/', trim(explode('?', $_SERVER['REQUEST_URI'] ?? '')[0], '/'));
23+
$this->path = explode(
24+
'/',
25+
trim(explode('?', $_SERVER['REQUEST_URI'] ?? '')[0], '/'),
26+
);
2227
}
2328

29+
/**
30+
* @throws ServiceNotFoundException
31+
* @throws RouterException
32+
* @throws ReflectionException
33+
* @throws RouteNotFoundException
34+
*/
2435
public function resolve(string $router_path): Response
2536
{
26-
/** @var array<string, class-string> */
37+
/** @var array<string, class-string> $router_path */
2738
$routes = require $router_path;
2839

2940
$link = "{$_SERVER['REQUEST_METHOD']} /{$this->path[0]}";

0 commit comments

Comments
 (0)