Skip to content

Instantly share code, notes, and snippets.

@zergin
Created July 16, 2012 19:28
Show Gist options
  • Save zergin/3124520 to your computer and use it in GitHub Desktop.
Save zergin/3124520 to your computer and use it in GitHub Desktop.
tonic: protected responseMessage use case
<?php
//...
require_once 'NotFoundResponse.php';
try {
$response = $resource->exec();
} catch (\Tonic\NotFoundException $e) {
$response = new NotFoundResponse;
}
//...
<?php
class NotFoundResponse extends Tonic\Response
{
public function __construct($code = Tonic\Response::NOTFOUND, $message = '')
{
$this->code = $code;
$this->body = ['code' => $code, 'message' => ($message ?: $this->responseMessage()) ];
$this->body = json_encode($this->body);
$this->contentType = 'application/json';
}
// ..
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment