Skip to content

Instantly share code, notes, and snippets.

@zergin
Created July 22, 2012 23:02
Show Gist options
  • Save zergin/3161318 to your computer and use it in GitHub Desktop.
Save zergin/3161318 to your computer and use it in GitHub Desktop.
Extendable responses
<?php
use Tonic\Response;
abstract class Error extends Response
{
public function output()
{
$this->body = ['code' => $this->responseCode(), 'message' => $this->responseMessage() ];
$this->body = json_encode($this->body);
$this->contentType = 'application/json';
return parent::output();
}
}
<?php
try {
// ...
} catch (\Tonic\NotFoundException $e) {
$response = new Responses\NotFound;
} catch (\Exception $e) {
$response = new Responses\InternalServerError;
}
<?php
class NotFound extends Error
{
public $code = self::NOTFOUND;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment