Skip to content

Instantly share code, notes, and snippets.

@TorbenKoehn
Last active July 8, 2016 10:57
Show Gist options
  • Save TorbenKoehn/9ada8d17d615ce6b40bbaa7228cf4194 to your computer and use it in GitHub Desktop.
Save TorbenKoehn/9ada8d17d615ce6b40bbaa7228cf4194 to your computer and use it in GitHub Desktop.
<?php
class Request
{
//...
public function __cast($type) {
switch ($type) {
case Response::class:
$headers = [];
//Create fitting headers based on request headers, e.g languages, content-type, compression, caching etc.
return new Response(200, $headers);
case 'array':
return ['uri' => $this->uri, 'headers' => $this->headers, 'body' => $this->body];
}
}
}
$response = (Response)$request;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment