Created
July 16, 2012 19:28
-
-
Save zergin/3124520 to your computer and use it in GitHub Desktop.
tonic: protected responseMessage use case
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
<?php | |
//... | |
require_once 'NotFoundResponse.php'; | |
try { | |
$response = $resource->exec(); | |
} catch (\Tonic\NotFoundException $e) { | |
$response = new NotFoundResponse; | |
} | |
//... |
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
<?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