<commit_before># Patchboard: A simple and fast PHP routing library.

Building on top of [nikic/fastroute](https://github.com/nikic/fastroute), and inspired by the routing
portion of the [Macaron](http://go-macaron.com/) web framework, this library is a simple, extensible,
non-opinionated, and fast routing library for PHP web applications and services.

# Example

They say an example is worth a thousand words.

```php
<?php

$req = Request::createFromGlobals();
$container->set(Request::class, $req);

$invoker = new Invoker\Invoker;
$invoker->getParameterResolver()->prependResolver(new TypeHintContainerResolver($container));

$r = new Patchboard\Router(new InvokerInvoker($invoker));

$authorized = function(Request $req) {
  list($user, $pass) = explode(':', base64_decode(explode(' ', $req->headers->get('Authorization'))[1]));
  if ($user != 'admin' && $pass != '<PASSWORD>') {
    return new JSONResponse(['message'=>'Not Authorized'], 403);
  }
};

$r->group('/users', function($r) {
  $r->get('/', 'MyApp\Controllers\Users::getAll');
  $r->post('/', 'MyApp\Controllers\Users::create');
}, $authorized);

try {
  $response = $r->dispatch($req->getMethod(), $req->getPathInfo());
}
catch (Patchboard\RouteNotFoundException $ex) {
  $response = new JSONResponse(['message' => $ex->getMessage()], 404);
}
catch (Patchboard\MethodNotAllowedException $ex) {
  $response = new JSONResponse(['message' => $ex->getMessage()], 405, ['Allow' => $ex->getAllowed()]);
}

$response->send();
```

Put into words:

1. Create a Request object from global variables (from the [symfony/http-foundation](https://github.com/symfony/http-foundation) library)
2. Register the request with your DI container (can be any implementation, I'd recommend [php-di/php-di](https://github.com/php-di/php-di))
3. Create a new Invoker (from the [php-di/invoker](https://github.com/php-di/invoker) library), and instruct it to resolve parameters from your DI container
4. Create a new Router object, and use an `InvokerInvoker` to utilize the Invoker library and object
5. Create the "authorized" handler. This is just a function that returns a 403 if the user is not authorized.<commit_msg>Make README example narrower<commit_after># Patchboard: A simple and fast PHP routing library.

Building on top of [nikic/fastroute](https://github.com/nikic/fastroute), and inspired by the routing
portion of the [Macaron](http://go-macaron.com/) web framework, this library is a simple, extensible,
non-opinionated, and fast routing library for PHP web applications and services.

# Example

They say an example is worth a thousand words. Or that might be something else.

```php
<?php

$req = Request::createFromGlobals();
$container->set(Request::class, $req);

$invoker = new Invoker\Invoker;
$invoker->getParameterResolver()->prependResolver(
  new TypeHintContainerResolver($container)
);

$r = new Patchboard\Router(new InvokerInvoker($invoker));

$authorized = function(Request $req) {
  list($user, $pass) = explode(':', base64_decode(
    explode(' ', $req->headers->get('Authorization'))[1]
  ));
  if ($user != 'admin' && $pass != '<PASSWORD>') {
    return new JSONResponse(['message'=>'Not Authorized'], 403);
  }
};

$r->group('/users', function($r) {
  $r->get('/', 'MyApp\Controllers\Users::getAll');
  $r->post('/', 'MyApp\Controllers\Users::create');
}, $authorized);

try {
  $response = $r->dispatch($req->getMethod(), $req->getPathInfo());
}
catch (Patchboard\RouteNotFoundException $ex) {
  $response = new JSONResponse(['message' => $ex->getMessage()], 404);
}
catch (Patchboard\MethodNotAllowedException $ex) {
  $response = new JSONResponse(['message' => $ex->getMessage()], 405,
    ['Allow' => $ex->getAllowed()]);
}

$response->send();
```

Put into words:

1. Create a Request object from global variables (from the [symfony/http-foundation](https://github.com/symfony/http-foundation) library)
2. Register the request with your DI container (can be any implementation, I'd recommend [php-di/php-di](https://github.com/php-di/php-di))
3. Create a new Invoker (from the [php-di/invoker](https://github.com/php-di/invoker) library), and instruct it to resolve parameters from your DI container
4. Create a new Router object, and use an `InvokerInvoker` to utilize the Invoker library and object
5. Create the "authorized" handler. This is just a function that returns a 403 if the user is not authorized.
{'fraction_non_alphanumeric': 0.16068181818181818, 'fraction_numerical': 0.00909090909090909, 'mean_word_length': 5.296137339055794, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 43, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5228375', 'n_tokens_mistral': 1368, 'n_tokens_neox': 1329, 'n_words': 412}