Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/webchemistry/router
- Owner: WebChemistry
- Created: 2016-02-04T22:10:17.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-03-26T16:59:36.000Z (over 5 years ago)
- Last Synced: 2024-07-09T23:25:46.868Z (6 months ago)
- Topics: modular-routers, priority-routes, router, routes
- Language: PHP
- Homepage:
- Size: 25.4 KB
- Stars: 4
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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
```