Overview

Namespaces

  • MvcCore
    • Ext
      • Auth
        • Virtual
      • Debug
        • Tracy
      • Form
        • Core
        • Validators
      • Request
      • Router
        • Lang
      • View
        • Helpers
  • None

Classes

  • Lang
  • Media
  • MediaSiteKey
  • Overview
  • Namespace
  • Class
  • Tree

Class Lang

Core router: - main store for all routes - application request routing process before request dispatching in core - currently matched route store - application url completing - by configured routes into mod_rewrite form - or into query string form, containing controller and action params - params query string building - primitive param value or array value representation possible

MvcCore\Router
Extended by MvcCore\Ext\Router\Lang
Namespace: MvcCore\Ext\Router
Located at ext-router-lang/src/MvcCore/Ext/Router/Lang.php
Methods summary
public MvcCore\Ext\Router\Lang
# SetAllowedLangs( )

Set international lowercase language code(s), allowed to use in your application. Default language is always allowed.

Set international lowercase language code(s), allowed to use in your application. Default language is always allowed.

Returns

MvcCore\Ext\Router\Lang

Var

string $lang..., international lowercase language code(s)
public MvcCore\Ext\Router\Lang
# AddAllowedLangs( )

Add international lowercase language code(s), allowed to use in your application. Default language is always allowed.

Add international lowercase language code(s), allowed to use in your application. Default language is always allowed.

Returns

MvcCore\Ext\Router\Lang

Var

string $lang..., international lowercase language code(s)
public MvcCore\Ext\Router\Lang
# SetDefaultLang( string $defaultLang )

Set default lang to use in cases, when is not possible to detect lang from url, not possible to detect lang from 'Accept-Language' http header or not possible to get from session.

Set default lang to use in cases, when is not possible to detect lang from url, not possible to detect lang from 'Accept-Language' http header or not possible to get from session.

Parameters

$defaultLang

Returns

MvcCore\Ext\Router\Lang
public MvcCore\Ext\Router\Lang
# SetLang( string $lang )

Set language externaly, not recomanded.

Set language externaly, not recomanded.

Parameters

$lang

Returns

MvcCore\Ext\Router\Lang
public MvcCore\Ext\Router\Lang
# SetSessionExpirationSeconds( integer $sessionExpirationSeconds = 3600 )

Session expiration in seconds, by default - one hour.

Session expiration in seconds, by default - one hour.

Parameters

$sessionExpirationSeconds

Returns

MvcCore\Ext\Router\Lang
public MvcCore\Ext\Router\Lang
# SetStricModeBySession( boolean $stricModeBySession = TRUE )

If TRUE, language is not possible to switch by different request url path begin, because for every different url path begin than session record is user automaticly redirected to url path begin by session. If TRUE, language version is possible to change only by special $_GET param called 'switch_lang=..' in query string. If not configured, FALSE by default.

If TRUE, language is not possible to switch by different request url path begin, because for every different url path begin than session record is user automaticly redirected to url path begin by session. If TRUE, language version is possible to change only by special $_GET param called 'switch_lang=..' in query string. If not configured, FALSE by default.

Parameters

$stricModeBySession

Returns

MvcCore\Ext\Router\Lang
public MvcCore\Ext\Router\Lang
# SetKeepDefaultLangPath( mixed $keepDefaultLangPath = TRUE )

If TRUE and language is necessary to request into default language url version, there is target url path completed into '/'+$this->DefaultLang, not to '/' (slash) only. If FALSE and language is necessary to request into default language url version, there is target url path completed only to '/' (slash). If not configured, FALSE by default.

If TRUE and language is necessary to request into default language url version, there is target url path completed into '/'+$this->DefaultLang, not to '/' (slash) only. If FALSE and language is necessary to request into default language url version, there is target url path completed only to '/' (slash). If not configured, FALSE by default.

Parameters

$keepDefaultLangPath

Returns

MvcCore\Ext\Router\Lang
public MvcCore\Ext\Router\Lang
# SetFirstRequestStrictlyByUserAgent( boolean $firstRequestStrictlyByUserAgent = TRUE )

If TRUE, first request language will be strictly recognized by user agent http header 'Acept-Language', not by requested url. First or not first request is detected by session. If not configured, FALSE by default.

If TRUE, first request language will be strictly recognized by user agent http header 'Acept-Language', not by requested url. First or not first request is detected by session. If not configured, FALSE by default.

Parameters

$firstRequestStrictlyByUserAgent

Returns

MvcCore\Ext\Router\Lang
public MvcCore\Ext\Router\Lang
# SetAllowNonLocalizedRoutes( boolean $allowNonLocalizedRoutes = TRUE )

If TRUE, redirect request to default language version if lang in request is not allowed. If not configured, TRUE by default.

If TRUE, redirect request to default language version if lang in request is not allowed. If not configured, TRUE by default.

Parameters

$allowNonLocalizedRoutes
$redirectToDefaultLangIfNotAllowed

Returns

MvcCore\Ext\Router\Lang
public MvcCore\Router
# AddRoute( array|stdClass|MvcCore\Route $routeCfgOrRoute, boolean $prepend = FALSE )

Append or prepend new request route. Route definition array shoud be array with route configuration definition, stdClass with route configuration definition or \MvcCore\Route instance. In configuration definition is required route name, controller, action, pattern and if pattern contains regexp groups, its necessary also to define route reverse. Route name should be defined as 'Controller:Action' string or any custom route name, but then there is necessary to specify controller name and action name inside route array/stdClass configuration or route instance.

Append or prepend new request route. Route definition array shoud be array with route configuration definition, stdClass with route configuration definition or \MvcCore\Route instance. In configuration definition is required route name, controller, action, pattern and if pattern contains regexp groups, its necessary also to define route reverse. Route name should be defined as 'Controller:Action' string or any custom route name, but then there is necessary to specify controller name and action name inside route array/stdClass configuration or route instance.

Parameters

$routeCfgOrRoute
$prepend

Returns

MvcCore\Router

Overrides

MvcCore\Router::AddRoute()
protected
# routeByRewriteRoutes( )

Complete current route and request params by defined routes

Complete current route and request params by defined routes

Overrides

MvcCore\Router::routeByRewriteRoutes()
protected string
# getRouteLocalizedRecord( MvcCore\Route & $route, string $routeRecordKey = '' )

Get route non-localized or localized record - 'Pattern' and 'Reverse'

Get route non-localized or localized record - 'Pattern' and 'Reverse'

Parameters

$route
$routeRecordKey

Returns

string
public static
# StaticInit( )

Static initialization - called when class is included by autoloader

Static initialization - called when class is included by autoloader

protected string
# urlByRoute( string $controllerActionOrRouteName, array $params )

Complete url by route instance reverse info

Complete url by route instance reverse info

Parameters

$controllerActionOrRouteName
$params

Returns

string

Overrides

MvcCore\Router::urlByRoute()
protected
# processLangVersion( MvcCore\Request & $request )

Detect language version by configured rules, set up detected version to current context, into request and into session and redirect if necessary.

Detect language version by configured rules, set up detected version to current context, into request and into session and redirect if necessary.

Parameters

$request
protected
# setUpDetectedLangAndRedirectIfNecessary( string $detectedLang )

Store detected language in session, in request and in router. If detected is different than request version - redirect to detected version. Else if original request version is different than request version and boolean switch $this->allowNonLocalizedRoutes is true, redirect to default lang.

Store detected language in session, in request and in router. If detected is different than request version - redirect to detected version. Else if original request version is different than request version and boolean switch $this->allowNonLocalizedRoutes is true, redirect to default lang.

Parameters

$detectedLang
protected
# prepareProcessing( MvcCore\Request & $request )

Prepare language processing: - store request object reference - store request path into request original path - try to complete switching param from $_GET - try to complete request lang - try to complete session lang

Prepare language processing: - store request object reference - store request path into request original path - try to complete switching param from $_GET - try to complete request lang - try to complete session lang

Var

void
protected
# redirectToDifferentLangVersion( string $targetLang )

Redirect to different language path version, only by changing first path element to different value. If router is configured to use default lang root path, keep it.

Redirect to different language path version, only by changing first path element to different value. If router is configured to use default lang root path, keep it.

Parameters

$targetLang
protected
# setUpRequestLangFromUrl( )

Try to set up lang from request, if there is any lang, correct request path, if thre is no request language, set up default lang.

Try to set up lang from request, if there is any lang, correct request path, if thre is no request language, set up default lang.

protected
# setUpAllowedLangs( )

Add default language into allowed languages and change all array values into keys, set all values as 1 (int).

Add default language into allowed languages and change all array values into keys, set all values as 1 (int).

protected
# setUpSession( )

If session namespace by this class is not initialized, init namespace and move expiration (to next hour by default)

If session namespace by this class is not initialized, init namespace and move expiration (to next hour by default)

protected
# getDetectedLangByUserAgent( )

Try to detect language from http header: 'Accept-Language'

Try to detect language from http header: 'Accept-Language'

Var

string
protected array
# parseUserAgentLangList( string $languagesList )

Parse list of comma separated language tags and sort it by the quality value

Parse list of comma separated language tags and sort it by the quality value

Parameters

$languagesList

Returns

array
Methods inherited from MvcCore\Router
AddRoutes(), GetCurrentRoute(), GetInstance(), GetRouteToDefaultIfNotMatch(), GetRoutes(), Route(), SetCurrentRoute(), SetRouteToDefaultIfNotMatch(), SetRoutes(), Url(), __construct(), completeControllerActionParam(), routeByControllerAndActionQueryString(), urlByQueryString()
Constants summary
string VERSION

MvcCore Extension - Router Lang - version: Comparation by PHP function version_compare();

MvcCore Extension - Router Lang - version: Comparation by PHP function version_compare();

See

http://php.net/manual/en/function.version-compare.php
# '4.2.0'
string LANG_URL_PARAM

Key name for language in second argument $params in $router->Url(); method, to tell $router->Url() method to generate different language url.

Key name for language in second argument $params in $router->Url(); method, to tell $router->Url() method to generate different language url.

# 'lang'
string LANG_SWITCH_URL_PARAM

Special $_GET param name for session strict mode, how to change site language version.

Special $_GET param name for session strict mode, how to change site language version.

# 'switch_lang'
Properties summary
public string|array $Pattern

Route preg_match pattern in classic PHP form: array('en' => "#^/url-begin/([^/])/([^/])/(.)#", 'de' => "#^/url-beginn/([^/])/([^/])/(.)#",);

Route preg_match pattern in classic PHP form: array('en' => "#^/url-begin/([^/])/([^/])/(.)#", 'de' => "#^/url-beginn/([^/])/([^/])/(.)#",);

# ''
public string|array $Reverse

Route reverse address form from preg_replace pattern in form: array('en' => "/url-begin/{%first}/{%second}/{%third}", 'de' => "/url-beginn/{%first}/{%second}/{%third}",);

Route reverse address form from preg_replace pattern in form: array('en' => "/url-begin/{%first}/{%second}/{%third}", 'de' => "/url-beginn/{%first}/{%second}/{%third}",);

# ''
public string $DefaultLang

Default language, two lowercase characters, internaltional language code, lang to use in cases, when is not possible to detect lang from url, not possible to detect lang from 'Accept-Language' http header or not possible to get from session.

Default language, two lowercase characters, internaltional language code, lang to use in cases, when is not possible to detect lang from url, not possible to detect lang from 'Accept-Language' http header or not possible to get from session.

# 'en'
public string $Lang

Result language, two lowercase characters, internaltional language code. Example: 'en' | 'fr' | 'de'...

Result language, two lowercase characters, internaltional language code. Example: 'en' | 'fr' | 'de'...

# ''
public integer $SessionExpirationSeconds

Session expiration seconds for remembering detected lang version by user agent. Session record is always used to compare if user is requesting different media site version then he has in session - if there is difference - user is redirected to session media site version and this seconds is time to remember that sessio record for described redirection.

Session expiration seconds for remembering detected lang version by user agent. Session record is always used to compare if user is requesting different media site version then he has in session - if there is difference - user is redirected to session media site version and this seconds is time to remember that sessio record for described redirection.

# 3600
protected MvcCore\Session|stdClass $session

Session record is always used to compare if user is requesting different lang version then he has in session - if there is difference - user is redirected to session lang version.

Session record is always used to compare if user is requesting different lang version then he has in session - if there is difference - user is redirected to session lang version.

# NULL
protected string $sessionLang

Lang founded in session.

Lang founded in session.

# ''
protected string $requestLang

Lang founded in request.

Lang founded in request.

# ''
protected string $switchUriParamLang

Lang value in special $_GET param if session mode is strict.

Lang value in special $_GET param if session mode is strict.

# ''
protected string $requestLangNotAllowed

If any, lang value in request, in url, not allowed to work with.

If any, lang value in request, in url, not allowed to work with.

# ''
protected boolean $stricModeBySession

If true, process lang version strictly by session stored version, so if request contains some version and in session is different, redirect user to session version value adress, only when lang switching param is contained in $_GET, switch the version in session. If false, process lang version more benevolently, so if request contains some lang and in session is different, store in session lang version from request and do not redirect user.

If true, process lang version strictly by session stored version, so if request contains some version and in session is different, redirect user to session version value adress, only when lang switching param is contained in $_GET, switch the version in session. If false, process lang version more benevolently, so if request contains some lang and in session is different, store in session lang version from request and do not redirect user.

# FALSE
protected boolean $keepDefaultLangPath

If TRUE and language is necessary to request into default language url version, there is target url path completed into '/'+$this->DefaultLang, not to '/' (slash) only. If FALSE and language is necessary to request into default language url version, there is target url path completed only to '/' (slash). If not configured, FALSE by default.

If TRUE and language is necessary to request into default language url version, there is target url path completed into '/'+$this->DefaultLang, not to '/' (slash) only. If FALSE and language is necessary to request into default language url version, there is target url path completed only to '/' (slash). If not configured, FALSE by default.

# FALSE
protected boo $allowNonLocalizedRoutes

If TRUE, redirect request to default language version if lang in request is not allowed. If not configured, TRUE by default.

If TRUE, redirect request to default language version if lang in request is not allowed. If not configured, TRUE by default.

# TRUE
protected boolean $firstRequestStrictlyByUserAgent

If TRUE, redirect request to default language version if lang in request is not allowed. If not configured, TRUE by default.

If TRUE, redirect request to default language version if lang in request is not allowed. If not configured, TRUE by default.

# FALSE
protected array $allowedLangs

Allowed language codes to use in your application, default lang will be allowed automaticly.

Allowed language codes to use in your application, default lang will be allowed automaticly.

# array()
Properties inherited from MvcCore\Router
$currentRoute, $instance, $request, $routeToDefaultIfNotMatch, $routes, $urlRoutes
MvcCore API documentation generated by ApiGen