Created
July 22, 2012 23:02
-
-
Save zergin/3161318 to your computer and use it in GitHub Desktop.
Extendable responses
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 | |
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(); | |
} | |
} |
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 | |
try { | |
// ... | |
} catch (\Tonic\NotFoundException $e) { | |
$response = new Responses\NotFound; | |
} catch (\Exception $e) { | |
$response = new Responses\InternalServerError; | |
} |
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 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