Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions core/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,40 @@ public static function container(): Container
}

/**
* Bootstrap the application
* The shared service container instance.
* @var Container
*/
protected static Container $container;

/**
* Create a new application instance.
*
* @param Container $container The service container instance.
*/
public function __construct(Container $container)
{
static::$container = $container;
}

/**
* Get the shared service container.
*
* This static method provides global access to the container.
*
* @return Container
*/
public static function container(): Container
{
return static::$container;
}

/**
* Bootstrap the application's core services and environment.
*
* This method loads environment variables, sets the timezone,
* enables error reporting (if in debug mode), and starts the session.
*
* @return void
*/
public function bootstrap(): void
{
Expand All @@ -43,7 +76,11 @@ public function bootstrap(): void
}

/**
* Enable Whoops
* Enable the Whoops error handler for detailed debug information.
*
* This is only enabled when the application is in debug mode.
*
* @return void
*/
public function enableWhoops(): void
{
Expand Down
31 changes: 21 additions & 10 deletions core/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,25 @@

class Container
{
/**
* The container's bindings.
* @var array
*/
protected array $bindings = [];

/**
* The container's shared instances.
* @var array
*/
protected array $instances = [];

/**
* Bind a resolver into the container.
* Register a binding with the container.
*
* @param string $key The abstract key (e.g., 'router' or Router::class).
* @param Closure|string|null $concrete The concrete resolver or class name.
* @param bool $singleton Whether the binding should be a singleton.
* @param string $key The abstract service key (e.g., Router::class).
* @param Closure|string|null $concrete The concrete implementation (a closure or class name).
* @param bool $singleton If true, the binding is resolved once and the same instance is returned.
* @return void
*/
public function bind(string $key, Closure|string|null $concrete = null, bool $singleton = false): void
{
Expand All @@ -29,20 +39,21 @@ public function bind(string $key, Closure|string|null $concrete = null, bool $si
/**
* Register a shared (singleton) binding in the container.
*
* @param string $key
* @param Closure|string|null $concrete
* @param string $key The abstract service key.
* @param Closure|string|null $concrete The concrete implementation.
* @return void
*/
public function singleton(string $key, Closure|string|null $concrete = null): void
{
$this->bind($key, $concrete, true);
}

/**
* Resolve the given type from the container.
* Resolve the given service from the container.
*
* @param string $key
* @return mixed
* @throws Exception
* @param string $key The abstract key of the service to resolve.
* @return mixed The resolved service instance.
* @throws Exception If no binding is found for the given key.
*/
public function resolve(string $key): mixed
{
Expand Down
35 changes: 33 additions & 2 deletions core/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,29 @@

class Request
{
/**
* The GET parameters from the query string.
* @var array
*/
public readonly array $query;

/**
* The POST data from the request body.
* @var array
*/
public readonly array $data;

/**
* The server variables ($_SERVER).
* @var array
*/
public readonly array $server;

/**
* Create a new Request instance.
*
* This constructor captures the global GET, POST, and SERVER variables.
*/
public function __construct()
{
$this->query = $_GET;
Expand All @@ -16,15 +35,19 @@ public function __construct()
}

/**
* Get the request URI path.
* Get the request URI path, trimmed of slashes.
*
* @return string
*/
public function getPath(): string
{
return trim(parse_url($this->server['REQUEST_URI'], PHP_URL_PATH), '/');
}

/**
* Get the request method.
* Get the HTTP request method (e.g., GET, POST).
*
* @return string
*/
public function getMethod(): string
{
Expand All @@ -33,6 +56,10 @@ public function getMethod(): string

/**
* Get a value from the POST data.
*
* @param string $key The key of the value to retrieve.
* @param mixed|null $default The default value to return if the key is not found.
* @return mixed
*/
public function get(string $key, $default = null)
{
Expand All @@ -41,6 +68,10 @@ public function get(string $key, $default = null)

/**
* Get a value from the GET query string.
*
* @param string $key The key of the value to retrieve.
* @param mixed|null $default The default value to return if the key is not found.
* @return mixed
*/
public function query(string $key, $default = null)
{
Expand Down
54 changes: 51 additions & 3 deletions core/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,42 @@ public function __construct(mixed $content = '', int $statusCode = 200, array $h
}

/**
* Set the HTTP status code.
* The response content.
* @var mixed
*/
protected mixed $content;

/**
* The HTTP status code.
* @var int
*/
protected int $statusCode;

/**
* The response headers.
* @var array
*/
protected array $headers;

/**
* Create a new Response instance.
*
* @param mixed $content The response content.
* @param int $statusCode The HTTP status code.
* @param array $headers An array of response headers.
*/
public function __construct(mixed $content = '', int $statusCode = 200, array $headers = [])
{
$this->content = $content;
$this->statusCode = $statusCode;
$this->headers = $headers;
}

/**
* Set the HTTP status code for the response.
*
* @param int $code The HTTP status code.
* @return $this
*/
public function setStatusCode(int $code): self
{
Expand All @@ -26,6 +61,10 @@ public function setStatusCode(int $code): self

/**
* Add a header to the response.
*
* @param string $name The name of the header.
* @param string $value The value of the header.
* @return $this
*/
public function addHeader(string $name, string $value): self
{
Expand All @@ -34,7 +73,11 @@ public function addHeader(string $name, string $value): self
}

/**
* Send the response to the client.
* Send the HTTP response to the client.
*
* This method sends the status code, headers, and content.
*
* @return void
*/
public function send(): void
{
Expand All @@ -51,7 +94,12 @@ public function send(): void
}

/**
* Factory method to create a new Response.
* Factory method to create a new Response instance.
*
* @param mixed $content The response content.
* @param int $statusCode The HTTP status code.
* @param array $headers An array of response headers.
* @return static
*/
public static function create(mixed $content = '', int $statusCode = 200, array $headers = []): self
{
Expand Down
Loading