Last active
August 26, 2015 08:45
-
-
Save meadsteve/21b85be1f79ac07fb750 to your computer and use it in GitHub Desktop.
Api !== Http
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
class Api { | |
const SUCCESS = 0; | |
const FAILURE = 13; | |
public function doThingOne($SomeArgument) | |
{ | |
// do something | |
return self::SUCCESS; | |
} | |
public function doThingTwo($SomeArgument) | |
{ | |
// do something else | |
if (bad_thing_happened()) { | |
return self::FAILURE; | |
} | |
return self::SUCCESS; | |
} | |
} | |
class HttpApi | |
{ | |
private $api; | |
public function __construction(Api $api) | |
{ | |
$this->api = $api; | |
} | |
public function post($route, $request) | |
{ | |
//.. do stuff with request & route | |
$result = $this->api->doThingOne($data); | |
if ($result == Api::Success) { | |
return new Response(HTTPCODE::OK); | |
} else { | |
return new Response(HTTPCODE::SERVER_ERROR); | |
} | |
} | |
} | |
class CommandLineApi | |
{ | |
private $api; | |
public function __construction(Api $api) | |
{ | |
$this->api = $api; | |
} | |
public function execute($command_line_args, $output) | |
{ | |
//.. do stuff with $command_line_args | |
$result = $this->api->doThingOne($data); | |
if ($result != Api::Success) { | |
$output->write("something went wrong!!!"); | |
} | |
return (int) $result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment