Tonic


Tyrell\Hello
src/Tyrell/Hello.php at line 18

Class Hello

Resource
└─Hello

public class Hello
extends Resource

The obligitory Hello World example

The @uri annotation routes requests that match that URL to this resource. Multiple annotations allow this resource to match multiple URLs.

Uri:
/hello
/hello/:name

Fields inherited from Tonic\Resource
params
Method Summary
str

sayHello(str name)

Use this method to handle GET HTTP requests.

str

sayHelloInFrench(str name)

str

replicants()

The @priority annotation makes this method take priority over the above method.

str

iveSeenThings()

protected void

only(mixed allowedName)

Condition method for above methods.

Response

sayHelloComputer()

The @provides annotation makes method only match requests that have a suitable accept header or URL extension (ie: /hello.json) and causes the response to automatically contain the correct content-type response header.

protected void

json()

Condition method to turn output into JSON

Response

feedTheComputer()

All HTTP methods are supported.

Methods inherited from Tonic\Resource
__construct, accepts, after, before, cache, exec, lang, method, priority, provides

Method Detail

src/Tyrell/Hello.php at line 33

sayHello

public str sayHello(str name)

Use this method to handle GET HTTP requests.

The optional :name parameter in the URL available as the first parameter to the method or as a property of the resource as $this->name.

Method can return a string response, an HTTP status code, an array of status code and response body, or a full Tonic\Response object.

Method:
GET

src/Tyrell/Hello.php at line 44

sayHelloInFrench

public str sayHelloInFrench(str name)

Method:
GET
Lang:
fr

src/Tyrell/Hello.php at line 60

replicants

public str replicants()

The @priority annotation makes this method take priority over the above method.

The custom @only annotation requires the matching class method to execute without throwing an exception allowing the addition of an arbitary condition to this method.

Method:
GET
Priority:
2
Only:
deckard

src/Tyrell/Hello.php at line 71

iveSeenThings

public str iveSeenThings()

Method:
GET
Priority:
2
Only:
roy

src/Tyrell/Hello.php at line 81

only

protected void only(mixed allowedName)

Condition method for above methods.

Only allow specific :name parameter to access the method


src/Tyrell/Hello.php at line 96

sayHelloComputer

public Response sayHelloComputer()

The @provides annotation makes method only match requests that have a suitable accept header or URL extension (ie: /hello.json) and causes the response to automatically contain the correct content-type response header.

Method:
GET
Provides:
application/json
Json.

src/Tyrell/Hello.php at line 107

json

protected void json()

Condition method to turn output into JSON


src/Tyrell/Hello.php at line 136

feedTheComputer

public Response feedTheComputer()

All HTTP methods are supported. The @accepts annotation makes method only match if the request body content-type matches.

curl -i -H "Content-Type: application/json" -X POST -d '{"hello": "computer"}' http://localhost/www/tonic/web/hello.json

Method:
POST
Accepts:
application/json
Provides:
application/json
Json.

Tonic