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:
- BeforeAspect - Executes before method calls
- AroundAspect - Wraps method execution
- AfterAspect - Processes results after method completion
Execution Order
Aspect execution sequence:
- Aspects are collected across the full inheritance hierarchy: grandparent → parent → current class → method
- Within each level, aspects are sorted by
priority(higher value executes first, default 0) - Before aspects run in that order — returning a Response short-circuits 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 via
getClass() - Class Name - Fully qualified class name via
getClassName() - Method Name - Executing method via
getMethodName() - Arguments - Method parameters via
getArguments() - HTTP Request - Request object via
getRequest()/setRequest()
Parameter Injection
Framework objects are injected based on type hints:
public function handleRequest(Request $request, SessionInterface $session) {
// $request and $session injected automatically
}