PHPackages                             mvccore/ext-router-media - 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-media

ActiveLibrary[Framework](/categories/framework)

mvccore/ext-router-media
========================

MvcCore - Extension - Router - Media - extension to manage website media versions (full/tablet/mobile) for different templates/CSS/JS files rendering, optionally contained in URL address in the beginning.

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

Since Jan 15Pushed 1y ago1 watchersCompare

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

READMEChangelog (10)Dependencies (3)Versions (19)Used By (2)

MvcCore - Extension - Router - Media
====================================

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

[![Latest Stable Version](https://camo.githubusercontent.com/5fcf6c8c4db95d05267ef89b6fcdcd252a231aa0e69eae48a6c0e5aefcd5f8e6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f537461626c652d76352e332e322d627269676874677265656e2e7376673f7374796c653d706c6173746963)](https://github.com/mvccore/ext-router-media/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 your website media version in URL to have media flag in the request, controller and view to render different templates, CSS and js files for mobiles, tablets or desktops.

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 - Media Url Prefixes And Allowed Media Versions](#user-content-42-usage---media-url-prefixes-and-allowed-media-versions)
5. [Advanced Configuration](#user-content-5-advanced-configuration)
    5.1. [Advanced Configuration - Session Expiration](#user-content-51-advanced-configuration---session-expiration)
    5.2. [Advanced Configuration - Strict Session Mode](#user-content-52-advanced-configuration---strict-session-mode)
    5.3. [Advanced Configuration - Routing `GET` Requests Only](#user-content-53-advanced-configuration---routing-get-requests-only)

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

[](#1-installation)

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

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

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

[](#2-features)

### 2.1. Features - Routing

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

- Router works with requests with media site version prefix in URL address, prefixes are configurable.
- Router recognizes user device as 3 predefined versions - `full`, `tablet` or `mobile` - in first request by HTTP header `User-Agent` with third-party [`\Mobile_Detect`](https://github.com/serbanghita/Mobile-Detect) library.
- Router redirects the first request if necessary to URL address with better media prefix, where is more suitable content for recognized device.
- Router stores recognized device version string in its own session namespace with configurable expiration (to not process `\Mobile_Detect` recognition in every request again).
- Router replaces possibly founded media prefix substring in request path (`$request->GetPath()`) with an empty string. It keeps request path every time in the same form to process routing as usual.
- Router completes `$request->GetMediaSiteVersion()` value to use it anywhere in your app as strings: `full`, `tablet` or `mobile`.
- Session strict mode for media site version (configurable) to drive application media version strictly by session value.

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

### 2.2. Features - Url Generating

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

- Router completes every application URL (or every `GET` URL by configuration) generated by built-in `Url()` method with media prefix substring by requested media version or media version given as second argument array with URL params for `Url()` method.
- There is also possible to configure the URL media version substring prefix.

[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)

- Router completes media site versions from these sources:
    - From requested URL (if there is no media site prefix in URL, it's completed to `full`).
    - From session (if there is nothing, it stays on `NULL`).
    - From special `$_GET` param to switch media site version in session strict mode (also could be `NULL`).
- Router process pre-route redirections by source data if necessary:
    - If there is allowed value in special `$_GET` switching param: - New media site version is stored in session and request is redirected to new media site version by special switching param.
    - Else if there is no media site version in session from any previous request: - There is recognized media site version by the third-party library [`\Mobile_Detect`](https://github.com/serbanghita/Mobile-Detect) and stored in the session for next requests.
        - There is also completed flag if the detected version is the same as the requested version.
    - If strict session mode is configured to `FALSE` (by default):
        - If the request is first (nothing is in session from previous requests):
            - If the detected version is different from the request version:
                - Redirect user to detected version:
            - Else route request with requested media site version in a standard way later, do not process any redirections.
        - Else route request with requested media site version in a standard way later, do not process any redirections.
    - If strict session mode is configured to `TRUE`:
        - If the requested media site version is different from the session version:
            - Redirect user to session version.
        - Else route request with requested media site version in a standard way later, do not process any redirections.
- Router removes any founded media site version URL prefix to process routing for any media site version with the same request path.
- Then the router, routes request in a standard way.

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

### 3.2. How It Works - Url Completing

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

- The router generates URL addresses always with the same media site version as requested media site version:
    - For addresses without any defined rewrite route, there is added into query string additional param about media site version (`&media_version=...`).
    - For addresses with defined rewrite route, there is prepended media site version URL prefix by router configuration.
- If requested version is `full` (`full` is by default), there is not necessary to put into URL addresses any additional data, so for `full` version, there is always the same original URL string without any special params or prefixes.
- If you define into build-in `Url()` method into second argument array into params any different media site version than requested media version is, there is added into result URL string query param or media site URL prefix by given media site version.
- If there is configured session strict mode, special `$_GET` switching param is always added automatically.

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

4. Usage
--------

[](#4-usage)

### 4.1. Usage - `Bootstrap` Initialization

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

Add this to `/App/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\Media');
...
// to get router instance for next configuration:
/** @var \MvcCore\Ext\Routers\Media $router */
$router = \MvcCore\Router::GetInstance();
```

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

### 4.2. Usage - Media Url Prefixes And Allowed Media Versions

[](#42-usage---media-url-prefixes-and-allowed-media-versions)

There are configured three media site versions with URL address prefixes by default:

```
use \MvcCore\Ext\Routers;
...
$router->SetAllowedMediaVersionsAndUrlValues([
    Routers\Media::MEDIA_VERSION_MOBILE	=> 'm',
    Routers\Media::MEDIA_VERSION_TABLET	=> 't',
    Routers\Media::MEDIA_VERSION_FULL	=> '',
]);
```

To allow only selected media site versions and to configure url prefixes, you can use:

```
// to allow only mobile version (with url prefix '/mobile')
// and full version (with no url prefix):
use \MvcCore\Ext\Routers;
...
// now, tablet version is not allowed:
$router->SetAllowedMediaVersionsAndUrlValues([
    Routers\Media::MEDIA_VERSION_MOBILE	=> 'mobile',
    // if you are using an empty string url prefix for full version,
    // you need to define it as the last item!
    Routers\Media::MEDIA_VERSION_FULL	=> '',
]);
```

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

5. Advanced Configuration
-------------------------

[](#5-advanced-configuration)

### 5.1. Advanced Configuration - Session Expiration

[](#51-advanced-configuration---session-expiration)

There is possible to change session expiration about detected media site version value to not recognize media site version every request where is no prefix in URL, because to process all regular expressions in `\Mobile_Detect` library could take some time. By **default** there is **1 hour**. You can change it by:

```
$router->SetSessionExpirationSeconds(
    \MvcCore\Session::EXPIRATION_SECONDS_DAY
);
```

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

### 5.2. Advanced Configuration - Strict Session Mode

[](#52-advanced-configuration---strict-session-mode)

**In session strict mode, there is not possible to change media site version only by requesting different media site version prefix in URL.**Strict session mode is router mode when media site version is managed by session value from the first request recognition. All requests to different media site version than the version in session are automatically redirected to media site version stored in the session.

Normally, there is possible to get different media site version only by requesting different media site version URL prefix. For example - to get a different version from `full` version, for example, to get `mobile` version, it's only necessary to request application with configured `mobile` prefix in URL like this: `/mobile/any/application/request/path`.

In session strict mode, there is possible to change media site version only by special `$_GET` parameter in your media version navigation. For example - to get a different version from `full` version, for example, `mobile` version, you need to add into query string parameters like this: `/any/application/request/path?switch_media_version=mobile`Then, there is changed media site version stored in the session and the user is redirected to the mobile application version with mobile URL prefixes everywhere.

To have this session strict mode, you only need to configure router by:

```
$router->SetStricModeBySession(TRUE);
```

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

### 5.3. Advanced Configuration - Routing `GET` Requests Only

[](#53-advanced-configuration---routing-get-requests-only)

The router manages media site version only for `GET` requests. It means redirections to the proper version in session strict mode or to redirect in the first request to recognized media site version. `POST` requests and other request methods to manage for media site version doesn't make sense. For those requests, you have still media site version record in session and you can use it any time. But to process all request methods, you can configure the router to do so like this:

```
$router->SetRouteGetRequestsOnly(FALSE);
```

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

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity67

Established project with proven stability

 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 ~169 days

Recently: every ~152 days

Total

18

Last Release

520d ago

Major Versions

v3.2.1 → v4.0.02017-01-29

v4.3.1 → v5.0.02021-01-18

PHP version history (2 changes)v3.0.0PHP &gt;=5.3.0

v5.0.0PHP &gt;=5.4.0

### 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 (139 commits)")

---

Tags

pluginframeworkaddressroutesrouterroutingmobilemediamvcextensionplug-inflagversionsiteexttabletmvccorefull

### Embed Badge

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

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

PHPackages © 2026

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