# ToroPHP **Repository Path**: mirrors/ToroPHP ## Basic Information - **Project Name**: ToroPHP - **Description**: 一个非常小的PHP框架,主要是路由功能 - **Primary Language**: PHP - **License**: MIT - **Default Branch**: master - **Homepage**: https://www.oschina.net/p/toroweb - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1 - **Created**: 2021-03-08 - **Last Updated**: 2026-01-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Toro Toro is a PHP router for developing RESTful web applications and APIs. It is designed for minimalists who want to get work done. ## Quick Links - [Official Website](http://toroweb.org) - [Changelog](https://github.com/anandkunal/ToroPHP/wiki/Changelog) - [Design Goals](https://github.com/anandkunal/ToroPHP/wiki/Design-Goals) ## Features - RESTful routing using strings, regular expressions, and defined types (`number`, `string`, `alpha`) - Flexible error handling and callbacks via `ToroHook` - Intuitive and self-documented core (`Toro.php`) - Tested with PHP 5.3 and above ## "Hello, world" The canonical "Hello, world" example: ```php "HelloHandler", )); ``` ## Routing Basics Routing with Toro is simple: ```php "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](http://tornadoweb.org) (Python). Routes are not expressed as anonymous functions to prevent unnecessary code duplication for RESTful dispatching. 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: ```php "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: ```php installer.php $ less installer.php $ # When you're certain it's safe... $ php installer.php ``` Create a `composer.json` file in your project root: ```js { "require": { "torophp/torophp": "dev-master" } } ``` Install via composer: ```sh $ php composer.phar install ``` ### Server Configuration #### Apache You may need to add the following snippet in your Apache HTTP server virtual host configuration or **.htaccess** file. ```apacheconf RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond $1 !^(index\.php) RewriteRule ^(.*)$ /index.php/$1 [L] ``` Alternatively, if you’re lucky enough to be using a version of Apache greater than 2.2.15, then you can instead just use this one, single line: ```apacheconf FallbackResource /index.php ``` #### IIS For IIS you will need to install URL Rewrite for IIS and then add the following rule to your `web.config`: ```xml ``` #### Nginx Under the `server` block of your virtual host configuration, you only need to add three lines. ```conf location / { try_files $uri $uri/ /index.php?$args; } ``` ## Contributions - Toro was inspired by the [Tornado Web Server](http://www.tornadoweb.org) (FriendFeed/Facebook) - [Berker Peksag](http://berkerpeksag.com), [Martin Bean](http://www.martinbean.co.uk), [Robbie Coleman](http://robbie.robnrob.com), and [John Kurkowski](http://about.me/john.kurkowski) for bug fixes and patches - [Danillo César de O. Melo](https://github.com/danillos/fire_event/blob/master/Event.php) for `ToroHook` - [Jason Mooberry](http://jasonmooberry.com) for code optimizations and feedback Contributions to Toro are welcome via pull requests. ## License ToroPHP was created by [Kunal Anand](http://kunalanand.com) and released under the MIT License.