PHPackages                             tcdev/macaw - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. tcdev/macaw

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tcdev/macaw
===========

Simple PHP router class.

v1.0.0(2y ago)02MITPHPPHP &gt;=5.3.3

Since Oct 25Pushed 2y agoCompare

[ Source](https://github.com/thrivecart/macaw)[ Packagist](https://packagist.org/packages/tcdev/macaw)[ RSS](/packages/tcdev-macaw/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Macaw
=====

[](#macaw)

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

### Install

[](#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: {
    "marcfowler/macaw": "dev-master"
}

```

### Examples

[](#examples)

First, `use` the Macaw namespace:

```
use \marcfowler\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();
```

You can specify a prefix which will be added to all of your routes. This is useful to prevent duplication if you know you're running behind a particular URL that isn't always defined by the directory you're executing from. For example, if you know your file is accessed at `/subfolder/somewhere-else/`, you can:

```
Macaw::setPrefix('/subfolder/somewhere-else/');
Macaw::get('/', function() {
  echo 'Hello!';
});
```

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
