Toro - 基于PHP的REST开发框架

[复制链接]
查看11 | 回复6 | 2014-2-19 11:55:14 | 显示全部楼层 |阅读模式
Toro is a PHP router for developing RESTful web applications and APIs. It is designed for minimalists who want to get work done.
Features
1. RESTful routing using strings, regular expressions, and defined types (number, string, alpha)
2. Flexible error handling and callbacks via ToroHook
3. Intuitive and self-documented core (toro.php)
4. Tested with PHP 5.3 and above
"Hello, world"
The canonical "Hello, world" example:
"HelloHandler",
));复制代码


回复

使用道具 举报

千问 | 2014-2-19 11:55:14 | 显示全部楼层
Routing Basics
Routing with Toro is simple: "SplashHandler",
"/catalog/page/:number" => "CatalogHandler",
"/product/:alpha" => "ProductHandler",
"/manufacturer/:string" => "ManufacturerHandler"
));复制代码An application's route table is expressed as an associative array (route_pattern => handler). This is closely modeled after Tornado (Python). Routes are not expressed as anonymous functions to prevent unnecessary code duplication for RESTful dispatching.

回复

使用道具 举报

千问 | 2014-2-19 11:55:14 | 显示全部楼层
From the above example, route stubs, such as :number, :string, and :alpha can be conveniently used instead of common regular expressions. Of course, regular expressions are still welcome. The previous example could also be expressed as:
"SplashHandler",
"/catalog/page/([0-9]+)" => "CatalogHandler",
"/product/([a-zA-Z0-9-_]+)" => "ProductHandler",
"/manufacturer/([a-zA-Z]+)" => "ManufacturerHandler"
));复制代码Pattern matches are passed in order as arguments to the handler's request method. In the case of ProductHandler above:复制代码
回复

使用道具 举报

千问 | 2014-2-19 11:55:14 | 显示全部楼层
RESTful Handlers复制代码From the above, you can see two emergent patterns.
Methods named after the HTTP request method (GET, POST, PUT, DELETE) are automatically called.
Appending _xhr to a handler method automatically matches JSON/XMLHTTPRequest requests. If the _xhr method is not implemented, then the given HTTP request method is called as a fallback.
回复

使用道具 举报

千问 | 2014-2-19 11:55:14 | 显示全部楼层
ToroHook (Callbacks)
As of v2.0.0, there are a total of five Toro-specific hooks (callbacks):复制代码before_handler and after_handler are defined within handler's constructor:复制代码
回复

使用道具 举报

千问 | 2014-2-19 11:55:14 | 显示全部楼层

Hooks can also be stacked. Adding a hook pushes the provided anonymous function into an array. When a hook is fired, all of the functions are called sequentially.
Installation
Grab a copy of the repository and move toro.php to your htdocs or library directory. You may need to add the following snippet in your Apache virtual host configuration or .htaccess:RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php/$1 [L]复制代码
回复

使用道具 举报

千问 | 2014-2-19 11:55:14 | 显示全部楼层
over.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行