Skip to content

Instantly share code, notes, and snippets.

@leocavalcante
Created January 8, 2020 23:18
Show Gist options
  • Save leocavalcante/39b82d57f00b876d40593bfa9d59d3e4 to your computer and use it in GitHub Desktop.
Save leocavalcante/39b82d57f00b876d40593bfa9d59d3e4 to your computer and use it in GitHub Desktop.
<?php
class HttpHandler {
private Database $db;
public function __construct(Database $db) {
$this->db = $db;
}
public function handleRequest() {
$factory = new Task\Factory();
$validator = new Task\Validator();
$task = $factory->fromHttpRequest($request);
if ($validator->validate($task)) {
if ($this->db->insertTask($task)) {
return HttoSuccess;
}
return HttpFailure;
}
return HttpInvalid;
}
}
class WebSocketHandler {
private Database $db;
public function __construct(Database $db) {
$this->db = $db;
}
public function handleRequest() {
$factory = new Task\Factory();
$validator = new Task\Validator();
$task = $factory->fromWebSocketFrame($frame);
if ($validator->validate($task)) {
if ($this->db->insertTask($task)) {
return WSSuccess;
}
return WSFailure;
}
return WSInvalid;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment