Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/webchemistry/router

Routes with priority for modular application
https://github.com/webchemistry/router

modular-routers priority-routes router routes

Last synced: about 1 month ago
JSON representation

Routes with priority for modular application

Awesome Lists containing this project

README

        

# WebChemistry/router

## Overview

- [Installation](README.md#Installation)
- [Configuration](README.md#Configuration)
- [Main router](README.md#Main-router)
- [Use autoregistration in own extension](README.md#Usage-autoregistration-in-own-extension)

## Installation

Install via composer.

```sh
composer require webchemistry/router
```

neon:
```yaml
extensions:
routers: WebChemistry\Routing\DI\RouterExtension
```

## Configuration
```yaml
routers:
modules:
- Front
- Admin
routers:
- App\MainRouter
- YourRouter
- HisRouter
```

## Main router

```php
addStyle('name');
$routeManager->setStyleProperty('name', Route::FILTER_OUT, function($url) {
return Strings::webalize($url);
});
$routeManager->setStyleProperty('name', Route::FILTER_IN, function($url) {
return Strings::webalize($url);
});

// Admin
$admin = $routeManager->getModule('Admin');
$admin[] = new Route('admin/[/][/[-]]', [
'presenter' => 'Homepage',
'action' => 'default',
]);

// Front
$front = $routeManager->getModule('Front');
$front[] = new Route('[/][/[-]]', [
'presenter' => 'Homepage',
'action' => 'default',
]);
}

}

```

## Usage autoregistration in own extension

```php
getContainerBuilder();

$builder->addDefinition($this->prefix('routers'))
->addTag('router')
->setFactory(\TestPackage\Test\TestRouter::class)
->setAutowired(true);

$builder->getDefinition('routers.routerManager')
->addSetup('createModule', ['Test']);
}

public function beforeCompile()
{
$builder = $this->getContainerBuilder();

$builder->getDefinition($builder->getByType(IPresenterFactory::class))
->addSetup(
'setMapping',
[['Test' => 'TestPackage\Test\Presenters\*Presenter']]
);
}
}
```

```php
getModule('Test');
$app[] = new Route('/test//[/]', 'Default:default');
}
}
```

app/config.neon:

```yaml
extensions:

...
- TestPackage\Test\DI\TestExtension
...
```

For correct router orders, you have to list all routers in app/config.neon:

```yaml
extensions:
...
routers: WebChemistry\Routing\DI\RouterExtension
- TestPackage\Test\DI\TestExtension
...

routers:
modules:
...
- Test
...
- App
routers:
...
- App\MainRouter
```