To understand Tonic, you need to get the Web, so forget everything you know for a minute and think about how the Web really works, it's not about HTML pages, it's about resources:
- Everything useful is a resource, not a file, not a CGI script, a resource, an abstract concept of something useful that the client wants to grab hold of.
- Resources are located by URLs, URLs are cheap and form the universal addressing system of the Web.
- Clients can issue a standard number of HTTP methods upon an infinite number of resources and receive something useful in return.
- Representations of resources are sent back to the client, a representation is just a way of turning the abstract concept of a resource into something more concrete, like a HTML page or a XML file. One resource can have many different representations.
Tonic helps you develop Web applications that embrace the way the Web really works, enabling your applications to scale, extend and work with other systems easily.
Quick Example
Front controller
Tonic uses the common front controller pattern to push all required traffic to a single script that then dispatches the request to the correct piece of developer logic to handle the request. The typical dispatcher PHP file looks like:
docroot/dispatch.php
Defining resources
With the dispatcher set up and all requests being forwarded to it by the Web server, we can then define a resource class to handle a request to a specific URL:
resource/example.php
Features
- Content negotiation
- Content and language negotiation support allowing you to easily pick the best representation for the client request.
- Output encoding
- Built-in support for compressed responses.
- Client side caching
- Support for sending correct cache control headers, entity tags, and 304 response codes.
- Collection resources
- Support for managing a collection of resources.
What Next?
The best place to start is to have a read through the README, then dig into the code and the examples.
Please checkout the code and have a play, comments and pull requests most welcome.