Core Classes

Canvas architecture combines annotation-driven routing, dependency injection, and aspect-oriented programming. These components handle request processing, service resolution, and cross-cutting concerns.

Framework Core

Kernel - Request Handler

The Kernel class manages the request lifecycle:

$kernel = new Kernel();
$response = $kernel->handle($request);

Responsibilities:

  • Service Discovery - Registers classes across the application
  • Dependency Injection - Creates objects and resolves dependencies
  • Annotation Processing - Parses annotations for routing and aspects
  • Exception Handling - Generates error pages in development

Request Processing

Request-to-response flow:

  1. Kernel receives HTTP request
  2. AnnotationResolver matches URL to controller method
  3. AspectDispatcher applies aspects
  4. Controller method executes
  5. Response returns to client

Routing System

AnnotationResolver - URL Mapping

Routes are discovered through method annotations:

/**
 * @Route("/users/{id}", methods={"GET"})
 */
public function showUser($id) {
    // Controller logic
}

Features:

  • Auto-Discovery - Scans src/Controllers for @Route annotations
  • Parameter Extraction - URL segments like {id} map to method parameters
  • HTTP Method Filtering - Restricts routes to specific HTTP methods
  • No Registration - Routes defined inline, no separate configuration

Resolution Algorithm

URL matching process:

  1. Parse URL into segments
  2. Scan controllers for route annotations
  3. Match segment count and HTTP method
  4. Extract variables from parameterized segments
  5. Return controller, method, and variables

Aspect-Oriented Programming

AspectDispatcher - Cross-Cutting Concerns

Aspects handle functionality that spans multiple application parts:

/**
 * @InterceptWith(CacheAspect::class, ttl=300)
 * @InterceptWith(LoggingAspect::class)
 */
public function expensiveOperation() {
    // Automatically cached and logged
}

Aspect Types:

  • RequestAspect - Transforms incoming requests
  • BeforeAspect - Executes before method calls
  • AroundAspect - Wraps method execution
  • AfterAspect - Processes results after method completion

Execution Order

Aspect execution sequence:

  1. Class-level aspects apply first
  2. Method-level aspects override class aspects
  3. Request aspects transform the request
  4. Before aspects can short-circuit execution
  5. Around aspects wrap the method in nested calls
  6. After aspects process the result

Method Context

MethodContext - Execution Metadata

The MethodContext provides aspects with method execution details:

Available Data:

  • Target Object - Controller instance
  • Method Name - Executing method
  • Arguments - Method parameters
  • Reflection Data - Method signature metadata
  • Annotations - Parsed annotations
  • HTTP Request - Request object and session

Parameter Injection

Framework objects are injected based on type hints:

public function handleRequest(Request $request, SessionInterface $session) {
    // $request and $session injected automatically
}