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:
- Kernel receives HTTP request
- AnnotationResolver matches URL to controller method
- AspectDispatcher applies aspects
- Controller method executes
- 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/Controllersfor@Routeannotations - 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:
- Parse URL into segments
- Scan controllers for route annotations
- Match segment count and HTTP method
- Extract variables from parameterized segments
- 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:
- Class-level aspects apply first
- Method-level aspects override class aspects
- Request aspects transform the request
- Before aspects can short-circuit execution
- Around aspects wrap the method in nested calls
- 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
}