<commit_before>Routing
=======

[![Build Status](https://travis-ci.org/felipecwb/Routing.svg?branch=master)](https://travis-ci.org/felipecwb/Routing)
[![Latest Stable Version](https://poser.pugx.org/felipecwb/routing/v/stable.svg)](https://packagist.org/packages/felipecwb/routing)
[![License](https://poser.pugx.org/felipecwb/routing/license.svg)](https://packagist.org/packages/felipecwb/routing)


More one simple Routing library for PHP.

*You'll need know about [Regex Patterns](http://php.net/manual/en/pcre.pattern.php).*

## Instalation
[Composer](https://packagist.org/packages/felipecwb/routing):
```json
{
    "felipecwb/routing": "dev-master"
}
```

**Example**:
```php
<?php

use Felipecwb\Routing\Router;
use Felipecwb\Routing\Route;
use Felipecwb\Routing\RouteCollection;
use Felipecwb\Routing\Matcher;
use Felipecwb\Routing\Resolver\CallableResolver;
// Exceptions
use Felipecwb\Routing\Exception\ResolverException;
use Felipecwb\Routing\Exception\RouteNotFoundException;

$router = new Router(
    new Matcher(
        new RouteCollection()
    ),
    new CallableResolver()
);

$router->add(new Route('|/|', function () {
    echo "Hello World!";
});

$router->add(new Route('|/hello/(\w+)|', function ($name) {
    echo "Hello {$name}!";
});

$router->add(new Route('|/article/(\d+)|', function ($id, $extraStr) {
    echo "Article {$id}! ${extraStr}";
});

try {
    $router->dispatch('/'); // output: Hello World!
    // with arguments
    $router->dispatch('/hello/felipecwb'); // output: Hello felipecwb!
    // with extra arguments
    $router->dispatch('/hello/10', ['Extra String!']); // output: Article 10! Extra String!
} catch (RouteNotFoundException $e) {
    echo "Sorry! The target can not be found!";
} catch (ResolverException $e) {
    echo "Sorry! The target can not be executed!";
}

die;
```<commit_msg>Fixing wrong sample<commit_after>Routing
=======

[![Build Status](https://travis-ci.org/felipecwb/Routing.svg?branch=master)](https://travis-ci.org/felipecwb/Routing)
[![Latest Stable Version](https://poser.pugx.org/felipecwb/routing/v/stable.svg)](https://packagist.org/packages/felipecwb/routing)
[![License](https://poser.pugx.org/felipecwb/routing/license.svg)](https://packagist.org/packages/felipecwb/routing)


More one simple Routing library for PHP.

*You'll need know about [Regex Patterns](http://php.net/manual/en/pcre.pattern.php).*

## Instalation
[Composer](https://packagist.org/packages/felipecwb/routing):
```json
{
    "felipecwb/routing": "dev-master"
}
```

**Example**:
```php
<?php

use Felipecwb\Routing\Router;
use Felipecwb\Routing\Route;
use Felipecwb\Routing\RouteCollection;
use Felipecwb\Routing\Matcher;
use Felipecwb\Routing\Resolver\CallableResolver;
// Exceptions
use Felipecwb\Routing\Exception\ResolverException;
use Felipecwb\Routing\Exception\RouteNotFoundException;

$router = new Router(
    new Matcher(
        new RouteCollection()
    ),
    new CallableResolver()
);

$router->add(new Route('|/|', function () {
    echo "Hello World!";
}));

$router->add(new Route('|/hello/(\w+)|', function ($name) {
    echo "Hello {$name}!";
}));

$router->add(new Route('|/article/(\d+)|', function ($id, $extraStr) {
    echo "Article {$id}! ${extraStr}";
}));

try {
    $router->dispatch('/'); // output: Hello World!
    // with arguments
    $router->dispatch('/hello/felipecwb'); // output: Hello felipecwb!
    // with extra arguments
    $router->dispatch('/hello/10', ['Extra String!']); // output: Article 10! Extra String!
} catch (RouteNotFoundException $e) {
    echo "Sorry! The target can not be found!";
} catch (ResolverException $e) {
    echo "Sorry! The target can not be executed!";
}

die;
```
{'fraction_non_alphanumeric': 0.18829585478190192, 'fraction_numerical': 0.002167434299647792, 'mean_word_length': 4.568627450980392, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 14, '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': '1384935', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1284, 'n_words': 240}