Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

TimeIsGoOn/Macaw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

79 Commits

Repository files navigation

Macaw

Macaw is a simple, open source PHP router. It's super small (~150 LOC), fast, and sexy. This class allows you to jus throw it into your project and start using it immediately.

Install

If you have Composer, just include Macaw as a project dependency in your composer.json. If you don't just install it by downloading the .ZIP file and extracting it to your project directory.

require: {
 "noahbuscher/macaw": "dev-master"
}

Examples

First, use the Macaw namespace:

use \NoahBuscher\Macaw\Macaw;

Macaw is not an object, so you can just make direct operations to the class. Here's the Hello World:

Macaw::get('/', function() {
 echo 'Hello world!';
});
Macaw::dispatch();

Macaw also supports lambda URIs, such as:

Macaw::get('/(:any)', function($slug) {
 echo 'The slug is: ' . $slug;
});
Macaw::dispatch();

You can also make requests for HTTP methods in Macaw, so you could also do:

Macaw::get('/', function() {
 echo 'I <3 GET commands!';
});
Macaw::post('/', function() {
 echo 'I <3 POST commands!';
});
Macaw::dispatch();

Lastly, if there is no route defined for a certain location, you can make Macaw run a custom callback, like:

Macaw::error(function() {
 echo '404 :: Not Found';
});

If you don't specify an error callback, Macaw will just echo 404.


In order to let the server know the URI does not point to a real file, you need to use the included .htaccess file.

About

Simple PHP router class.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 96.0%
  • ApacheConf 2.7%
  • Nginx 1.3%

AltStyle によって変換されたページ (->オリジナル) /