Responsibility - recognize media site version from URL or user agent or session and set up request object, complete automatically rewritten URL with remembered media site version. Redirect to proper media site version by configuration.Than route request like parent class does. Generate URL addresses with prefixed media site version for recognized special devices or add only media site version into query string if necessary.
Methods summary
public
string|null
|
#
GetMediaSiteVersion( )
Get resolved media site version, used in \MvcCore\Request
object and possible to use in controller or view.
Possible values are always: "full" | "tablet" | "mobile" | NULL .
Get resolved media site version, used in \MvcCore\Request
object and possible to use in controller or view.
Possible values are always: "full" | "tablet" | "mobile" | NULL .
Returns
string|null
|
public
MvcCore\Ext\Routers\Media
|
#
SetMediaSiteVersion( string|null $mediaSiteVersion )
Set media site version, used in \MvcCore\Request
object and possible to use in controller or view.
Possible values are always: "full" | "tablet" | "mobile" | NULL .
Set media site version, used in \MvcCore\Request
object and possible to use in controller or view.
Possible values are always: "full" | "tablet" | "mobile" | NULL .
Parameters
Returns
|
public
array
&
|
#
GetAllowedMediaVersionsAndUrlValues( )
Get URL prefixes prepended before request URL path to describe media site
version in url. Keys are media site version values and values in array are
URL prefixes, how to describe media site version in URL. Full version with
possible empty string prefix is necessary to have as last item. If you do
not want to use rewrite routes, just have under your allowed keys any values.
Example:
[
'mobile' => 'm', // to have `/m` substring in every mobile URL begin.
'full' => '', // to have nothing extra in URL for full site version.
];
Get URL prefixes prepended before request URL path to describe media site
version in url. Keys are media site version values and values in array are
URL prefixes, how to describe media site version in URL. Full version with
possible empty string prefix is necessary to have as last item. If you do
not want to use rewrite routes, just have under your allowed keys any values.
Example:
[ 'mobile' => 'm', // to have `/m` substring in every mobile URL begin. 'full' => '', // to have nothing extra in URL for full site version.
];
Returns
array
|
public
MvcCore\Ext\Routers\Media
|
#
SetAllowedMediaVersionsAndUrlValues( array $allowedMediaVersionsAndUrlValues = [] )
Set URL prefixes prepended before request URL path to describe media site
version in URL. Keys are media site version values and values in array are
URL prefixes, how to describe media site version in URL. Full version with
possible empty string prefix is necessary to put as last item. If you do
not want to use rewrite routes, just put under your allowed keys any values.
Example:
\MvcCore\Ext\Routers\Media::GetInstance()->SetAllowedMediaVersionsAndUrlValues([
'mobile' => 'm', // to have `/m` substring in every mobile URL begin.
'full' => '', // to have nothing extra in URL for full site version.
]);
Set URL prefixes prepended before request URL path to describe media site
version in URL. Keys are media site version values and values in array are
URL prefixes, how to describe media site version in URL. Full version with
possible empty string prefix is necessary to put as last item. If you do
not want to use rewrite routes, just put under your allowed keys any values.
Example:
\MvcCore\Ext\Routers\Media::GetInstance()->SetAllowedMediaVersionsAndUrlValues([ 'mobile' => 'm', // to have `/m` substring in every mobile URL begin. 'full' => '', // to have nothing extra in URL for full site version.
]);
Parameters
- $allowedMediaVersionsAndUrlValues
Returns
|
public
boolean
|
#
Route( )
Route current app request by configured routes lists or by query string.
1. Check if request is targeting any internal action in internal ctrl.
2. Choose route strategy by request path and existing query string
controller and/or action values - strategy by query string or by
rewrite routes.
3. If request is not internal, redirect to possible better URL form by
configured trailing slash strategy and return FALSE for redirection.
4. Prepare media site version properties and redirect if necessary.
5. Try to complete current route object by chosen strategy.
6. If any current route found and if route contains redirection, do it.
7. If there is no current route and request is targeting homepage, create
new empty route by default values if ctrl configuration allows it.
8. If there is any current route completed, complete self route name by
it to generate self routes and canonical URL later.
9. If there is necessary, try to complete canonical URL and if canonical
URL is shorter than requested URL, redirect user to shorter version.
If there was necessary to redirect user in routing process, return
immediately FALSE and return from this method. Else continue to next
step and return TRUE . This method is always called from core routing by:
\MvcCore\Application::Run(); => \MvcCore\Application::routeRequest(); .
Route current app request by configured routes lists or by query string.
1. Check if request is targeting any internal action in internal ctrl.
2. Choose route strategy by request path and existing query string controller and/or action values - strategy by query string or by rewrite routes.
3. If request is not internal, redirect to possible better URL form by configured trailing slash strategy and return FALSE for redirection.
4. Prepare media site version properties and redirect if necessary.
5. Try to complete current route object by chosen strategy.
6. If any current route found and if route contains redirection, do it.
7. If there is no current route and request is targeting homepage, create new empty route by default values if ctrl configuration allows it.
8. If there is any current route completed, complete self route name by it to generate self routes and canonical URL later.
9. If there is necessary, try to complete canonical URL and if canonical URL is shorter than requested URL, redirect user to shorter version.
If there was necessary to redirect user in routing process, return
immediately FALSE and return from this method. Else continue to next
step and return TRUE . This method is always called from core routing by:
\MvcCore\Application::Run(); => \MvcCore\Application::routeRequest(); .
Returns
boolean
Throws
LogicException Route configuration property is missing.
InvalidArgumentException Wrong route pattern format.
|
public
string
|
#
UrlByRoute( MvcCore\IRoute $route, array & $params = [], string $urlParamRouteName = NULL )
Complete non-absolute, non-localized url by route instance reverse info.
If there is key media_version in $params , unset this param before
route url completing and choose by this param url prefix to prepend
completed url string.
If there is key localization in $params , unset this param before
route url completing and place this param as url prefix to prepend
completed url string and to prepend media site version prefix.
Example:
Input (\MvcCore\Route::$reverse ):
"/products-list/<name>/<color>"
Input ($params):
array(
"name" => "cool-product-name",
"color" => "red",
"variant" => ["L", "XL"],
"media_version" => "mobile",
);
Output:
/application/base-bath/m/products-list/cool-product-name/blue?variant[]=L&variant[]=XL"
Complete non-absolute, non-localized url by route instance reverse info.
If there is key media_version in $params , unset this param before
route url completing and choose by this param url prefix to prepend
completed url string.
If there is key localization in $params , unset this param before
route url completing and place this param as url prefix to prepend
completed url string and to prepend media site version prefix.
Example:
Input (\MvcCore\Route::$reverse ): "/products-list/<name>/<color>"
Input ($params): array( "name" => "cool-product-name", "color" => "red", "variant" => ["L", "XL"], "media_version" => "mobile", );
Output: /application/base-bath/m/products-list/cool-product-name/blue?variant[]=L&variant[]=XL"
Parameters
- $route
- $route
- $params
- $urlParamRouteName
Returns
string
|
Constants summary
string |
MEDIA_VERSION_FULL
Predefined media site version value for full version.
Predefined media site version value for full version.
|
|
string |
MEDIA_VERSION_TABLET
Predefined media site version value for tablet version.
Predefined media site version value for tablet version.
|
|
string |
MEDIA_VERSION_MOBILE
Predefined media site version value for mobile version.
Predefined media site version value for mobile version.
|
|
string |
URL_PARAM_MEDIA_VERSION
Key name for URL $params when building URL in controller or template by:
$this->Url('route_name', $params); . If you need to create URL into different
media site version, you need to add into $params array key with this value,
then your URL will be created into different media site version.
Example:
$this->Url('route_name', ['media_version' => 'mobile']);
$this->Url('route_name', [\MvcCore\Ext\Routes\IMedia::URL_PARAM_MEDIA_VERSION => 'mobile']); .
Key name for URL $params when building URL in controller or template by:
$this->Url('route_name', $params); . If you need to create URL into different
media site version, you need to add into $params array key with this value,
then your URL will be created into different media site version.
Example:
$this->Url('route_name', ['media_version' => 'mobile']);
$this->Url('route_name', [\MvcCore\Ext\Routes\IMedia::URL_PARAM_MEDIA_VERSION => 'mobile']); .
|
|
string |
URL_PARAM_SWITCH_MEDIA_VERSION
Special $_GET param name for session strict mode.
To change to different media website version in session
strict mode, you need to add after URL something like this:
/any/path?any=params&media_version=mobile .
but if you are creating URL into different site version in
controller or template by $this->Url() with key media_version
in second $params array argument, this switching param for strict
mode is added automatically.
Special $_GET param name for session strict mode.
To change to different media website version in session
strict mode, you need to add after URL something like this:
/any/path?any=params&media_version=mobile .
but if you are creating URL into different site version in
controller or template by $this->Url() with key media_version
in second $params array argument, this switching param for strict
mode is added automatically.
|
|