PHPackages                             mvccore/ext-router-module - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. mvccore/ext-router-module

ActiveLibrary[Framework](/categories/framework)

mvccore/ext-router-module
=========================

MvcCore - Extension - Router - Modules - extension to manage multiple websites in a single project, defined by domain routes, targeted by module property in URL completing.

v5.3.0(1y ago)15213BSD-3-ClausePHPPHP &gt;=5.4.0

Since Jan 18Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mvccore/ext-router-module)[ Packagist](https://packagist.org/packages/mvccore/ext-router-module)[ RSS](/packages/mvccore-ext-router-module/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (7)Dependencies (2)Versions (8)Used By (3)

MvcCore - Extension - Router - Modules
======================================

[](#mvccore---extension---router---modules)

[![Latest Stable Version](https://camo.githubusercontent.com/6a0e9e7da98c52006afe617f10a93df0da2dce64b73eedf5b9b3fcee6bfb6039/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f537461626c652d76352e332e302d627269676874677265656e2e7376673f7374796c653d706c6173746963)](https://github.com/mvccore/ext-router-module/releases)[![License](https://camo.githubusercontent.com/53baed538c1c87a033a212f6f4acce684d36137f8622307643ab25e08118452e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d425344253230332d627269676874677265656e2e7376673f7374796c653d706c6173746963)](https://mvccore.github.io/docs/mvccore/5.0.0/LICENSE.md)[![PHP Version](https://camo.githubusercontent.com/9e923690739211296a00adce5d359999dfa345f80fc1b2e2cfe72c49523ee334/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d2533453d352e342d627269676874677265656e2e7376673f7374796c653d706c6173746963)](https://camo.githubusercontent.com/9e923690739211296a00adce5d359999dfa345f80fc1b2e2cfe72c49523ee334/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d2533453d352e342d627269676874677265656e2e7376673f7374796c653d706c6173746963)

MvcCore Router extension to manage multiple websites in single project, defined by domain routes, targeted by module property in URL completing.

This router is the way, how to route your requests in domain level with params or variable sections, namespaces, default param values and more.

Outline
-------

[](#outline)

1. [Installation](#user-content-1-installation)
2. [Features](#user-content-2-features)
    2.1. [Features - Routing](#user-content-21-features---routing)
    2.2. [Features - Url Generating](#user-content-22-features---url-generating)
3. [How It Works](#user-content-3-how-it-works)
    3.1. [How It Works - Routing](#user-content-31-how-it-works---routing)
    3.2. [How It Works - Url Completing](#user-content-32-how-it-works---url-completing)
4. [Usage](#user-content-4-usage)
    4.1. [Usage - `Bootstrap` Initialization](#user-content-41-usage---bootstrap-initialization)
    4.2. [Usage - Targeting Custom Application Part](#user-content-42-usage---targeting-custom-application-part)
    4.3. [Usage - Creating Module Domain Route](#user-content-43-usage---creating-module-domain-route)
    4.4. [Usage - Domain Routes And Standard Routes Definition](#user-content-44-usage---domain-routes-and-standard-routes-definition)

1. Installation
---------------

[](#1-installation)

```
composer require mvccore/ext-router-module
```

[go to top](#user-content-outline)

2. Features
-----------

[](#2-features)

### 2.1. Features - Routing

[](#21-features---routing)

- Router works with domains and targets requests with different module name in request params
- Router could target various application controller namespaces (various application parts) by defined namespace in "domain route".
- Router stores another collection of routes, so-called "domain routes".
- There is processed domain routes routing before standard router routing. For routing strategy by rewrite routes and also for routing strategy by query string.
- Each domain route has required `module` name and `pattern` property (or `match` with `reverse`) describing only scheme and domain URL part (or base path). If route matches incoming request base part, there is assigned property `module` name into request params by matched domain route. Then there is processed standard routing by standard routes.
- Each domain route could have defined `namespace` property for targeted controller by standard route or by query string, if that controller path is not defined absolutely - if it doesn't start with single backslash `\` or with double slash `//`.
- Every standard route could have defined advanced configuration property called `allowedModules` with array of strings describing for which module name is the route allowed. If route has not defined that advanced property, it means "route is allowed for all modules".
- Any standard route still could have defined `pattern` (or `match` and `reverse`) absolutely. That route is then used in matching process only for it's fixed defined domain or scheme.

[go to top](#user-content-outline)

### 2.2. Features - Url Generating

[](#22-features---url-generating)

- Router could generate URL addresses into different modules only by adding `module` record with target module name into `Url()` method second argument - `$params` array.
- If there is no `module` record in second argument `$params`, there is not generated absolute part of URL, only if standard route requires it or if there is `absolute` record in second argument `$params` with `TRUE` value.
- Canonical and `self` URL addresses are also solved by module domain routes.

[go to top](#user-content-outline)

3. How It Works
---------------

[](#3-how-it-works)

### 3.1. How It Works - Routing

[](#31-how-it-works---routing)

- After router strategy is solved and before standard routes routing is processed, there is processed module domain routes routing.
- After module domain routes are processed, current module domain route is initialized.
- Then every processed standard route is checked if there is allowed module name or not, if route is not allowed, is skipped.
- After routing, if there is matched any module domain route with namespace and target controller is not defined absolutely, module route namespace is added before target controller path.
- There is not required but recommended to define module domain routes by method `$router->SetDomainRoutes(...);` in `Bootstrap.php`.

[go to top](#user-content-outline)

### 3.2. How It Works - Url Completing

[](#32-how-it-works---url-completing)

- If there is defined `module` record name in second arguments `$params` array, there is completed base url part (scheme, domain and base path) by module domain route.
- If standard route has defined absolute part or if standard route is defined as absolute and if there is specified any different `module` record name in second argument `$params` array, error is generated, because it's logic conflict.

[go to top](#user-content-outline)

4. Usage
--------

[](#4-usage)

4.1. Usage - `Bootstrap` Initialization
---------------------------------------

[](#41-usage---bootstrap-initialization)

Add this to `Bootstrap.php` or to **very application beginning**, before application routing or any other extension configuration using router for any purposes:

```
$app = \MvcCore\Application::GetInstance();
$app->SetRouterClass('\MvcCore\Ext\Routers\Module');
...
// to get router instance for next configuration:
/** @var \MvcCore\Ext\Routers\Module $router */
$router = \MvcCore\Router::GetInstance();
```

[go to top](#user-content-outline)

4.2. Usage - Targeting Custom Application Part
----------------------------------------------

[](#42-usage---targeting-custom-application-part)

Module domain route is special kind of route how to define part of application, not directly controller or action.
The definition of a custom part of the application is designed very freely so that you are able to do whatever you want.

- Your custom application part also could be defined as namespace in module domain route, which is used for routed controller by standard route(s), when the controller is not defined absolutely (by single backslash at the beginning or by double slashes in the beginning).
- Your custom application part could be also defined by allowed modules definition, added into any standard route. By this way, you could define which standard route could be used for which module. There could be more than one allowed module name or none (`NULL` means all modules are allowed).
- Your custom part of application could be defined by special param name, called `module`. This param is added into request object every time when is any module domain route matched. It's value is completed in match by domain route module name. This param serves only for describing purposes, how to generate URL from one module to another. But you could use it in controller processing and rendering for anything else how to generate application result.

[go to top](#user-content-outline)

4.3. Usage - Creating Module Domain Route
-----------------------------------------

[](#43-usage---creating-module-domain-route)

- Module domain route is special kind of route how to define part of application, not directly controller or action.
- Module domain route pattern could contain any params or variable sections as standard route, it could contain percentage dynamic replacements for domain URL part as standard route (like `%domain%` or `%tld%` ...), but id can not contain anything else then scheme definition (`http://`, `https://` or `//`), domain part (and base part if you need), nothing else.
- Module domain route is extended directly from standard `\MvcCore\Route` class.
- Domain routes also could be defined as single configuration arrays passed into module domain route constructor, when you define module domain routes on router instance by methods `SetDomainRoutes()`, `AddDomainRoutes()` or `AddDomainRoute()`.

```
// Instance by specified all constructor params:
new \MvcCore\Ext\Routers\Modules\Route(
    "//blog.%sld%.%tld%",             // pattern
    "blog",        "Blog",            // module, namespace
    ["page" => 1], ["page" => "\d+"], // defaults, constraints
    [                                 // advanced configuration
        "allowedLocalizations" => ["en-US"],     // only for extension `mvccore/ext-router-localization`
        "allowedMediaVersions" => ["full" => ""] // only for extension `mvccore/ext-router-media`
    ]
);

// Or instance by single configuration array:
new \MvcCore\Ext\Routers\Modules\Route([
    "pattern"              => "//blog.%sld%.%tld%",
    "module"               => "blog",
    "namespace"            => "Blog",
    "defaults"             => ["page" => 1],
    "constraints"          => ["page" => "\d+"],
    "allowedLocalizations" => ["en-US"],     // only for extension `mvccore/ext-router-localization`
    "allowedMediaVersions" => ["full" => ""] // only for extension `mvccore/ext-router-media`
]);

// Or instance by single configuration array with directly defined
// regular expression `match` pattern and `reverse` pattern`:
new \MvcCore\Ext\Routers\Modules\Route([
    "match"                => "#^//blog\.%sld%\.%tld%$#",
    "reverse"              => "//blog.%sld%.%tld%",
    "module"               => "blog",
    "namespace"            => "Blog",
    "defaults"             => ["page" => 1],
    "constraints"          => ["page" => "\d+"],
    "allowedLocalizations" => ["en-US"],     // only for extension `mvccore/ext-router-localization`
    "allowedMediaVersions" => ["full" => ""] // only for extension `mvccore/ext-router-media`
]);
```

[go to top](#user-content-outline)

4.4. Usage - Domain Routes And Standard Routes Definition
---------------------------------------------------------

[](#44-usage---domain-routes-and-standard-routes-definition)

To work with modules, you need to specify more. With standard routes, you need to specify "module domain routes":

```
// Define domain routes (domain routes also could be defined as single
// configuration arrays passed into module domain route constructor):
$router->SetDomainRoutes([
    // to define blog website module:
    'blog'    => [
        'pattern'      => '//blog.example.com',
        'namespace'      => 'Blog',
    ],
    // to define main website module:
    'main'    => [
        'pattern'      => '//[.]example.com',
        'constraints' => ['productsCategory' => '-a-z0-9]+'],
        'namespace'      => 'Main',
    ],
	// now all requests into `main` module will have `productsCategory` param
	// in request object. For request into `http://example.com/`, there will
	// be `NULL` value for this param, so you can recognize a homepage or there
	// are many other ways how to target a homepage.
]);

// Now let's define standard routes:
$router->SetRoutes([

    // Absolutely defined target controller in `\App\Controllers`:
    '\Admin\Index:Index'   => '/admin',

    // Relatively defined controllers in `\App\Controllers` by module route namespace:

    // There will be only used controllers `\Main\Categories` and
    // `\Main\Categories`, because there is allowed only `main` module.
    // Example match by: `http://phones.example.com/`, `http://phones.example.com/2`, ...
    'Categories:List'      => [
        'pattern'          => '/[]',
        'defaults'         => ['page' => 1],
        'constraints'      => ['page' => '\d+'],
        'allowedModules'   => ['main'],
    ],
    // Example match by: `http://phones.example.com/products/brands-samsung/price-0-1000`, ...
    'Products:List'   => [
        'pattern'          => '/products[/]',
        'constraints'      => ['filter' => '-a-zA-Z0-9_/]+'],
        'allowedModules'   => ['main'],
    ],
    // Example match by: `http://phones.example.com/product/samsung-galaxy-note-9/white`, ...
    'Products:Detail' => [
        'match'            => '#^/product/(?\d+)(/(?[a-z]+))?/?#',
        'reverse'          => '/product/[/]',
        'defaults'         => ['color' => 'red'],
        'allowedModules'   => ['main'],
    ],
    // There will be only used controller `\Blog\Posts`,
    // because there is allowed only `blog` module.
    // Example match by: `http://blog.example.com/`, `http://blog.example.com/2`, ...
    'Posts:List'           => [
        'pattern'          => '/]',
        'defaults'         => ['page' => 1],
        'constraints'      => ['page' => '\d+'],
        'allowedModules'   => ['blog'],
    ],
    // Example match by: `http://blog.example.com/post/which-phone-to-buy`, ...
    'Posts:Detail'         => [
        'pattern'          => '/post/[]',
        'constraints'      => ['path' => '[-a-zA-Z0-9_/]+']
        'allowedModules'   => ['blog'],
    ],
    // There will be used controller `\Main\Index` but
    // there could be also used controller `\Blog\Index`.
    // Example match by: `http://example.com/pages/contacts`, `http://blog.example.com/pages/contacts`, ...
    'Index:Index'          => [
        'pattern'          => '/pages/',
        'constraints'      => ['path' => '[-a-zA-Z0-9_/]+'],
        //'allowedModules' => [NULL], //if there is allowed `NULL`, all modules are allowed
    ],
]);
```

[go to top](#user-content-outline)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~234 days

Recently: every ~339 days

Total

7

Last Release

534d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a68d9cd696ed584a9ee742fa089d0650f4f7a95754bf5d9ee301e6c9013df3fd?d=identicon)[tomFlidr](/maintainers/tomFlidr)

---

Top Contributors

[![tomFlidr](https://avatars.githubusercontent.com/u/1833722?v=4)](https://github.com/tomFlidr "tomFlidr (59 commits)")

---

Tags

pluginframeworkroutesrouterroutingmvcextensionmodulesplug-inprojectsmultipleextsitesmvccore

### Embed Badge

![Health badge](/badges/mvccore-ext-router-module/health.svg)

```
[![Health](https://phpackages.com/badges/mvccore-ext-router-module/health.svg)](https://phpackages.com/packages/mvccore-ext-router-module)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
