Revision 6528,
1.2 KB
checked in by gustavo, 12 years ago
(diff) |
Ticket #2766 - Merge do branch das novas funcionalidaes para o trunk
|
-
Property svn:executable set to
*
|
Rev | Line | |
---|
[6351] | 1 | <?php |
---|
| 2 | |
---|
| 3 | /** |
---|
| 4 | * The Hello World of Tonic |
---|
| 5 | * |
---|
| 6 | * This example outputs a simple hello world message and the details of the |
---|
| 7 | * request and response as generated by Tonic. It also demonstrates etags and |
---|
| 8 | * "if none match" functionality. |
---|
| 9 | * |
---|
| 10 | * @namespace Tonic\Examples\Helloworld |
---|
| 11 | * @uri /helloworld |
---|
| 12 | */ |
---|
| 13 | class HelloWorldResource extends Resource { |
---|
| 14 | |
---|
| 15 | /** |
---|
| 16 | * Handle a GET request for this resource |
---|
| 17 | * @param Request request |
---|
| 18 | * @return Response |
---|
| 19 | */ |
---|
| 20 | function get($request) { |
---|
| 21 | |
---|
| 22 | $response = new Response($request); |
---|
| 23 | |
---|
| 24 | $etag = md5($request->uri); |
---|
| 25 | if ($request->ifNoneMatch($etag)) { |
---|
| 26 | |
---|
| 27 | $response->code = Response::NOTMODIFIED; |
---|
| 28 | |
---|
| 29 | } else { |
---|
| 30 | |
---|
| 31 | $response->code = Response::OK; |
---|
| 32 | $response->addHeader('Content-type', 'text/plain'); |
---|
| 33 | $response->addEtag($etag); |
---|
| 34 | $response->body = |
---|
| 35 | "Hello world!\n". |
---|
| 36 | "\n". |
---|
| 37 | "This request:\n". |
---|
| 38 | "\n". |
---|
| 39 | $request->__toString()."\n". |
---|
| 40 | "\n". |
---|
| 41 | "This response:\n". |
---|
| 42 | "\n". |
---|
| 43 | $response->__toString(); |
---|
| 44 | |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | return $response; |
---|
| 48 | |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | } |
---|
| 52 | |
---|
Note: See
TracBrowser
for help on using the repository browser.