The Chain of Responsibility Conduit
Pass a chaotic request along a chain of handlers until one captures it.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Chain of Responsibility
ARCANUM SCHOOL: Evocation // Channeling
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// PHP PATTERN //
<?php
namespace Tekromancy\WebChaos;
abstract class MiddlewareHandler {
private ?MiddlewareHandler $next = null;
public function setNext(MiddlewareHandler $handler): MiddlewareHandler {
$this->next = $handler;
return $handler;
}
public function handle(array $request): ?string {
if ($this->next) {
return $this->next->handle($request);
}
return null;
}
}
class FirewallHandler extends MiddlewareHandler {
public function handle(array $request): ?string {
if (isset($request['malicious'])) {
return "Firewall Blocked Chaos!";
}
return parent::handle($request);
}
}
The Chain of Responsibility Conduit
In the realm of HTTP chaos, incoming requests are bombarded by myriad filters, wards, and authenticators. The Chain of Responsibility links these handlers dynamically. If the FirewallHandler cannot process the chaos, it passes the burden along the conduit until a capable ward intervenes.
Runic Tags:
#web-chaos-magic
#elephants-curse
#php8