Overview

Namespaces

  • None
  • Wei
    • Validator

Classes

  • Apc
  • App
  • ArrayCache
  • Asset
  • Base
  • BaseCache
  • BaseController
  • Bicache
  • Cache
  • Config
  • Cookie
  • Couchbase
  • Counter
  • Db
  • DbCache
  • E
  • Env
  • Error
  • FileCache
  • Gravatar
  • Http
  • Lock
  • Logger
  • Memcache
  • Memcached
  • MongoCache
  • Password
  • PhpError
  • PhpFileCache
  • Pinyin
  • Record
  • Redis
  • Request
  • Response
  • Router
  • SafeUrl
  • Session
  • Soap
  • T
  • Ua
  • Upload
  • Url
  • Uuid
  • Validate
  • View
  • WeChatApp
  • Wei
  • Overview
  • Namespace
  • Class

Class Router

A service that parse the URL to request data

Wei\Base
Extended by Wei\Router
Namespace: Wei
Author: Twin Huang twinhuang@qq.com
Link:

The code is inspired by the awesome framework - Kohana http://kohanaframework.org/3.0/guide/api/Kohana_Route


Located at Router.php
Methods summary
public
# setRoutes( array $routes )

Set routes

Set routes

Parameters

$routes

Returns


$this
public array
# getRoutes( )

Return routes

Return routes

Returns

array
public
# set( array $route )

Add one route

Add one route

Parameters

$route
the options of the route

Returns


$this

Throws

InvalidArgumentException
When argument is not string or array
public false|array
# getRoute( string $id )

Get the route by id

Get the route by id

Parameters

$id
The id of the route

Returns

false|array
public
# remove( string $id )

Remove the route

Remove the route

Parameters

$id
The id of the route

Returns


$this
protected array
# compile( array & $route )

Prepare the route pattern to regex

Prepare the route pattern to regex

Parameters

$route
the route array

Returns

array
public false|array
# match( string $pathInfo, string|null $method = null )

Check if there is a route matches the path info and method, and return the parameters, or return false when not matched

Check if there is a route matches the path info and method, and return the parameters, or return false when not matched

Parameters

$pathInfo
The path info to match
$method
The request method to match, maybe GET, POST, etc

Returns

false|array
public array
# matchParamSet( string $pathInfo, string|null $method = 'GET' )

Parse the path info to parameter set

Parse the path info to parameter set

Parameters

$pathInfo
The path info to match
$method
The request method to match, maybe GET, POST, etc

Returns

array
protected false|array
# matchRoute( string $pathInfo, string $method, string $id )

Check if the route matches the path info and method, and return the parameters, or return false when not matched

Check if the route matches the path info and method, and return the parameters, or return false when not matched

Parameters

$pathInfo
The path info to match
$method
The request method to match
$id
The id of the route

Returns

false|array
public array
# matchRestParamSet( string $path, string $method = 'GET' )

Parse the path info to multi REST parameters

Parse the path info to multi REST parameters

Parameters

$path
$method

Returns

array
protected array
# parsePath( string $path )

Parse path to resource names, actions and ids

Parse path to resource names, actions and ids

Parameters

$path

Returns

array
public
# setCombinedResources( array $combinedResources )

Set combined resources

Set combined resources

Parameters

$combinedResources

Returns


$this
public
# setSingulars( array $singulars )

Append words to singulars

Append words to singulars

Parameters

$singulars

Returns


$this
protected string
# singularize( string $word )

Returns a word in singular form.

Returns a word in singular form.

The implementation is borrowed from Doctrine Inflector

Parameters

$word

Returns

string

Link

https://github.com/doctrine/inflector
protected string
# camelize( string $word )

Camelizes a word

Camelizes a word

Parameters

$word
The word to camelize.

Returns

string
The camelized word.
protected string
# methodToAction( string $method, boolean $collection = false )

Convert HTTP method to action name

Convert HTTP method to action name

Parameters

$method
$collection

Returns

string
protected boolean
# isAction( string $action )

Parameters

$action

Returns

boolean
Methods inherited from Wei\Base
__call(), __construct(), __get(), getOption(), setOption()
Properties summary
protected array $routes

The routes configurations

The routes configurations

# array()
protected array $routeOptions

The default route options

The default route options

# array( 'pattern' => null, 'rules' => array(), 'defaults' => array(), 'method' => null, 'regex' => null, )
protected array $namespaces

The string to split out at the beginning of path

The string to split out at the beginning of path

# array('admin', 'api')
protected array $scopes

The string to split out after namespace string

The string to split out after namespace string

# array('user')
protected array $combinedResources

The resources that contains "/", eg articles/categories, products/categories, issues/comments.

The resources that contains "/", eg articles/categories, products/categories, issues/comments.

# array()
protected string $defaultController
# 'index'
protected string $defaultAction
# 'index'
protected array $methodToAction

An array contains the HTTP method and action name

An array contains the HTTP method and action name

# array( 'GET-collection' => 'index', 'GET' => 'show', 'POST' => 'create', 'PATCH' => 'update', 'PUT' => 'update', 'DELETE' => 'destroy' )
protected array $singularRules

Singular inflector rules

Singular inflector rules

# array( '/(o|x|ch|ss|sh)es$/i' => '\1', // heroes, potatoes, tomatoes '/([^aeiouy]|qu)ies$/i' => '\1y', // histories '/s$/i' => '', )
protected array $singulars

The plural to singular array

The plural to singular array

# array( 'aliases' => 'alias', 'analyses' => 'analysis', 'buses' => 'bus', 'children' => 'child', 'cookies' => 'cookie', 'criteria' => 'criterion', 'data' => 'datum', 'lives' => 'life', 'matrices' => 'matrix', 'men' => 'man', 'menus' => 'menu', 'monies' => 'money', 'news' => 'news', 'people' => 'person', 'quizzes' => 'quiz', )
Properties inherited from Wei\Base
$providers, $wei
Wei Framework API documentation generated by ApiGen