Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sirodiaz/routify
A simple PHP router.
https://github.com/sirodiaz/routify
php php-router router routify
Last synced: about 2 months ago
JSON representation
A simple PHP router.
- Host: GitHub
- URL: https://github.com/sirodiaz/routify
- Owner: SiroDiaz
- License: mit
- Created: 2016-01-24T23:22:39.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-08-10T08:56:10.000Z (over 8 years ago)
- Last Synced: 2024-05-03T14:17:33.592Z (8 months ago)
- Topics: php, php-router, router, routify
- Language: PHP
- Homepage:
- Size: 42 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Routify
=======
[![Build Status](https://travis-ci.org/SiroDiaz/Routify.svg)](https://travis-ci.org/SiroDiaz/Routify)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/SiroDiaz/Routify/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/SiroDiaz/Routify/?branch=master)A simple PHP router inspired in Express framework.
Routify is a fast and flexible router for PHP 5.4 and higher.
- Flexible regular expression routing (inspired by Express)
- Concrete use. Focused in do well one thing
- Easy to learn. Simple API that will remember you Express or Slim### Getting started
1. PHP 5.4.x is required
2. Install Routify using Composer (recommended) or manually
3. Setup URL rewriting so that all requests are handled by index.php, for example, using an .htaccess file### Example
```php
require 'vendor/autoload.php';$router = new Routify\Router();
$middleware1 = function() {
echo "middleware 1";
};$middleware2 = function() {
echo "middleware 2";
};$router->get('/', function() {
echo "This is an action";
},
['before' => $middleware1, 'after' => $middleware2]
);$router->get('/post/:slug/:id', function($slug, $id) {
echo "You are seeing the post nº $id, with title: $slug";
});$router->post('/new', function() {
// something for the POST /new
});$router->put('/', function() {
// something for the PUT /
});$router->delete('/:id', function($id) {
// something for the DELETE /:id
});$router->both('/hello/world', function() {
// something for GET and POST requests
}, ['GET', 'POST']);$router->any('/bye', function() {
// something for any request method
}, ['before' => $middleware1, 'after' => $middleware2]);// regular expression route
$router->get('/(login|logout), function() {
// response for the login or logout route requested
});$router->run();
```### Tests and submit code
New features or modifications must be tested with **PHPUnit** previously to pull requests of new code.