PHPackages                             bake/bob - 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. bake/bob

ActiveLibrary

bake/bob
========

Very basic routing class

2122PHP

Since Sep 6Pushed 9y ago1 watchersCompare

[ Source](https://github.com/BakeRolls/Bob)[ Packagist](https://packagist.org/packages/bake/bob)[ RSS](/packages/bake-bob/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Bob
===

[](#bob)

Very basic routing class ([about 103 lines](https://github.com/BakeRolls/Bob/blob/master/Bob.php#L103)) ...

tl;dr
-----

[](#tldr)

```
Bob::get($pattern, $callback);
```

is short for

```
Bob::add('get', $pattern, $callback);
```

`$method` and `$pattern` can either be strings or arrays of strings. `$callback`s are [one](#routes) or [more functions](#callbacks) or a [class](#a-class-as-callback).

```
Bob::go($file);
```

Usage
-----

[](#usage)

### Routes

[](#routes)

Add a route:

```
Bob::get('/', function() {
	echo 'Hello World';
});
```

A little bit more:

```
Bob::get('/user/bob', function() {
	echo 'Hey, bob!';
});
```

Add a bunch of patterns:

```
Bob::get(['/', '/home'], function() {
	echo 'Hello World';
});
```

Use a function:

```
Bob::get('/user/:is_numeric', function($id) {
	echo 'Hello, '.$user[$id];
});
```

Use an own function:

```
Bob::get('/user/:is_user', function($user) {
	echo 'Hey, '.$user.'!';
});

function is_user($user) {
	return in_array($user, ['Justus', 'Peter', 'Bob']);
}
```

Negate:

```
Bob::get('/user/:is_user', function($user) {
	echo 'Hey, '.$user.'!';
});

Bob::get('/user/!is_user', function($user) {
	echo 'Can\'t find this user :(';
});
```

You can also use regex (in the same way you'd use a function):

```
Bob::$patterns = [
	'num' => '[0-9]+',
	'all' => '.*'
];

Bob::get('/:num', function($id) {
	echo $id;
});
```

### Callbacks

[](#callbacks)

Use multiple callbacks:

```
Bob::get('/user/:is_numeric', [function($id) {
	echo 'Hello, '.$user[$id];
}, count_login($id)]);
```

Multiple request methods:

```
Bob::add(['post', 'put'], '/user', function() {
	// Add a user! Or something else! I don't care!
});
```

### A Class as Callback

[](#a-class-as-callback)

Your can also use a class as callback. Just pass its name. Bob will try to execute `$method` on `$callback`, so something like this will work:

```
class SayHello {
	static function get($num) {
		for($i = 0; $i < $num; $i++)
			echo 'GET Hello!';
	}

	static function post($num) {
		for($i = 0; $i < $num; $i++)
			echo 'POST Hello!';
	}
}
```

```
Bob::add([], '/:is_numeric', 'SayHello');
```

Notice that you have to use `Bob::add()` with an empty array. In this case, you're not required to tell Bob the accepted HTTP methods, it'll just look inside the provided class.

### Execute

[](#execute)

With the *use-an-own-function-example* from above, the ([second](#if-nothing-was-found)) final step could look like this:

```
Bob::go();
```

Or - if you'd like to work in a subdirectory - trim the request url:

```
Bob::go('/foo/bar.php');
```

`http://localhost/foo/bar.php/user/1` `=>` `/user/1`

### If nothing was found

[](#if-nothing-was-found)

404:

```
Bob::summary(function($passed, $refused) {
	echo $passed.' routes passed, '.$refused.' were refused.';
});
```

This will only execute the callback, if no rule matched the request:

```
Bob::notfound(function($passed, $refused) {
	echo '404 :(';
});
```

You're done. Have a nice day.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/49896052?v=4)[bake](/maintainers/BakeRolls)[@bakerolls](https://github.com/bakerolls)

---

Top Contributors

[![bake](https://avatars.githubusercontent.com/u/1502822?v=4)](https://github.com/bake "bake (39 commits)")[![Keyes](https://avatars.githubusercontent.com/u/185757?v=4)](https://github.com/Keyes "Keyes (2 commits)")

### Embed Badge

![Health badge](/badges/bake-bob/health.svg)

```
[![Health](https://phpackages.com/badges/bake-bob/health.svg)](https://phpackages.com/packages/bake-bob)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
