Skip to content

Instantly share code, notes, and snippets.

@meadsteve
Last active August 26, 2015 08:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meadsteve/21b85be1f79ac07fb750 to your computer and use it in GitHub Desktop.
Save meadsteve/21b85be1f79ac07fb750 to your computer and use it in GitHub Desktop.
Api !== Http
<?
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