Overview

Namespaces

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

Classes

  • Config
  • Controller
  • Debug
  • Model
  • Request
  • Response
  • Route
  • Router
  • Session
  • Tool
  • View
  • Overview
  • Namespace
  • Class
  • Tree

Class Router

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

Direct known subclasses

MvcCore\Ext\Router\Lang, MvcCore\Ext\Router\Media
Namespace: MvcCore
Located at mvccore/src/MvcCore/Router.php
Methods summary
public static MvcCore\Router &
# GetInstance( array $routes = array() )

Get singleton instance by configured class In MvcCore app instance, optionaly set routes as first argument.

Get singleton instance by configured class In MvcCore app instance, optionaly set routes as first argument.

Parameters

$routes

Returns

MvcCore\Router
public
# __construct( array & $routes = array() )

Create router, optionaly set routes into new instance as first argument.

Create router, optionaly set routes into new instance as first argument.

Parameters

$routes
public MvcCore\Router
# SetRoutes( array $routes = array() )

Clear and set http routes again

Clear and set http routes again

Parameters

$routes

Returns

MvcCore\Router
public array
# GetRoutes( )

Get all configured routes.

Get all configured routes.

Returns

array
public MvcCore\Router
# AddRoutes( array $routes = array(), boolean $prepend = FALSE )

Append or prepend new request routes. Routes definition array shoud have items as array with route configuration definitions, stdClass with route configuration definitions or \MvcCore\Route instance. Keys in given array has to be route names as 'Controller:Action' strings or any custom route names with defined controller name and action name inside route array/stdClass configuration or route instance.

Append or prepend new request routes. Routes definition array shoud have items as array with route configuration definitions, stdClass with route configuration definitions or \MvcCore\Route instance. Keys in given array has to be route names as 'Controller:Action' strings or any custom route names with defined controller name and action name inside route array/stdClass configuration or route instance.

Parameters

$routes
keyed array with routes, keys are route names or route Controller::Action definitions
$prepend
optional

Returns

MvcCore\Router
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
public MvcCore\Router
# SetCurrentRoute( MvcCore\Route $currentRoute )

Set current route

Set current route

Parameters

$currentRoute

Returns

MvcCore\Router
public MvcCore\Route &
# GetCurrentRoute( )

Return routed route by http request.

Return routed route by http request.

Returns

MvcCore\Route
public
# GetRouteToDefaultIfNotMatch( boolean $enable,… )

Get state about request routing to 'Default:Default' route if no route matches.

Get state about request routing to 'Default:Default' route if no route matches.

Parameters

$enable,…
public
# SetRouteToDefaultIfNotMatch( boolean $enable = TRUE )

Set route request to 'Default:Default' route if no route matches.

Set route request to 'Default:Default' route if no route matches.

Parameters

$enable
public MvcCore\Route &
# Route( MvcCore\Request & $request )

Route application request by configured routes list. To route request - custom complete currentRoute property and Params property in referenced application request by current request url. Return routed route as current route as reference. This method is always called from \MvcCore app instance to dispatch controller by result route.

Route application request by configured routes list. To route request - custom complete currentRoute property and Params property in referenced application request by current request url. Return routed route as current route as reference. This method is always called from \MvcCore app instance to dispatch controller by result route.

Parameters

$request

Returns

MvcCore\Route
public string
# Url( string $controllerActionOrRouteName = 'Index:Index', array $params = array() )

Generates url by: - 'Controller:Action' name and params array (for routes configuration when routes array has keys with 'Controller:Action' strings and routes has not controller name and action name defined inside) - route name and params array (route name is key in routes configuration array, should be any string but routes must have information about controller name and action name inside) Result address should have two forms: - nice rewrited url by routes configuration (for apps with .htaccess supporting url_rewrite and when first param is key in routes configuration array) - for all other cases is url form: index.php?controller=ctrlName&action=actionName (when first param is not founded in routes configuration array)

Generates url by: - 'Controller:Action' name and params array (for routes configuration when routes array has keys with 'Controller:Action' strings and routes has not controller name and action name defined inside) - route name and params array (route name is key in routes configuration array, should be any string but routes must have information about controller name and action name inside) Result address should have two forms: - nice rewrited url by routes configuration (for apps with .htaccess supporting url_rewrite and when first param is key in routes configuration array) - for all other cases is url form: index.php?controller=ctrlName&action=actionName (when first param is not founded in routes configuration array)

Parameters

$controllerActionOrRouteName
Should be 'Controller:Action' combination or just any route name as custom specific string
$params
optional

Returns

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

Complete url with all data in query string

Complete url with all data in query string

Parameters

$controllerActionOrRouteName
$params

Returns

string
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
protected
# routeByControllerAndActionQueryString( string $controllerName, string $actionName )

Complete current route and request params by query string

Complete current route and request params by query string

Parameters

$controllerName
$actionName
protected
# routeByRewriteRoutes( )

Complete current route and request params by defined routes

Complete current route and request params by defined routes

protected static string[]
# completeControllerActionParam( string $dashed = '' )

Complete controller and action names in both forms - dashed and pascal case

Complete controller and action names in both forms - dashed and pascal case

Parameters

$dashed

Returns

string[]
Properties summary
protected static MvcCore\Router $instance

Current singleton instance

Current singleton instance

#
protected MvcCore\Request $request

Current application request

Current application request

#
protected array $routes

All application routes to route request

All application routes to route request

# array()
protected array $urlRoutes

All application routes to build url

All application routes to build url

# array()
protected MvcCore\Route $currentRoute

Current application http routes

Current application http routes

# NULL
protected boolean $routeToDefaultIfNotMatch

Route request to Default:Default route if no route matches.

Route request to Default:Default route if no route matches.

# FALSE
MvcCore API documentation generated by ApiGen