Toro is a PHP router for developing RESTful web applications and APIs.
Toro is a PHP router for developing RESTful web applications and APIs.
Toro is a PHP router for developing RESTful web applications and APIs. It is designed for minimalists who want to get work done.
number, string, alpha)ToroHookToro.php)The canonical "Hello, world" example:
"HelloHandler",
));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.
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:
installer.php
$ less installer.php
$ # When you're certain it's safe...
$ php installer.phpCreate a composer.json file in your project root:
{
"require": {
"torophp/torophp": "dev-master"
}
}Install via composer:
$ php composer.phar installYou may need to add the following snippet in your Apache HTTP server virtual host configuration or .htaccess file.
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:
FallbackResource /index.phpFor IIS you will need to install URL Rewrite for IIS and then add the following rule to your web.config:
Under the server block of your virtual host configuration, you only need to add three lines.
location / {
try_files $uri $uri/ /index.php?$args;
}ToroHookContributions to Toro are welcome via pull requests.
ToroPHP was created by Kunal Anand and released under the MIT License.
No open issues yet, or sync has not completed.