Engine API Reference

Overview

The Forge Framework Engine provides a robust set of core classes and interfaces for building web applications. This documentation covers the essential components, their methods, and usage patterns.

Container

The Dependency Injection Container is the core of the Forge Framework, managing service instantiation and resolution.

Core\DependencyInjection\Container

namespace Forge\Core\DependencyInjection;

class Container implements ContainerInterface
{
    public function get(string $id);
    public function has(string $id): bool;
    public function set(string $id, $concrete);
    public function singleton(string $id, $concrete);
}

Usage: The container is used to manage dependencies throughout your application.

HTTP Components

Core HTTP classes for handling requests and responses.

Http\Request

namespace Forge\Http;

class Request
{
    public function getMethod(): string;
    public function getUri(): string;
    public function getHeaders(): array;
    public function getBody(): array;
    public function input(string $key, $default = null);
}

Http\Response

namespace Forge\Http;

class Response
{
    public function setStatusCode(int $code): self;
    public function setHeader(string $name, string $value): self;
    public function setContent($content): self;
    public function json($data, int $status = 200): self;
}

Routing

The routing system handles URL matching and request dispatching.

Core\Routing\Router

namespace Forge\Core\Routing;

class Router
{
    public function get(string $path, $handler);
    public function post(string $path, $handler);
    public function put(string $path, $handler);
    public function delete(string $path, $handler);
    public function group(array $attributes, callable $callback);
}

Configuration

Configuration management system for your application.

Core\Configuration\Config

namespace Forge\Core\Configuration;

class Config
{
    public function get(string $key, $default = null);
    public function set(string $key, $value);
    public function has(string $key): bool;
    public function load(string $path);
}

Events

The event system provides a robust way to handle and dispatch events throughout your application.

Core\Events\EventDispatcher

namespace Forge\Core\Events;

class EventDispatcher implements EventDispatcherInterface
{
    public function dispatch(object $event);
    public function addListener(string $eventName, callable $listener, int $priority = 0);
    public function removeListener(string $eventName, callable $listener);
    public function getListeners(?string $eventName = null): array;
}

Usage: Register event listeners and dispatch events to handle various application scenarios.

Services

Service providers are responsible for bootstrapping and configuring your application's core services.

Core\Services\ServiceProvider

namespace Forge\Core\Services;

abstract class ServiceProvider
{
    protected Container $container;

    public function register(): void;
    public function boot(): void;
    public function provides(): array;
}

Usage: Extend this class to create custom service providers for your application components.