<commit_before># bitexpert/pathfinder
A PHP routing component.

## How to use ...

Router
------

The router is responsible for resolving the target from the given route as well building an uri for a given 
route identifier (and it`s parameters). Using the Psr7Router (\bitExpert\Pathfinder\Psr7Router) is pretty easy:

```php
$baseUrl = 'http://myapp.loc:8080';
$router = new \bitExpert\Pathfinder\Psr7Router($baseUrl);
$router->setRoutes(
    [
        new Route('GET', '/', 'index'),
        new Route('GET', '/question/[:title]_[:id]', 'question'),
        new Route(['GET', 'POST'], '/editquestion', 'editquestion')
    ]
);
```

Routes
------
Routes in Pathfinder are implemented immutual. You may define your routes in several styles:

```php
new Route('GET', '/', 'index');
Route::create('GET', '/', 'index');
Route::get('/')->to('index');
Route::create()->from('/')->to('index')->accepting('GET');
Route::get('/pathtofunctarget')->to(function () {
    // callable target contents
})->named('routewithcallabletarget');
```

You may also mix all the styles above, just as you like, since every method returns a new instance of route.

Matchers
--------
Matchers are used to ensure that your route params match given criteria such as digits only:

```php
Route::get('/user/[:id]')->to('users')->ifMatches('id', new NumericMatcher());
```

## How to implement your own ...

Matchers
--------
Each matcher in Pathfinder must implement the \bitExpert\Pathfinder\Matcher\Matcher interface.

```php
class OnlyDigitMatcher implements \bitExpert\Pathfinder\Matcher\Matcher {
    public function match($value) {
        return ctype_digit($value);
    }
}
```

Routes
------
Routes in Pathfinder must be an instance of the \bitExpert\Pathfinder\Route class.

```php
$route = \bitExpert\Pathfinder\Route::get('/user/[:id]')->to('users')->ifMatches('id', new OnlyDigitMatcher());
```

Router
------
Each router in Pathfinder must implement the \bitExpert\Pathfinder\Router interface.

```php
use \Psr\Http\Message\ServerRequestInterface;
use \bitExpert\Pathfinder\Route;

class SimpleRouter implements \bitExpert\Pathfinder\Router {

 protected $routes = [];
 protected $defaultTarget;

 public function addRoute(Route $route) {
    $this->routes[] = $route;
    return $this;
 }
 
 public function setRoutes(array $routes) {
    foreach($routes as $route) {
        $this->addRoute($route);
    }
    return $this;
 }
 
 public function getTargetRequestAttribute() {
    return self::DEFAULT_TARGET_REQUEST_ATTRIBUTE;
 }
 
 public function setDefaultTarget($defaultTarget) {
    $this->defaultTarget = $defaultTarget;
    return $this;
 }
 
 public function match(ServerRequestInterface $request) {
    // using \bitExpert\Pathfinder\Psr7Router::match() logic ...
 }
 
 public function generateUri($routeIdentifier, array $params = []) {
     // using \bitExpert\Pathfinder\Psr7Router::generateUri() logic ...
 }
}
```





License
-------

Pathfinder is released under the Apache 2.0 license.<commit_msg>Added Travis and Versioneye badges.<commit_after># bitexpert/pathfinder
A PHP routing component.

[![Build Status](https://travis-ci.org/bitExpert/pathfinder.svg?branch=master)](https://travis-ci.org/bitExpert/pathfinder)
[![Dependency Status](https://www.versioneye.com/php/bitexpert:pathfinder/dev-master/badge?style=flat)](https://www.versioneye.com/php/bitexpert:pathfinder/dev-master)

Router
------

The router is responsible for resolving the target from the given route as well building an uri for a given 
route identifier (and it`s parameters). Using the Psr7Router (\bitExpert\Pathfinder\Psr7Router) is pretty easy:

```php
$baseUrl = 'http://myapp.loc:8080';
$router = new \bitExpert\Pathfinder\Psr7Router($baseUrl);
$router->setRoutes(
    [
        new Route('GET', '/', 'index'),
        new Route('GET', '/question/[:title]_[:id]', 'question'),
        new Route(['GET', 'POST'], '/editquestion', 'editquestion')
    ]
);
```

Routes
------
Routes in Pathfinder are implemented immutual. You may define your routes in several styles:

```php
new Route('GET', '/', 'index');
Route::create('GET', '/', 'index');
Route::get('/')->to('index');
Route::create()->from('/')->to('index')->accepting('GET');
Route::get('/pathtofunctarget')->to(function () {
    // callable target contents
})->named('routewithcallabletarget');
```

You may also mix all the styles above, just as you like, since every method returns a new instance of route.

Matchers
--------
Matchers are used to ensure that your route params match given criteria such as digits only:

```php
Route::get('/user/[:id]')->to('users')->ifMatches('id', new NumericMatcher());
```

License
-------

Pathfinder is released under the Apache 2.0 license.
{'fraction_non_alphanumeric': 0.16892464013547842, 'fraction_numerical': 0.004233700254022015, 'mean_word_length': 4.1923076923076925, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, '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': '6826860', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1394, 'n_words': 394}